task2/solution13/src/org/apidesign/apifest08/currency/ConversionNotSupportedException.java
author japod@localhost
Tue, 07 Oct 2008 01:18:23 +0200
changeset 41 a7e6f84fb078
permissions -rw-r--r--
adding solution13 for task2
     1 package org.apidesign.apifest08.currency;
     2 
     3 /**
     4  * Conversion not suported exception. This expecption may optionaly describe which conversion was required and failed.
     5  * Required conversion can be found in {@link #getFromCurrecyCode() } and {@link #getToCurrecyCode() }.
     6  * 
     7  * @author arnostvalicek
     8  * @since version2
     9  */
    10 public class ConversionNotSupportedException extends ConvertorException {
    11     String from;
    12     String to;
    13     boolean reversed;
    14     
    15     public ConversionNotSupportedException() {
    16         super();
    17     }
    18 
    19     public ConversionNotSupportedException(String message) {
    20         super(message);
    21     }
    22 
    23     public ConversionNotSupportedException(String message, Throwable cause) {
    24         super(message, cause);
    25     }
    26 
    27     public ConversionNotSupportedException(Throwable cause) {
    28         super(cause);
    29     }
    30     
    31     /**
    32      * Create exception witd additional information about currencies which are not supported in coversion.
    33      * @param from Code of source currency.
    34      * @param to Code of target currency.
    35      * @param twoWay Set to <code>false</code> if <em>From-&gt;To</em> is not supported.
    36      *               Set to <code>true</code> if both ways <em>From-&gt;To</em> and <em>To->From</em> conversions are not supported.
    37      *               
    38      */
    39     public ConversionNotSupportedException(String from, String to, boolean twoWay) {
    40         this.from = from;
    41         this.to = to;
    42         this.reversed = true;
    43     }
    44 
    45     @Override
    46     public String toString() {
    47         if (from!=null && to !=null) {
    48           if (reversed) {
    49              return "Neither onversion nor reverted conversion from " + from + " to " + to + "  is not supported,"; 
    50           }  else {
    51              return "Conversion from " + from + " to " + to + "  is not supported,"; 
    52           }
    53         } else {
    54             return super.toString();
    55         }
    56     }
    57     
    58     /**
    59      * Returns code of source currency. This value may be null.
    60      * @return Returns code of source currency.
    61      */
    62     public String getFromCurrecyCode() {
    63         return from;
    64     }
    65 
    66     /**
    67      * Returns code of target currency. This value may be null.
    68      * @return Returns code of target currency.
    69      */    public String getToCurrecyCode() {
    70         return to;
    71     }
    72      
    73     /**
    74      * Returns if one way of two way conversion is not supported.
    75      * 
    76      * Value <code>false</code> means one way conversion is not supported. Value <code>true</code> means
    77      * that two way conversio is not supported.
    78      * 
    79      * @return Returs <code>false</code> for one way conversion, <code>true</code> for two way conversion.
    80      */ 
    81     public boolean getTwoWayConversion() {
    82         return reversed;
    83     }
    84 
    85 }