com.metamatrix.common.properties
Class PropertyManager

java.lang.Object
  extended by com.metamatrix.common.properties.PropertyManager
All Implemented Interfaces:
LogCommonConstants
Direct Known Subclasses:
TextManager

public class PropertyManager
extends java.lang.Object
implements LogCommonConstants

PropertyManager provides the ability to manage application properties stored in resource bundles. This allows for locale-specific retrieval of property values. Instances of PropertyManager retrieve property values from registered namespaces, which ultimately map to a properties file or class in the same manner as a resource bundle, and in fact must conform to resource bundle naming conventions. Multiple namespaces can be used to retrieve property values, such that if a value is not found in a particular namespace, the previously registered namespace will be searched next, and so on until the value is found or all registered namespaces have been exhausted.

To use PropertyManager, an instance of PropertyManager must be created, and the namespaces to be searched must be registered with this instance in the reverse order that they should be searched (In other words, the first name-space registered will be searched last). The property values within the resource bundles can then be retrieved using the getter methods provided, passing appropriate property keys as arguments.

Notes:

Example:

Resource Bundle (com/metamatrix/someproject/some.properties)

Key1 = Value1
Key2 = Value2

Code

public static void main() {
final PropertyManager propMgr = new PropertyManager("com/metamatrix/someproject/some");
final Object val = propMgr.get("Key1");
}

Since:
3.1
See Also:
ResourceBundle

Field Summary
 
Fields inherited from interface com.metamatrix.common.util.LogCommonConstants
CTX_BUFFER_MGR, CTX_CONFIG, CTX_CONTROLLER, CTX_DBIDGEN, CTX_DISTRIB_CACHE, CTX_EXTENSION_SOURCE, CTX_EXTENSION_SOURCE_JDBC, CTX_LOGGING, CTX_LOGON, CTX_MESSAGE_BUS, CTX_POOLING, CTX_PROXY, CTX_SERVICE, CTX_STANDARD_ERR, CTX_STANDARD_OUT, CTX_STORAGE_MGR, CTX_TXN_LOG, CTX_XA_TXN, TYPE_DEBUG, TYPE_ERROR, TYPE_EXCEPTION, TYPE_INFO, TYPE_TRACE, TYPE_WARNING
 
Constructor Summary
PropertyManager()
          Creates an instance of PropertyManager with no registered namespaces.
PropertyManager(java.util.List namespaces)
          Creates an instance of PropertyManager that will retrieve property values from the specified list of namespaces.
PropertyManager(java.lang.String namespace)
          Creates an instance of PropertyManager that will retrieve property values from the specified namespace.
PropertyManager(java.lang.String[] namespaces)
          Creates an instance of PropertyManager that will retrieve property values from the specified list of namespaces.
PropertyManager(java.lang.String namespace, java.util.Map propertyMap)
          Creates an instance of PropertyManager that will retrieve property values from the specified namespace.
 
Method Summary
 boolean addNamespace(java.lang.String namespace)
          Adds the specified namespace to the list of registered namespaces to search when retrieving property values.
 boolean addNamespace(java.lang.String namespace, java.util.Map propertyMap)
          Adds the specified namespace to the list of registered namespaces to search when retrieving property values.
 boolean addNamespaces(java.util.List namespaces)
          Adds the specified list of namespaces to the list of registered namespaces to search when retrieving property values.
 boolean addNamespaces(java.lang.String[] namespaces)
          Adds the specified list of namespaces to the list of registered namespaces to search when retrieving property values.
 void clearNamespaces()
          Removes all naemspaces from the list of registered naemspaces.
protected  void constructPropertyManager(java.util.List namespaces, java.util.Map propertyMap)
          Called by each constructor to initialize the namespaces list and register any namespaces passed in the constructor.
protected  java.lang.Object evaluateValue(java.lang.String key, java.lang.String value)
          Provided for subclasses to control the evaluation of retrieved property values.
 java.lang.Object get(java.lang.String key)
          Retrieves the value of the property identified by the specified case-sensitive key.
static java.util.Set getLoadedNamespaces()
          Returns The set of namespaces that have been loaded
 java.util.List getNamespaces()
          Returns The list of namespaces registered to be searched for property values
protected  void initializeNamespaces(java.util.List namespaces, java.util.Map propertyMap)
          Called by #initializePropertyManager(List, Map) to register any namespaces passed in the constructor.
