com.sourceforge.jpatterns.core.configuration
Class PropertiesManagerImpl

java.lang.Object
  extended by com.sourceforge.jpatterns.core.configuration.PropertiesManagerImpl
All Implemented Interfaces:
IPropertiesManager, Serializable

public class PropertiesManagerImpl
extends Object
implements IPropertiesManager

This class manages deals with the properties files JPatterns uses.
Please do not put here any functionality which could be customizable later. Only the functionality fitting the approach: we have default and custom properties files which are taken from the classpath. In the case custom configuration contains the same keys - they would override the default configuration.
Potentially the part of this PropertyManager could be used at the JInit.
Please be noticed the very important method is the following: com.sourceforge.jpatterns.core.configuration.PropertiesManagerImpl#getBundle(java.lang.String), and this method firstly checks the default configuration, and then checks the overriden, custom configuration. todo [zmicer]: think if this could be moved to the common functionality. Think over the PropertiesProvider class - why do we really need\ two these classes? Please finish investigating. todo [zmicer]: introduce the opportunity to setup the necessary names from outside - it would allow us to use this approach as the common functionality. todo [zmicer]: please check in which way the is used here: 0001\src\testdata\jpatterns_custom.properties $Author:: zmicer $
$Rev:: 67 $
* $Date:: 2007-08-28 21:37:07 #$
$Date:: 2007-08-28 21:37:07 #$

See Also:
Serialized Form

Field Summary
static org.apache.log4j.Logger LOG
          Logger instance.
 
Constructor Summary
PropertiesManagerImpl()
          The reason this class has the constructor and implements "singleton" - we are worrying if we need interface for it later.
 
Method Summary
protected  void checkIsInitialized()
          Perform the check if the functionality was initialized.
 boolean customConfigPresents()
           
 boolean defaultConfigPresents()
           
 String getBundle(Class key)
          Get bundle for the provided key - it is a class.
 String getBundle(String key)
          Return the bundle value using the ResourceBundle already retrieved.
 Object getBundledObject(Class key)
          Get bundled object by the key provided.
 Object getBundledObject(String key)
          Get bundled object by the String key provided.
 String getCustomBundle(String key)
          Get the value from the custom bundle. this was provided in any case - potentially it could be used at the unit tests etc.
 String getDefaultBundle(String key)
          Get the value from the default bundle. this was provided in any case - potentially it could be used at the unit tests etc.
 Set<String> getMergedKeys()
           
 void initConfigs()
          Init the resource bundles configuration (methods getDefaultBundleFileName and getCustomBundleFileName are used for the retrieving the actual nname of the properties to be obtained during the initialization process)
Protected to allow to cover that with the unit tests
protected  void initUseOnlyCustomConfigIfPresent()
          Initialize the useOnlyCustomPropsIfPresent field.
 boolean useOnlyCustomConfigIfPresent()
          This method returns the value of the props signing if custom properties file totally overrides the default, and if it is present, then the values from the default properties are not used at all.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.log4j.Logger LOG
Logger instance.

Constructor Detail

PropertiesManagerImpl

public PropertiesManagerImpl()
The reason this class has the constructor and implements "singleton" - we are worrying if we need interface for it later.

Method Detail

checkIsInitialized

protected void checkIsInitialized()
Perform the check if the functionality was initialized. Throws IllegalStateException in the case the functionality was not intialized. Should be used for all the "state read/write" methods just to be sure all is ok.


initConfigs

public void initConfigs()
Init the resource bundles configuration (methods getDefaultBundleFileName and getCustomBundleFileName are used for the retrieving the actual nname of the properties to be obtained during the initialization process)
Protected to allow to cover that with the unit tests


customConfigPresents

public boolean customConfigPresents()
Specified by:
customConfigPresents in interface IPropertiesManager
Returns:
true if the custom resource bundle is presents at the class path
See Also:
IPropertiesManager.customConfigPresents()

defaultConfigPresents

public boolean defaultConfigPresents()
Specified by:
defaultConfigPresents in interface IPropertiesManager
Returns:
true if the default config resource bundle is presents at the class path
See Also:
IPropertiesManager.defaultConfigPresents()

useOnlyCustomConfigIfPresent

public boolean useOnlyCustomConfigIfPresent()
Description copied from interface: IPropertiesManager
This method returns the value of the props signing if custom properties file totally overrides the default, and if it is present, then the values from the default properties are not used at all.
Please review properly the following Java Docs - it is important for understanding of the algorithm of working of the JPatterns configuration functionality. com.sourceforge.jpatterns.core.configuration.PropertiesProvider.JPProperties.USE_ONLY_CUSTOM_FRAMEWORK_PROPERTIES

