com.metamatrix.common.properties
Class ObjectPropertyManager

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

public class ObjectPropertyManager
extends TextManager

ObjectPropertyManager adds to TextManager the ability to apply a Java interpreter to evaluate property values at runtime. This means that all property values evaluate to Objects, which provides an easy means to specify complex property values.

Since the values within the resource bundles are interpreted, they must be specified using Java syntax (although trailing semicolons are optional). A special variable, "mgr", can be used within property values to reference the instance of ObjectPropertyManager retrieving the value, and is intended for accessing the getter methods of that instance.

Notes:

Example:

Resource Bundle (com/metamatrix/toolbox/uiDefaults.properties)

message.key = "line1\\nline2"
other.key = 3
integer.property.key = mgr.get("other.key")

Code

public static void main() {
final ObjectPropertyManager propMgr = new ObjectPropertyManager("com/metamatrix/toolbox/uiDefaults");
final int intProp = propMgr.getInt("integer.property.key");
}

Since:
2.1
See Also:
ResourceBundle

Field Summary
 
Fields inherited from class com.metamatrix.common.properties.TextManager
DEFAULT_NAMESPACES, INSTANCE
 
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
ObjectPropertyManager()
          Creates an instance of ObjectPropertyManager with no namespaces.
ObjectPropertyManager(java.util.List namespaces)
          Creates an instance of ObjectPropertyManager that will retrieve property values from the specified list of namespaces.
ObjectPropertyManager(java.lang.String namespace)
          Creates an instance of ObjectPropertyManager that will retrieve property values from the specified namespace.
ObjectPropertyManager(java.lang.String[] namespaces)
          Creates an instance of ObjectPropertyManager that will retrieve property values from the specified list of namespaces.
ObjectPropertyManager(java.lang.String namespace, java.util.Map propertyMap)
          Creates an instance of ObjectPropertyManager that will retrieve property values from the specified namespace.
 
Method Summary
protected static void assertClass(java.lang.String key, java.lang.Object value, java.lang.Class expectedClass)
          Verifies that the specified value is an instance of the specified class.
