task2/solution01/src/org/apidesign/apifest08/currency/CurrencyConvertorFactoryImpl.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 01 Oct 2008 10:43:05 +0200
changeset 29 f6073056b9fe
parent 6 task1/solution01/src/org/apidesign/apifest08/currency/CurrencyConvertorFactoryImpl.java@97662396c0fd
permissions -rw-r--r--
Getting ready for task2: copying all solutions to new locations
     1 package org.apidesign.apifest08.currency;
     2 
     3 import java.util.Currency;
     4 
     5 /**
     6  * Convertor Factory implementation
     7  * In the real-time world this code should be optimized - convertors caching etc.
     8  * @author Ladislav Vitasek
     9  */
    10 class CurrencyConvertorFactoryImpl extends AbstractConvertorFactory  {
    11     
    12 
    13     CurrencyConvertorFactoryImpl() {
    14         super();
    15     }
    16 
    17     // Note - implementation of this method is dummy
    18     
    19     public Convertor createConvertor(Currency currency1, Currency currency2, ConversionProperties conversionProperties) throws ConvertorNotAvailableException {
    20         if (currency1 == null || currency2 == null || conversionProperties == null)
    21             throw new NullPointerException();
    22 
    23         try {
    24             return new CurrencyConvertorImpl(currency1, currency2, conversionProperties.getConversionRatioProvider(), conversionProperties.getRoundingMode());//can be cached somehow
    25         } catch (Exception e) {
    26             throw new ConvertorNotAvailableException(e);
    27         }
    28     }
    29 }