ncsa.tools.common.types
Class Configuration

java.lang.Object
  extended byncsa.tools.common.types.Configuration
All Implemented Interfaces:
UserFacing
Direct Known Subclasses:
TrebuchetConfiguration

public class Configuration
extends java.lang.Object
implements UserFacing

Can be used in one of two ways. Either provides a dynamic set of name-value pairs which can be used to configure an object's "set" methods by reflection; or it carries definitions of properties to be used dynamically in connection with an operation, without their being directly associated with an object's accessor methods.

The principal data type added and stored is a Property; however, its subclass, ActualValueAttribute, can also be added directly.

The "match" operation only attempts to match names and string values, even on the ActualValueAttribute.

If a property name is in the configuration propertyObjectMap and matches an accessor method on the object to be configured, that object will be given the corresponding value for that field by first deserializing the string value.

A single configuration object can be re-used to configure more than one object. Care must be taken, however, to avoid re-use of the same Configuration across objects of different types when these have intersecting method names whose values need to be different, or where default values for those names should not be changed on one of the objects.

Author:
Albert L. Rossi

Field Summary
static java.lang.String TAG_SELF
           
 
Constructor Summary
Configuration()
          Default constructor.
Configuration(Configuration config)
          Does a shallow copy of the configuration.
 
Method Summary
 void addActualValueAttribute(ActualValueAttribute a)
           
 void addActualValueAttribute(java.lang.String name, java.lang.Object value)
           
 Configuration addBooleanProperty(java.lang.String name, boolean b)
           
 void addConfiguredAttribute(Property p)
          This code is for backwards compatibility with OGRE tags, where a Property is passed in as "attribute" without any type designation.
 Configuration addDoubleProperty(java.lang.String name, double d)
           
 Configuration addIntProperty(java.lang.String name, int i)
           
 Configuration addLongProperty(java.lang.String name, long l)
           
 void addProperty(Property p)
           
 Configuration addProperty(java.lang.String name, java.lang.String value)
           
 Configuration addProperty(java.lang.String name, java.lang.String value, java.lang.String type)
           
 Configuration addProperty(java.lang.String name, java.lang.String value, java.lang.String type, java.lang.String category)
           
 org.dom4j.Element asElement()
           
 void clear()
           
 void configureObject(java.lang.Object o)
          Invokes the static method with configuration = this.
static void configureObject(java.lang.Object o, Configuration c)
          Hashes the configuration object if its "dirty" flag is true, then uses ReflectUtils.getAttributes to get the public non-static single- parameter 'set' methods on the object to be configured; for each method whose name appears in the configuration propertyObjectMap, the method is invoked on the object using the mapped value.
 java.lang.Object getActualValue(java.lang.String name)
           
 java.util.List getProperties()
           
 Property getProperty(java.lang.String name)
           
 java.util.Map getPropertyObjectMap()
           
 java.lang.String getPropertyValue(java.lang.String name)
           
 boolean hasMatch(java.lang.String name, java.lang.String value, boolean defaultValue)
           
 boolean hasProperty(java.lang.String name)
           
 void initializeFromElement(org.dom4j.Element element)
           
 Configuration mergeWith(Configuration parent)
          Union of parent with this object; values in this (child) shadow/overwrite identically named values in parent.
 java.util.Map nameValueObjectPairs()
           
 java.util.Map nameValueStringPairs()
           
 Configuration remove(Property p)
           
 Property removeProperty(java.lang.String name)
           
 Configuration setProperties(java.util.List l)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TAG_SELF

public static final java.lang.String TAG_SELF
See Also:
Constant Field Values
Constructor Detail

Configuration

public Configuration()
Default constructor.


Configuration

public Configuration(Configuration config)
Does a shallow copy of the configuration.

Method Detail

clear

public void clear()

asElement

public org.dom4j.Element asElement()
Specified by:
asElement in interface UserFacing

toString

public java.lang.String toString()

initializeFromElement

