task2/solution01/src/org/apidesign/apifest08/currency/CurrencyConvertorFactoryImpl.java
1 package org.apidesign.apifest08.currency;
3 import java.util.Currency;
6 * Convertor Factory implementation
7 * In the real-time world this code should be optimized - convertors caching etc.
8 * @author Ladislav Vitasek
10 class CurrencyConvertorFactoryImpl extends AbstractConvertorFactory {
13 CurrencyConvertorFactoryImpl() {
17 // Note - implementation of this method is dummy
19 public Convertor createConvertor(Currency currency1, Currency currency2, ConversionProperties conversionProperties) throws ConvertorNotAvailableException {
20 if (currency1 == null || currency2 == null || conversionProperties == null)
21 throw new NullPointerException();
24 return new CurrencyConvertorImpl(currency1, currency2, conversionProperties.getConversionRatioProvider(), conversionProperties.getRoundingMode());//can be cached somehow
25 } catch (Exception e) {
26 throw new ConvertorNotAvailableException(e);