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