public void initializeFromElement(org.dom4j.Element element)
Specified by:
initializeFromElement in interface UserFacing

addConfiguredAttribute

public void addConfiguredAttribute(Property p)
This code is for backwards compatibility with OGRE tags, where a Property is passed in as "attribute" without any type designation.


addActualValueAttribute

public void addActualValueAttribute(ActualValueAttribute a)
Parameters:
a - attribute to configure.

addActualValueAttribute

public void addActualValueAttribute(java.lang.String name,
                                    java.lang.Object value)
Parameters:
name - of attribute to configure.
value - of attribute to configure.

addProperty

public void addProperty(Property p)

addProperty

public Configuration addProperty(java.lang.String name,
                                 java.lang.String value)

addBooleanProperty

public Configuration addBooleanProperty(java.lang.String name,
                                        boolean b)

addIntProperty

public Configuration addIntProperty(java.lang.String name,
                                    int i)

addLongProperty

public Configuration addLongProperty(java.lang.String name,
                                     long l)

addDoubleProperty

public Configuration addDoubleProperty(java.lang.String name,
                                       double d)

addProperty

public Configuration addProperty(java.lang.String name,
                                 java.lang.String value,
                                 java.lang.String type)

addProperty

public Configuration addProperty(java.lang.String name,
                                 java.lang.String value,
                                 java.lang.String type,
                                 java.lang.String category)

remove

public Configuration remove(Property p)

removeProperty

public Property removeProperty(java.lang.String name)

setProperties

public Configuration setProperties(java.util.List l)

getProperty

public Property getProperty(java.lang.String name)
Parameters:
name - of property.
Returns:
property object.

getPropertyValue

public java.lang.String getPropertyValue(java.lang.String name)

getActualValue

public java.lang.Object getActualValue(java.lang.String name)

getProperties

public java.util.List getProperties()
Returns:
list of properties in this configuration object.

getPropertyObjectMap

public java.util.Map getPropertyObjectMap()
Returns:
map of properties in this configuration object.

hasProperty

public boolean hasProperty(java.lang.String name)
Parameters:
name - of property.
Returns:
true if property is in this object's propertyObjectMap.

hasMatch

public boolean hasMatch(java.lang.String name,
                        java.lang.String value,
                        boolean defaultValue)
Parameters:
name - of property.
value - string value of property to match.
defaultValue - to return if property is not in the propertyObjectMap.
Returns:
defaultValue if property is not defined in this configuration's propertyObjectMap; else true if property's string value equals the value to match, or if property's string value and value to match are both null; otherwise false.

configureObject

public void configureObject(java.lang.Object o)
                     throws java.lang.Throwable
Invokes the static method with configuration = this.

Parameters:
o - object whose attributes should be configured using this configuration.
Throws:
NCSAException - if reflection or invocation on the object fails.
java.lang.Throwable

mergeWith

public Configuration mergeWith(Configuration parent)
Union of parent with this object; values in this (child) shadow/overwrite identically named values in parent.

Parameters:
parent -
Returns:

nameValueStringPairs

public java.util.Map nameValueStringPairs()
Returns:
flat map of name - property value (String) pairs.

nameValueObjectPairs

public java.util.Map nameValueObjectPairs()
Returns:
flat map of name - attribute value (Object) pairs.

configureObject

public static void configureObject(java.lang.Object o,
                                   Configuration c)
                            throws java.lang.Throwable
Hashes the configuration object if its "dirty" flag is true, then uses ReflectUtils.getAttributes to get the public non-static single- parameter 'set' methods on the object to be configured; for each method whose name appears in the configuration propertyObjectMap, the method is invoked on the object using the mapped value.

If either object or configuration is null, the method is a NOP.

Parameters:
o - object whose attributes should be configured.
c - to use in configuring the object.
Throws:
NCSAException - if reflection or invocation on the object fails.
java.lang.Throwable
See Also:
ReflectUtils.getAttributes(java.lang.Class, boolean), ReflectUtils.invokeOn(java.lang.String, java.lang.Object)