1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/task2/solution01/src/org/apidesign/apifest08/currency/ConvertorsFactory.java Wed Oct 01 10:43:05 2008 +0200
1.3 @@ -0,0 +1,43 @@
1.4 +package org.apidesign.apifest08.currency;
1.5 +
1.6 +/**
1.7 + * Some Factory for Factories :-)
1.8 + * Depends on the whole application design...
1.9 + * @author Ladislav Vitasek
1.10 + */
1.11 +final public class ConvertorsFactory {
1.12 + private CurrencyConvertorFactory currencyConvertorFactoryInstance = null;
1.13 + private final static ConvertorsFactory instance = new ConvertorsFactory();
1.14 +
1.15 +
1.16 + private ConvertorsFactory() {
1.17 +
1.18 + }
1.19 +
1.20 + public static CurrencyConvertorFactory getCurrencyConvertorFactoryInstance() throws CannotInstantiateFactoryException {
1.21 + return getInstance().getCurrencyConvertor();
1.22 + }
1.23 +
1.24 + /**
1.25 + * Returns instance of CurrencyConvertorFactory
1.26 + * @return new instance of CurrencyConvertorFactory
1.27 + * @throws CannotInstantiateFactoryException
1.28 + */
1.29 + private synchronized CurrencyConvertorFactory getCurrencyConvertor() throws CannotInstantiateFactoryException {
1.30 + if (currencyConvertorFactoryInstance == null) {//intern implementation
1.31 +// String className = System.getProperty("currencyFactory", CurrencyConvertorFactoryImpl.class.getName());
1.32 +// try {
1.33 +// currencyConvertorFactoryInstance = (CurrencyConvertorFactory) Class.forName(className).newInstance();
1.34 +// } catch (Exception e) {
1.35 +// throw new CannotInstantiateFactoryException(e);
1.36 +// }
1.37 + //without reflection
1.38 + currencyConvertorFactoryInstance = new CurrencyConvertorFactoryImpl();
1.39 + }
1.40 + return currencyConvertorFactoryInstance;
1.41 + }
1.42 +
1.43 + public static ConvertorsFactory getInstance() {
1.44 + return instance;
1.45 + }
1.46 +}