static boolean isNamespaceLoaded(java.lang.String namespace)
          Returns whether the specified namespace has been loaded.
 boolean isNamespaceRegistered(java.lang.String namespace)
          Returns whether the specified namespace has been registered.
protected static void load(java.lang.String name)
          Loads the resource bundle with the specified name and stores the name as a namespace.
protected static void load(java.lang.String name, boolean reload, java.util.Map propertyMap)
          Loads or reloads, as specified, the resource bundle with the specified name into the specified map and stores the name as a namespace.
protected static void load(java.lang.String name, java.util.Map propertyMap)
          Loads the resource bundle with the specified name into the specified map and stores the name as a namespace.
static void reload(java.lang.String name)
          Reloads the resource bundle with the specified name.
static void reload(java.lang.String name, java.util.Map propertyMap)
          Reloads the resource bundle with the specified name into the specified map.
 boolean removeNamespace(java.lang.String namespace)
          Removes the specified namespace from the list of registered namespaces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyManager

public PropertyManager()
Creates an instance of PropertyManager with no registered namespaces.

Since:
3.1

PropertyManager

public PropertyManager(java.lang.String namespace)
Creates an instance of PropertyManager that will retrieve property values from the specified namespace.

Parameters:
namespace - The namespace identifier
Since:
3.1

PropertyManager

public PropertyManager(java.lang.String[] namespaces)
Creates an instance of PropertyManager that will retrieve property values from the specified list of namespaces. The namespaces will be searched in ascending order, starting with the first namespace registered.

Parameters:
namespaces - The list of namespace identifiers
Since:
3.1

PropertyManager

public PropertyManager(java.util.List namespaces)
Creates an instance of PropertyManager that will retrieve property values from the specified list of namespaces. The namespaces will be searched in ascending order, starting with the first namespace registered.

Parameters:
namespaces - The list of namespace identifiers
Since:
3.1

PropertyManager

public PropertyManager(java.lang.String namespace,
                       java.util.Map propertyMap)
Creates an instance of PropertyManager that will retrieve property values from the specified namespace. Properties from the resource bundle identified by the namespace will be loaded into the specified property map.

Parameters:
namespace - The namespace identifier
propertyMap - The map into which the property values are loaded
Since:
3.1
Method Detail

getLoadedNamespaces

public static java.util.Set getLoadedNamespaces()
Returns The set of namespaces that have been loaded

Returns:
The set of loaded namespaces
Since:
3.1

isNamespaceLoaded

public static boolean isNamespaceLoaded(java.lang.String namespace)
Returns whether the specified namespace has been loaded.

Parameters:
namespace - The namespace identifier
Returns:
True if the namespace has been loaded
Since:
3.1

load

protected static void load(java.lang.String name)
Loads the resource bundle with the specified name and stores the name as a namespace. The name, which represents a file path, must be specified with a path relative to the current classpath and with no extensions or periods in the filename.

Parameters:
name - The name of the resource bundle
Throws:
java.util.MissingResourceException - If the resource associated with the namespace could not be found.
Since:
3.1

load

protected static void load(java.lang.String name,
                           java.util.Map propertyMap)
Loads the resource bundle with the specified name into the specified map and stores the name as a namespace. The name, which represents a file path, must be specified with a path relative to the current classpath and with no extensions or periods in the filename.

Parameters:
name - The name of the resource bundle
propertyMap - The map into which the property values are loaded
Throws:
java.util.MissingResourceException - If the resource associated with the namespace could not be found.
Since:
3.1

load

protected static void load(java.lang.String name,
                           boolean reload,
                           java.util.Map propertyMap)
Loads or reloads, as specified, the resource bundle with the specified name into the specified map and stores the name as a namespace. The name, which represents a file path, must be specified with a path relative to the current classpath and with no extensions or periods in the filename.

Parameters:
name - The name of the resource bundle
reload - True if the bundle should be reloaded
propertyMap - The map into which the property values are loaded
Throws:
java.util.MissingResourceException - If the resource associated with the namespace could not be found.
Since:
3.1

reload

public static void reload(java.lang.String name)
Reloads the resource bundle with the specified name.

Parameters:
name - The name of the resource bundle
Throws:
java.util.MissingResourceException - If the resource associated with the namespace could not be found.
Since:
3.1

