|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.metamatrix.common.properties.PropertyManager
public class PropertyManager
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");
- }
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 |
---|
public PropertyManager()
public PropertyManager(java.lang.String namespace)
namespace
- The namespace identifierpublic PropertyManager(java.lang.String[] namespaces)
namespaces
- The list of namespace identifierspublic PropertyManager(java.util.List namespaces)
namespaces
- The list of namespace identifierspublic PropertyManager(java.lang.String namespace, java.util.Map propertyMap)
namespace
- The namespace identifierpropertyMap
- The map into which the property values are loadedMethod Detail |
---|
public static java.util.Set getLoadedNamespaces()
public static boolean isNamespaceLoaded(java.lang.String namespace)
namespace
- The namespace identifier
protected static void load(java.lang.String name)
name
- The name of the resource bundle
java.util.MissingResourceException
- If the resource associated with the namespace could not be found.protected static void load(java.lang.String name, java.util.Map propertyMap)
name
- The name of the resource bundlepropertyMap
- The map into which the property values are loaded
java.util.MissingResourceException
- If the resource associated with the namespace could not be found.protected static void load(java.lang.String name, boolean reload, java.util.Map propertyMap)
name
- The name of the resource bundlereload
- True if the bundle should be reloadedpropertyMap
- The map into which the property values are loaded
java.util.MissingResourceException
- If the resource associated with the namespace could not be found.public static void reload(java.lang.String name)
name
- The name of the resource bundle
java.util.MissingResourceException
- If the resource associated with the namespace could not be found.public static void reload(java.lang.String name, java.util.Map propertyMap)
name
- The name of the resource bundlepropertyMap
- The map into which the property values are loaded
java.util.MissingResourceException
- If the resource associated with the namespace could not be found.public boolean addNamespace(java.lang.String namespace)
namespace
- The namespace identifier
public boolean addNamespace(java.lang.String namespace, java.util.Map propertyMap)
namespace
- The namespace identifierpropertyMap
- The map into which the property values are loaded
public boolean addNamespaces(java.lang.String[] namespaces)
namespaces
- The list of namespace identifiers
public boolean addNamespaces(java.util.List namespaces)
namespaces
- The list of namespace identifiers
public void clearNamespaces()
protected void constructPropertyManager(java.util.List namespaces, java.util.Map propertyMap)
namespaces
- The list of namespace identifiers passed in the constructorpropertyMap
- The map into which the property values are loaded if a single namespace is specifiedprotected java.lang.Object evaluateValue(java.lang.String key, java.lang.String value)
key
- The property's case-sensitive key; never null.The
- property value; never null.
public java.lang.Object get(java.lang.String key)
key
- The property's case-sensitive key
public java.util.List getNamespaces()
protected void initializeNamespaces(java.util.List namespaces, java.util.Map propertyMap)
#initializePropertyManager(List, Map)
to register any namespaces passed in the constructor.
namespaces
- The list of namespace identifiers passed in the constructorpropertyMap
- The map into which the property values are loaded if a single namespace is specifiedpublic boolean isNamespaceRegistered(java.lang.String namespace)
namespace
- The namespace identifier
addNamespace(String)
,
addNamespaces(List)
public boolean removeNamespace(java.lang.String namespace)
namespace
- The namespace identifier
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |