Singleton-Configuration-Loader and Interfaces with configuration-constants
Hi!
In order to simplify the first version of my application, I have been using Interfaces to define configuration constants. E.g. InterfaceDataConstants: publicfinallong NOT_SET = -1;
Now I would like to expand my application using a singleton ConfigHandler to load the configuration settings as System Properties.
publicstatic String getConfigurationProperty(String property_name)throws ConfigurationError{
if (configarationManager ==null)
configarationManager =new ConfigurationManager();
return System.getProperty(property_name);
}
The constructor ConfigurationManager() calls the init()-method, which reads the configuration file and sets the system properties:
privatevoid init()throws ConfigurationError{
String configFilePath = DataConstants.CONFIG_FILE_NAME_UNIX;
properties =new Properties(System.getProperties());
try{
// Read configuration
properties.load(new BufferedInputStream(new FileInputStream(configFilePath)));
}catch (FileNotFoundException e1){
thrownew ConfigurationError(ErrorConstants.CONFIGURATION_ERROR,"--","Couldn抰 find " +configFilePath+"!");
}catch (IOException e){
thrownew ConfigurationError(ErrorConstants.CONFIGURATION_ERROR,"--"," Couldn抰 read ?configFilePath+"!");
}
// Set Properties
System.setProperties(properties);
}
I hoped, I could just set the constants by calling the static method getConfigurationProperty() and carry on using the constant-interface in my classes. E.g.:
publicfinallong NOT_SET =new Long(ConfigurationManager.getConfigurationProperty("NOT_SET")).longValue();
But I get problems handling possible Exceptions.
Is there any possibility to keep the interfaces? Surely I could use e.g.publiclong user_id = = ConfigurationManager.getConfigurationProperty("NOT_SET");
insead of
publiclong user_id = DataConstants.NOT_SET;
in my classes, but then I have to modify a great number of code lines, which I'd like to prevent. Do you have any advice? Thanks for any help.
Lena