Specified by:
useOnlyCustomConfigIfPresent in interface IPropertiesManager
Returns:
true if the approrpiate property is set to the true, false otherwise.
See Also:
IPropertiesManager.useOnlyCustomConfigIfPresent()

initUseOnlyCustomConfigIfPresent

protected void initUseOnlyCustomConfigIfPresent()
Initialize the useOnlyCustomPropsIfPresent field.


getBundle

public String getBundle(String key)
Description copied from interface: IPropertiesManager
Return the bundle value using the ResourceBundle already retrieved. This method analyzes two bundles - default and custom one, the priority has custom - it provides the user with the possibility to override the values defined at the default properties, and it is a good customization point for the framework.

Specified by:
getBundle in interface IPropertiesManager
Parameters:
key - for the value we need. Can not be null (otherwise IllegalArgumentException would appear).
Returns:
the value for this bundle or just null in the case there is not defined bundles with such name
See Also:
IPropertiesManager.getBundle(java.lang.String)

getBundle

public String getBundle(Class key)
Description copied from interface: IPropertiesManager
Get bundle for the provided key - it is a class. The shorten name is used - Serializable, PropertiesManagerImpl etc. - without packaging

Specified by:
getBundle in interface IPropertiesManager
Parameters:
key - for the value we need, Class object. Can not be null (otherwise IllegalArgumentException would appear).
Returns:
the value for this bundle or just null in the case there is not defined bundles with such name
See Also:
IPropertiesManager.getBundle(Class)

getBundledObject

public Object getBundledObject(Class key)
Description copied from interface: IPropertiesManager
Get bundled object by the key provided. We would obtain the full class name using this key, and then try to instantiate the object. In the case value for the this key is null, or object can not be instantiated the JPConfigException would appear.

Specified by:
getBundledObject in interface IPropertiesManager
Parameters:
key - the class for which we should obtain appropriate implementation (usually it is class of the interface of abstract class implementation of which we would obtain.)
Returns:
the Object which was instantiated (following the Java Docs above we would throw the JPConfigException exception in the case the key was not found or the object can not be instantiated.)
See Also:
IPropertiesManager.getBundledObject(Class)

getBundledObject

public Object getBundledObject(String key)
Description copied from interface: IPropertiesManager
Get bundled object by the String key provided. We would obtain the full class name using this key, and then try to instantiate the object. In the case value for the this key is null, or object can not be instantiated the JPConfigException would appear.

Specified by:
getBundledObject in interface IPropertiesManager
Parameters:
key - the class for which we should obtain appropriate implementation (usually it is String - base name of the interface of abstract class implementation of which we would obtain.)
Returns:
the Object which was instantiated (following the Java Docs above we would throw the JPConfigException exception in the case the key was not found or the object can not be instantiated.)
See Also:
IPropertiesManager.getBundledObject(String)

getDefaultBundle

public String getDefaultBundle(String key)
Description copied from interface: IPropertiesManager
Get the value from the default bundle. this was provided in any case - potentially it could be used at the unit tests etc.
Please be noticed that we should check if the default configuration presents before the getting the value. The absence of the default configuration is a failure for the JPatterns framework.

Specified by:
getDefaultBundle in interface IPropertiesManager
Parameters:
key - to be processed. Can not be null (otherwise IllegalArgumentException would appear).
Returns:
String, the value required
See Also:
IPropertiesManager.getDefaultBundle(java.lang.String)

getCustomBundle

public String getCustomBundle(String key)
Description copied from interface: IPropertiesManager
Get the value from the custom bundle. this was provided in any case - potentially it could be used at the unit tests etc.
Please be noticed that we should check if the custom configuration presents before the getting the value. The absence of the custom configuration is a normal behavioral of the system.

Specified by:
getCustomBundle in interface IPropertiesManager
Parameters:
key - to be processed. Can not be null (otherwise IllegalArgumentException would appear).
Returns:
String, the value required
See Also:
IPropertiesManager.getCustomBundle(java.lang.String)

getMergedKeys

public Set<String> getMergedKeys()
Specified by:
getMergedKeys in interface IPropertiesManager
Returns:
the Enumeration of the keys (merged one or the custom one or the default one - it depends on the following: a. if custom properties files is present or was specified at the JVM parameter b. study the com.sourceforge.jpatterns.core.configuration.PropertiesProvider.JPProperties.USE_ONLY_CUSTOM_FRAMEWORK_PROPERTIES) todo: [zmicer] think over the caching these values between the initialization periods - just to increase the performance of the framework initialization!


Copyright © 2007 jzmicer.team. All Rights Reserved.