task2/solution13/src/org/apidesign/apifest08/currency/ConversionNotSupportedException.java
changeset 41 a7e6f84fb078
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/task2/solution13/src/org/apidesign/apifest08/currency/ConversionNotSupportedException.java	Tue Oct 07 01:18:23 2008 +0200
     1.3 @@ -0,0 +1,85 @@
     1.4 +package org.apidesign.apifest08.currency;
     1.5 +
     1.6 +/**
     1.7 + * Conversion not suported exception. This expecption may optionaly describe which conversion was required and failed.
     1.8 + * Required conversion can be found in {@link #getFromCurrecyCode() } and {@link #getToCurrecyCode() }.
     1.9 + * 
    1.10 + * @author arnostvalicek
    1.11 + * @since version2
    1.12 + */
    1.13 +public class ConversionNotSupportedException extends ConvertorException {
    1.14 +    String from;
    1.15 +    String to;
    1.16 +    boolean reversed;
    1.17 +    
    1.18 +    public ConversionNotSupportedException() {
    1.19 +        super();
    1.20 +    }
    1.21 +
    1.22 +    public ConversionNotSupportedException(String message) {
    1.23 +        super(message);
    1.24 +    }
    1.25 +
    1.26 +    public ConversionNotSupportedException(String message, Throwable cause) {
    1.27 +        super(message, cause);
    1.28 +    }
    1.29 +
    1.30 +    public ConversionNotSupportedException(Throwable cause) {
    1.31 +        super(cause);
    1.32 +    }
    1.33 +    
    1.34 +    /**
    1.35 +     * Create exception witd additional information about currencies which are not supported in coversion.
    1.36 +     * @param from Code of source currency.
    1.37 +     * @param to Code of target currency.
    1.38 +     * @param twoWay Set to <code>false</code> if <em>From-&gt;To</em> is not supported.
    1.39 +     *               Set to <code>true</code> if both ways <em>From-&gt;To</em> and <em>To->From</em> conversions are not supported.
    1.40 +     *               
    1.41 +     */
    1.42 +    public ConversionNotSupportedException(String from, String to, boolean twoWay) {
    1.43 +        this.from = from;
    1.44 +        this.to = to;
    1.45 +        this.reversed = true;
    1.46 +    }
    1.47 +
    1.48 +    @Override
    1.49 +    public String toString() {
    1.50 +        if (from!=null && to !=null) {
    1.51 +          if (reversed) {
    1.52 +             return "Neither onversion nor reverted conversion from " + from + " to " + to + "  is not supported,"; 
    1.53 +          }  else {
    1.54 +             return "Conversion from " + from + " to " + to + "  is not supported,"; 
    1.55 +          }
    1.56 +        } else {
    1.57 +            return super.toString();
    1.58 +        }
    1.59 +    }
    1.60 +    
    1.61 +    /**
    1.62 +     * Returns code of source currency. This value may be null.
    1.63 +     * @return Returns code of source currency.
    1.64 +     */
    1.65 +    public String getFromCurrecyCode() {
    1.66 +        return from;
    1.67 +    }
    1.68 +
    1.69 +    /**
    1.70 +     * Returns code of target currency. This value may be null.
    1.71 +     * @return Returns code of target currency.
    1.72 +     */    public String getToCurrecyCode() {
    1.73 +        return to;
    1.74 +    }
    1.75 +     
    1.76 +    /**
    1.77 +     * Returns if one way of two way conversion is not supported.
    1.78 +     * 
    1.79 +     * Value <code>false</code> means one way conversion is not supported. Value <code>true</code> means
    1.80 +     * that two way conversio is not supported.
    1.81 +     * 
    1.82 +     * @return Returs <code>false</code> for one way conversion, <code>true</code> for two way conversion.
    1.83 +     */ 
    1.84 +    public boolean getTwoWayConversion() {
    1.85 +        return reversed;
    1.86 +    }
    1.87 +
    1.88 +}