author | japod@localhost |
Sun, 28 Sep 2008 14:12:38 +0200 | |
changeset 6 | 97662396c0fd |
permissions | -rw-r--r-- |
japod@6 | 1 |
package org.apidesign.apifest08.currency; |
japod@6 | 2 |
|
japod@6 | 3 |
/** |
japod@6 | 4 |
* Some Factory for Factories :-) |
japod@6 | 5 |
* Depends on the whole application design... |
japod@6 | 6 |
* @author Ladislav Vitasek |
japod@6 | 7 |
*/ |
japod@6 | 8 |
final public class ConvertorsFactory { |
japod@6 | 9 |
private CurrencyConvertorFactory currencyConvertorFactoryInstance = null; |
japod@6 | 10 |
private final static ConvertorsFactory instance = new ConvertorsFactory(); |
japod@6 | 11 |
|
japod@6 | 12 |
|
japod@6 | 13 |
private ConvertorsFactory() { |
japod@6 | 14 |
|
japod@6 | 15 |
} |
japod@6 | 16 |
|
japod@6 | 17 |
public static CurrencyConvertorFactory getCurrencyConvertorFactoryInstance() throws CannotInstantiateFactoryException { |
japod@6 | 18 |
return getInstance().getCurrencyConvertor(); |
japod@6 | 19 |
} |
japod@6 | 20 |
|
japod@6 | 21 |
/** |
japod@6 | 22 |
* Returns instance of CurrencyConvertorFactory |
japod@6 | 23 |
* @return new instance of CurrencyConvertorFactory |
japod@6 | 24 |
* @throws CannotInstantiateFactoryException |
japod@6 | 25 |
*/ |
japod@6 | 26 |
private synchronized CurrencyConvertorFactory getCurrencyConvertor() throws CannotInstantiateFactoryException { |
japod@6 | 27 |
if (currencyConvertorFactoryInstance == null) {//intern implementation |
japod@6 | 28 |
// String className = System.getProperty("currencyFactory", CurrencyConvertorFactoryImpl.class.getName()); |
japod@6 | 29 |
// try { |
japod@6 | 30 |
// currencyConvertorFactoryInstance = (CurrencyConvertorFactory) Class.forName(className).newInstance(); |
japod@6 | 31 |
// } catch (Exception e) { |
japod@6 | 32 |
// throw new CannotInstantiateFactoryException(e); |
japod@6 | 33 |
// } |
japod@6 | 34 |
//without reflection |
japod@6 | 35 |
currencyConvertorFactoryInstance = new CurrencyConvertorFactoryImpl(); |
japod@6 | 36 |
} |
japod@6 | 37 |
return currencyConvertorFactoryInstance; |
japod@6 | 38 |
} |
japod@6 | 39 |
|
japod@6 | 40 |
public static ConvertorsFactory getInstance() { |
japod@6 | 41 |
return instance; |
japod@6 | 42 |
} |
japod@6 | 43 |
} |