diff -r 000000000000 -r a7e6f84fb078 task2/solution13/src/org/apidesign/apifest08/currency/ConversionNotSupportedException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/task2/solution13/src/org/apidesign/apifest08/currency/ConversionNotSupportedException.java Tue Oct 07 01:18:23 2008 +0200 @@ -0,0 +1,85 @@ +package org.apidesign.apifest08.currency; + +/** + * Conversion not suported exception. This expecption may optionaly describe which conversion was required and failed. + * Required conversion can be found in {@link #getFromCurrecyCode() } and {@link #getToCurrecyCode() }. + * + * @author arnostvalicek + * @since version2 + */ +public class ConversionNotSupportedException extends ConvertorException { + String from; + String to; + boolean reversed; + + public ConversionNotSupportedException() { + super(); + } + + public ConversionNotSupportedException(String message) { + super(message); + } + + public ConversionNotSupportedException(String message, Throwable cause) { + super(message, cause); + } + + public ConversionNotSupportedException(Throwable cause) { + super(cause); + } + + /** + * Create exception witd additional information about currencies which are not supported in coversion. + * @param from Code of source currency. + * @param to Code of target currency. + * @param twoWay Set to false if From->To is not supported. + * Set to true if both ways From->To and To->From conversions are not supported. + * + */ + public ConversionNotSupportedException(String from, String to, boolean twoWay) { + this.from = from; + this.to = to; + this.reversed = true; + } + + @Override + public String toString() { + if (from!=null && to !=null) { + if (reversed) { + return "Neither onversion nor reverted conversion from " + from + " to " + to + " is not supported,"; + } else { + return "Conversion from " + from + " to " + to + " is not supported,"; + } + } else { + return super.toString(); + } + } + + /** + * Returns code of source currency. This value may be null. + * @return Returns code of source currency. + */ + public String getFromCurrecyCode() { + return from; + } + + /** + * Returns code of target currency. This value may be null. + * @return Returns code of target currency. + */ public String getToCurrecyCode() { + return to; + } + + /** + * Returns if one way of two way conversion is not supported. + * + * Value false means one way conversion is not supported. Value true means + * that two way conversio is not supported. + * + * @return Returs false for one way conversion, true for two way conversion. + */ + public boolean getTwoWayConversion() { + return reversed; + } + +}