reload

public static void reload(java.lang.String name,
                          java.util.Map propertyMap)
Reloads the resource bundle with the specified name into the specified map.

Parameters:
name - The name of the resource bundle
propertyMap - The map into which the property values are loaded
Throws:
java.util.MissingResourceException - If the resource associated with the namespace could not be found.
Since:
3.1

addNamespace

public boolean addNamespace(java.lang.String namespace)
Adds the specified namespace to the list of registered namespaces to search when retrieving property values. The order that namespaces are registered is important, whereas the last namespace registered will be the first to be searched.

Parameters:
namespace - The namespace identifier
Returns:
True if the namespace was successfully registered, false if it was previously registered or its associated resource bundle was not found.
Since:
3.1

addNamespace

public boolean addNamespace(java.lang.String namespace,
                            java.util.Map propertyMap)
Adds the specified namespace to the list of registered namespaces to search when retrieving property values. The order that namespaces are registered is important, whereas the last namespace registered will be the first to be searched. Properties from the resource bundle identified by the namespace will be loaded into the specified property map.

Parameters:
namespace - The namespace identifier
propertyMap - The map into which the property values are loaded
Returns:
True if the namespace was successfully registered, false if it was previously registered or its associated resource bundle was not found.
Since:
3.1

addNamespaces

public boolean addNamespaces(java.lang.String[] namespaces)
Adds the specified list of namespaces to the list of registered namespaces to search when retrieving property values. The order that namespaces are registered is important, whereas the last namespace registered will be the first to be searched.

Parameters:
namespaces - The list of namespace identifiers
Returns:
True if all namespaces were successfully registered, false if any were previously registered or any of the associated resource bundles were not found.
Since:
3.1

addNamespaces

public boolean addNamespaces(java.util.List namespaces)
Adds the specified list of namespaces to the list of registered namespaces to search when retrieving property values. The order that namespaces are registered is important, whereas the last naemspace registered will be the first to be searched.

Parameters:
namespaces - The list of namespace identifiers
Returns:
True if all namespaces were successfully registered, false if any were previously registered or any of the associated resource bundles were not found.
Since:
3.1

clearNamespaces

public void clearNamespaces()
Removes all naemspaces from the list of registered naemspaces.

Since:
3.1

constructPropertyManager

protected void constructPropertyManager(java.util.List namespaces,
                                        java.util.Map propertyMap)
Called by each constructor to initialize the namespaces list and register any namespaces passed in the constructor.

Parameters:
namespaces - The list of namespace identifiers passed in the constructor
propertyMap - The map into which the property values are loaded if a single namespace is specified
Since:
3.1

evaluateValue

protected java.lang.Object evaluateValue(java.lang.String key,
                                         java.lang.String value)
Provided for subclasses to control the evaluation of retrieved property values.

Parameters:
key - The property's case-sensitive key; never null.
The - property value; never null.
Returns:
The evaluated value.
Since:
3.1

get

public java.lang.Object get(java.lang.String key)
Retrieves the value of the property identified by the specified case-sensitive key.

Parameters:
key - The property's case-sensitive key
Returns:
The property value; may be null
Since:
2.1

getNamespaces

public java.util.List getNamespaces()
Returns The list of namespaces registered to be searched for property values

Returns:
The list of registered namespaces
Since:
3.1

initializeNamespaces

protected void initializeNamespaces(java.util.List namespaces,
                                    java.util.Map propertyMap)
Called by #initializePropertyManager(List, Map) to register any namespaces passed in the constructor.

Parameters:
namespaces - The list of namespace identifiers passed in the constructor
propertyMap - The map into which the property values are loaded if a single namespace is specified
Since:
3.1

isNamespaceRegistered

public boolean isNamespaceRegistered(java.lang.String namespace)
Returns whether the specified namespace has been registered.

Parameters:
namespace - The namespace identifier
Returns:
True if the namespace has been registered
Since:
3.1
See Also:
addNamespace(String), addNamespaces(List)

removeNamespace

public boolean removeNamespace(java.lang.String namespace)
Removes the specified namespace from the list of registered namespaces.

Parameters:
namespace - The namespace identifier
Returns:
True if the namespace was successfully removed, false if it was not previously registered
Since:
3.1


Copyright © 2009. All Rights Reserved.