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