protected  void constructObjectPropertyManager(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.
 boolean getBoolean(java.lang.String key)
          Retrieves the boolean value of the property identified by the specified key.
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Retrieves the boolean value of the property identified by the specified key, or if not found, returns the specified default value.
 byte getByte(java.lang.String key)
          Retrieves the byte value of the property identified by the specified key.
 byte getByte(java.lang.String key, byte defaultValue)
          Retrieves the byte value of the property identified by the specified key, or if not found, returns the specified default value.
 char getChar(java.lang.String key)
          Retrieves the char value of the property identified by the specified key.
 char getChar(java.lang.String key, char defaultValue)
          Retrieves the char value of the property identified by the specified key, or if not found, returns the specified default value.
 double getDouble(java.lang.String key)
          Retrieves the double value of the property identified by the specified key.
 double getDouble(java.lang.String key, double defaultValue)
          Retrieves the double value of the property identified by the specified key, or if not found, returns the specified default value.
 float getFloat(java.lang.String key)
          Retrieves the float value of the property identified by the specified key.
 float getFloat(java.lang.String key, float defaultValue)
          Retrieves the float value of the property identified by the specified key, or if not found, returns the specified default value.
 int getInt(java.lang.String key)
          Retrieves the int value of the property identified by the specified key.
 int getInt(java.lang.String key, int defaultValue)
          Retrieves the int value of the property identified by the specified key, or if not found, returns the specified default value.
 Interpreter getInterpreter()
          Returns the Java interpreter used to evaluate poroperty values.
 long getLong(java.lang.String key)
          Retrieves the long value of the property identified by the specified key.
 long getLong(java.lang.String key, long defaultValue)
          Retrieves the long value of the property identified by the specified key, or if not found, returns the specified default value.
protected  java.lang.Object getNonNullObject(java.lang.String key)
          Retrieves the value of the property identified by the specified key.
 short getShort(java.lang.String key)
          Retrieves the short value of the property identified by the specified key.
 short getShort(java.lang.String key, short defaultValue)
          Retrieves the short value of the property identified by the specified key, or if not found, returns the specified default value.
 java.lang.String getString(java.lang.String key)
          Retrieves the String value of the property identified by the specified key.
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Retrieves the String value of the property identified by the specified key, or if not found, returns the specified default value.
protected static void throwRuntimeException(java.lang.Exception error)
          Throws the specified exception as a RuntimeException.
 
Methods inherited from class com.metamatrix.common.properties.TextManager
getText, getText, getText, getText, getText, getText, getText, getText, getText, getText, getText, getText, getText, getText, translate
 
Methods inherited from class com.metamatrix.common.properties.PropertyManager
addNamespace, addNamespace, addNamespaces, addNamespaces, clearNamespaces, constructPropertyManager, get, getLoadedNamespaces, getNamespaces, initializeNamespaces, isNamespaceLoaded, isNamespaceRegistered, load, load, load, reload, reload, removeNamespace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectPropertyManager

public ObjectPropertyManager()
Creates an instance of ObjectPropertyManager with no namespaces.

Since:
2.1

ObjectPropertyManager

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

Parameters:
namespace - The namespace identifier
Since:
2.1

ObjectPropertyManager

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

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

ObjectPropertyManager

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

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

ObjectPropertyManager

public ObjectPropertyManager(java.lang.String namespace,
                             java.util.Map propertyMap)
Creates an instance of ObjectPropertyManager 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:
2.1
Method Detail

assertClass

protected static void assertClass(java.lang.String key,
                                  java.lang.Object value,
                                  java.lang.Class expectedClass)
Verifies that the specified value is an instance of the specified class.

Parameters:
key - The key used to retrieve the value
value - The value to verify
expectedClass - The class of which the value must be an instance
Throws:
java.lang.ClassCastException - If the value is not an instance of the specified class.
Since:
2.1

throwRuntimeException

protected static void throwRuntimeException(java.lang.Exception error)
Throws the specified exception as a RuntimeException.

Parameters:
error - An exception
Since:
2.1

constructObjectPropertyManager

protected void constructObjectPropertyManager(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:
2.1

evaluateValue

protected java.lang.Object evaluateValue(java.lang.String key,
                                         java.lang.String value)
Description copied from class: PropertyManager
Provided for subclasses to control the evaluation of retrieved property values.

Overrides:
evaluateValue in class PropertyManager
Parameters:
key - The property's case-sensitive key; never null.
Returns:
The evaluated value.

getBoolean

public boolean getBoolean(java.lang.String key)
Retrieves the boolean value of the property identified by the specified key.

Parameters:
key - The property key
Returns:
The property value
Throws:
java.util.MissingResourceException - If the value could not be found
Since:
2.1

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
Retrieves the boolean value of the property identified by the specified key, or if not found, returns the specified default value.

Parameters:
key - The property key
defaultValue - The default value
Returns:
The property value, or the default value if not found
Since:
2.1

getByte

public byte getByte(java.lang.String key)
Retrieves the byte value of the property identified by the specified key.

Parameters:
key - The property key
Returns:
The property value
Throws:
java.util.MissingResourceException - If the value could not be found
Since:
2.1

getByte

public byte getByte(java.lang.String key,
                    byte defaultValue)
Retrieves the byte value of the property identified by the specified key, or if not found, returns the specified default value.

Parameters:
key - The property key
defaultValue - The default value
Returns:
The property value, or the default value if not found
Since:
2.1

getChar

public char getChar(java.lang.String key)
Retrieves the char value of the property identified by the specified key.

Parameters:
key - The property key
Returns:
The property value
Throws:
java.util.MissingResourceException - If the value could not be found
Since:
2.1

getChar

public char getChar(java.lang.String key,
                    char defaultValue)
Retrieves the char value of the property identified by the specified key, or if not found, returns the specified default value.

Parameters:
key - The property key
defaultValue - The default value
Returns:
The property value, or the default value if not found
Since:
2.1

getDouble

public double getDouble(java.lang.String key)
Retrieves the double value of the property identified by the specified key.

Parameters:
key - The property key
Returns:
The property value
Throws:
java.util.MissingResourceException - If the value could not be found
Since:
2.1

getDouble

public double getDouble(java.lang.String key,
                        double defaultValue)
Retrieves the double value of the property identified by the specified key, or if not found, returns the specified default value.

Parameters:
key - The property key
defaultValue - The default value
Returns:
The property value, or the default value if not found
Since:
2.1

getFloat

public float getFloat(java.lang.String key)
Retrieves the float value of the property identified by the specified key.

Parameters:
key - The property key
Returns:
The property value
Throws:
java.util.MissingResourceException - If the value could not be found
Since:
2.1

getFloat

public float getFloat(java.lang.String key,
                      float defaultValue)
Retrieves the float value of the property identified by the specified key, or if not found, returns the specified default value.

Parameters:
key - The property key
defaultValue - The default value
Returns:
The property value, or the default value if not found
Since:
2.1

getInt

public int getInt(java.lang.String key)
Retrieves the int value of the property identified by the specified key.

Parameters:
key - The property key
Returns:
The property value
Throws:
java.util.MissingResourceException - If the value could not be found
Since:
2.1

getInt

public int getInt(java.lang.String key,
                  int defaultValue)
Retrieves the int value of the property identified by the specified key, or if not found, returns the specified default value.

Parameters:
key - The property key
defaultValue - The default value
Returns:
The property value, or the default value if not found
Since:
2.1

getInterpreter

public Interpreter getInterpreter()
Returns the Java interpreter used to evaluate poroperty values. The interpreter can be customized, for instance, to include additional import statements so package names do not need to be specified in property values, or to define methods that may be called within a property value.

Returns:
The interpreter
Since:
2.1

getLong

public long getLong(java.lang.String key)
Retrieves the long value of the property identified by the specified key.

Parameters:
key - The property key
Returns:
The property value
Throws:
java.util.MissingResourceException - If the value could not be found
Since:
2.1

getLong

public long getLong(java.lang.String key,
                    long defaultValue)
Retrieves the long value of the property identified by the specified key, or if not found, returns the specified default value.

Parameters:
key - The property key
defaultValue - The default value
Returns:
The property value, or the default value if not found
Since:
2.1

getNonNullObject

protected java.lang.Object getNonNullObject(java.lang.String key)
Retrieves the value of the property identified by the specified key.

Parameters:
key - The property key
Returns:
The property value
Throws:
java.util.MissingResourceException - If the value could not be found
Since:
2.1

getShort

public short getShort(java.lang.String key)
Retrieves the short value of the property identified by the specified key.

Parameters:
key - The property key
Returns:
The property value
Throws:
java.util.MissingResourceException - If the value could not be found
Since:
2.1

getShort

public short getShort(java.lang.String key,
                      short defaultValue)
Retrieves the short value of the property identified by the specified key, or if not found, returns the specified default value.

Parameters:
key - The property key
defaultValue - The default value
Returns:
The property value, or the default value if not found
Since:
2.1

getString

public java.lang.String getString(java.lang.String key)
Retrieves the String value of the property identified by the specified key.

Parameters:
key - The property key
Returns:
The property value, or null if not found
Since:
2.1

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)
Retrieves the String value of the property identified by the specified key, or if not found, returns the specified default value.

Parameters:
key - The property key
defaultValue - The default value
Returns:
The property value, or the default value if not found
Since:
1.0


Copyright © 2009. All Rights Reserved.