task1/solution01/src/org/apidesign/apifest08/currency/CurrencyConvertorFactoryImpl.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/task1/solution01/src/org/apidesign/apifest08/currency/CurrencyConvertorFactoryImpl.java Sun Sep 28 14:12:38 2008 +0200
1.3 @@ -0,0 +1,29 @@
1.4 +package org.apidesign.apifest08.currency;
1.5 +
1.6 +import java.util.Currency;
1.7 +
1.8 +/**
1.9 + * Convertor Factory implementation
1.10 + * In the real-time world this code should be optimized - convertors caching etc.
1.11 + * @author Ladislav Vitasek
1.12 + */
1.13 +class CurrencyConvertorFactoryImpl extends AbstractConvertorFactory {
1.14 +
1.15 +
1.16 + CurrencyConvertorFactoryImpl() {
1.17 + super();
1.18 + }
1.19 +
1.20 + // Note - implementation of this method is dummy
1.21 +
1.22 + public Convertor createConvertor(Currency currency1, Currency currency2, ConversionProperties conversionProperties) throws ConvertorNotAvailableException {
1.23 + if (currency1 == null || currency2 == null || conversionProperties == null)
1.24 + throw new NullPointerException();
1.25 +
1.26 + try {
1.27 + return new CurrencyConvertorImpl(currency1, currency2, conversionProperties.getConversionRatioProvider(), conversionProperties.getRoundingMode());//can be cached somehow
1.28 + } catch (Exception e) {
1.29 + throw new ConvertorNotAvailableException(e);
1.30 + }
1.31 + }
1.32 +}