Author: dcosse Date: 2014-09-29 18:26:31 +0200 (Mon, 29 Sep 2014) New Revision: 3929 Url: http://forge.chorem.org/projects/lima/repository/revisions/3929 Log: refs #1115 on s'assure que LimaServiceConfig ne peut-?\195?\170tre qu'un singleton, le constructeur n'est plus public Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaServiceConfig.java trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestsConfig.java trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaServiceConfig.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaServiceConfig.java 2014-09-29 13:16:00 UTC (rev 3928) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaServiceConfig.java 2014-09-29 16:26:31 UTC (rev 3929) @@ -65,13 +65,13 @@ protected static final String LIMA_DEFAULT_CONF_FILENAME = "lima.properties"; - protected static ApplicationConfig config; + protected ApplicationConfig config; + protected Properties rootContextProperties; + protected static volatile LimaServiceConfig instance; - protected static Properties rootContextProperties; - - public LimaServiceConfig(String configFileName) { + private LimaServiceConfig(String configFileName) { try { ApplicationConfig defaultConfig = new ApplicationConfig(LIMA_DEFAULT_CONF_FILENAME); defaultConfig.loadDefaultOptions(ServiceConfigOption.values()); @@ -94,8 +94,8 @@ } } - public static Properties getRootContextProperties() { - if (rootContextProperties == null) { + protected static Properties getRootContextProperties() { + if (getInstance().rootContextProperties == null) { Properties result = instance.getFlatOptions(); // add persistence classes from generated code result.setProperty(TopiaConfigurationConstants.CONFIG_PERSISTENCE_CLASSES, LimaCallaoEntityEnum.getImplementationClassesAsString()); @@ -110,11 +110,18 @@ result.setProperty(entry.getKey(), entry.getValue()); } } - rootContextProperties = result; + getInstance().setRootContextProperties(result); + + } - return rootContextProperties; + Properties result = getInstance().rootContextProperties; + return result; } + protected void setRootContextProperties(Properties rootContextProperties) { + this.rootContextProperties = rootContextProperties; + } + public static LimaServiceConfig getInstance(String configFileName) { if (instance == null) { instance= new LimaServiceConfig(configFileName); @@ -129,6 +136,10 @@ return instance; } + protected void setConfig(ApplicationConfig config) { + this.config = config; + } + public ApplicationConfig getConfig() { return config; } @@ -150,7 +161,7 @@ } protected static void loadAccountingRules() { - Class<?> accountingRulesClass = config.getOptionAsClass(ServiceConfigOption.RULES_NATIONALTY.key); + Class<?> accountingRulesClass = getInstance().config.getOptionAsClass(ServiceConfigOption.RULES_NATIONALTY.key); if (accountingRulesClass == null) { if (log.isErrorEnabled()) { log.error("No accounting rules defined for:" + ServiceConfigOption.RULES_NATIONALTY.key); @@ -177,7 +188,7 @@ } public void setAccountingRule(String accountingRule) { - LimaServiceConfig.config.setOption(ServiceConfigOption.RULES_NATIONALTY.key, accountingRule); + LimaServiceConfig.getInstance().config.setOption(ServiceConfigOption.RULES_NATIONALTY.key, accountingRule); // clear cache loadAccountingRules(); } Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-09-29 13:16:00 UTC (rev 3928) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-09-29 16:26:31 UTC (rev 3929) @@ -114,8 +114,8 @@ public void initAbstractTest() throws Exception { setUpLocale(); Properties options = getTestConfiguration(); - LimaServiceConfig limaTestConfig = new LimaTestsConfig(LIMA_TEST_DEFAULT_CONF_FILENAME, options); - initServices(limaTestConfig); + new LimaTestsConfig(LIMA_TEST_DEFAULT_CONF_FILENAME, options); + initServices(); context = createNewTestApplicationContext(); } @@ -127,9 +127,9 @@ * Init services after i18n#init(). * @throws java.io.IOException */ - protected void initServices(LimaServiceConfig config) throws IOException { + protected void initServices() throws IOException { if(accountService == null) { - LimaServiceFactory.initFactory(config.getConfig()); + LimaServiceFactory.initFactory(LimaServiceConfig.getInstance().getConfig()); accountService = LimaServiceFactory.getService(AccountService.class); entryBookService = LimaServiceFactory.getService(EntryBookService.class); financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class); Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestsConfig.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestsConfig.java 2014-09-29 13:16:00 UTC (rev 3928) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestsConfig.java 2014-09-29 16:26:31 UTC (rev 3929) @@ -35,21 +35,21 @@ /** * Created by davidcosse on 11/06/14. */ -public class LimaTestsConfig extends LimaServiceConfig { +public class LimaTestsConfig { public LimaTestsConfig(String configFileName, Properties limaTestConfig) { - super(configFileName); - Properties standardLimaConfig = config.getFlatOptions(); + LimaServiceConfig instance = LimaServiceConfig.getInstance(configFileName); + Properties standardLimaConfig = instance.getConfig().getFlatOptions(); for (Map.Entry<Object, Object> entry : limaTestConfig.entrySet()) { standardLimaConfig.setProperty((String)entry.getKey(),(String)entry.getValue()); } - config = new ApplicationConfig(standardLimaConfig); - instance = this; + ApplicationConfig testConfig = new ApplicationConfig(standardLimaConfig); + instance.setConfig(testConfig); setRootContextProperties(instance); } - public void setRootContextProperties(LimaServiceConfig instance) { + protected void setRootContextProperties(LimaServiceConfig instance) { Properties result = instance.getFlatOptions(); // add persistence classes from generated code result.setProperty(TopiaConfigurationConstants.CONFIG_PERSISTENCE_CLASSES, LimaCallaoEntityEnum.getImplementationClassesAsString()); @@ -64,8 +64,7 @@ result.setProperty(entry.getKey(), entry.getValue()); } } - rootContextProperties = result; - + instance.setRootContextProperties(result); } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java 2014-09-29 13:16:00 UTC (rev 3928) +++ trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java 2014-09-29 16:26:31 UTC (rev 3929) @@ -53,10 +53,10 @@ private static final Log log = LogFactory.getLog(LimaMain.class); /** Lima configuration. */ - public static LimaSwingConfig config; + protected static LimaSwingConfig config; /** splash */ - private static LimaSplash splash; + protected static LimaSplash splash; /** * Lima main method.