org.jboss.soa.esb.helpers
Class ConfigTree

java.lang.Object
  extended by org.jboss.soa.esb.helpers.ConfigTree
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
NotificationList

public class ConfigTree
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Objects of this class are to be used for run time configuration of ESB components

This should gradually replace the ConfigTree class
It is a subset of Tree that accepts a Map of attributes, and a List of children
children can only be String values, or objects of this class

fromXml() and toXml() methods allow 'visible' representations of objects of this class and run time loading/dumping from/to standard XML documents

Author:
schifest@heuristica.com.ar
See Also:
Serialized Form

Constructor Summary
protected ConfigTree(ConfigTree other)
          protected constructor
  ConfigTree(java.lang.String name)
          Constructor of a root node (an uppermost ConfigTree)
  ConfigTree(java.lang.String name, ConfigTree dad)
          Constructor of a ConfigTree as a child of another (second arg)
 
Method Summary
 void addTextChild(java.lang.String value)
          add a child element that consists only of the text in arg0
 int attributeCount()
           
 java.util.List<KeyValuePair> attributesAsList()
          obtain the list of all attribute as a List
 int childCount()
           
 java.util.List<KeyValuePair> childPropertyList()
          obtain the list of all child "property" elements as a List
 java.lang.Object clone()
           
 ConfigTree cloneObj()
          instantiate a new ConfigTree with the same topology and contents of 'this'
Contained ConfigTree child elements will also be cloned
Transient objects are NOT copied nor cloned
protected  void copyFrom(ConfigTree other)
          Deep copy of other tree
static ConfigTree fromElement(org.w3c.dom.Element elem)
           
static ConfigTree fromInputStream(java.io.InputStream input)
          obtain an instance of this class, from a 'normalized' xml format contained in an input stream

the 'normalized' xml format is the output of the toXml() instance method

static ConfigTree fromXml(java.lang.String xml)
          obtain an instance of this class, from a 'normalized' xml format, with the default encoding

the 'normalized' xml format is the output of the toXml() instance method

static ConfigTree fromXml(java.lang.String xml, java.lang.String encoding)
          obtain an instance of this class, from a 'normalized' xml format, with the encoding defined in arg1

the 'normalized' xml format is the output of the toXml() instance method

 ConfigTree[] getAllChildren()
          retrieve list of child elements of 'this' that are instances of ConfigTree
 java.lang.String getAttribute(java.lang.String name)
          Retrieve the value assigned to an attribute key.
 java.lang.String getAttribute(java.lang.String name, java.lang.String defaultValue)
          Retrieve the value assigned to an attribute key, returning the supplied default if the attribute is not defined.
 java.util.Set<java.lang.String> getAttributeNames()
          obtain the list of all attribute names
 boolean getBooleanAttribute(java.lang.String name, boolean defaultValue)
           
 ConfigTree[] getChildren(java.lang.String name)
          list of child elements of 'this' that are instances of ConfigTree, with name = arg0
 ConfigTree getFirstChild(java.lang.String name)
          first child of class ConfigTree with name=arg0
 java.lang.String getFirstTextChild(java.lang.String name)
          first child containing only text, with name=arg0
 float getFloatAttribute(java.lang.String name, float defaultValue)
           
 long getLongAttribute(java.lang.String name, long defaultValue)
           
 java.lang.String getName()
           
 ConfigTree getParent()
          whose child is 'this' (null if root)
 java.lang.String getRequiredAttribute(java.lang.String name)
          Get the value of a requred property, throwing a ConfigurationException if the property is not defined.
 java.lang.String[] getTextChildren(java.lang.String name)
          Obtain all String values with the same name
 java.lang.String getWholeText()
          concatenated values of all child String values that have been added to 'this'
"" (zero length String) if no String child nodes
 boolean isPureText()
           
 void removeAllChildren()
          purge the list of children
 void removeChildrenByName(java.lang.String name)
          remove children by name
 java.lang.String setAttribute(java.lang.String name, java.lang.String value)
          assign a value to a named attribute
 void setName(java.lang.String name)
          assign a name to 'this'
 java.lang.String toString()
          Equivalent to a call to toXml()
 java.lang.String toString(java.lang.String encoding)
          Equivalent to a call to toXml(encoding)
 java.lang.String toXml()
           
 java.lang.String toXml(java.lang.String encoding)
          Serialize this object - Transient objects are
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConfigTree

public ConfigTree(java.lang.String name)
Constructor of a root node (an uppermost ConfigTree)

Parameters:
name - String - the element name of 'this'

ConfigTree

public ConfigTree(java.lang.String name,
                  ConfigTree dad)
Constructor of a ConfigTree as a child of another (second arg)

Parameters:
name - String - element name of 'this'
dad - ConfigTree - whom 'this' will be hanging from

ConfigTree

protected ConfigTree(ConfigTree other)
protected constructor

Parameters:
other - - Where to get values for deep copy
Method Detail

getName

public java.lang.String getName()
Returns:
String - the name of this tree (element name for XML representation)

setName

public void setName(java.lang.String name)
assign a name to 'this'

Parameters:
name - String - The name for this object

getParent

public ConfigTree getParent()
whose child is 'this' (null if root)

Returns:
ConfigTree - the parent tree of 'this'

setAttribute

public java.lang.String setAttribute(java.lang.String name,
                                     java.lang.String value)
assign a value to a named attribute

Parameters:
name - String - the name (key) for the new attribute
value - String - the value assigned to the key (if null - old value will be deleted)
Returns:
String - old value assigned to the name (null if there was none)

attributeCount

public int attributeCount()
Returns:
int - the number of non null attributes that this node has been assigned

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Retrieve the value assigned to an attribute key.

Parameters:
name - String - the search key.
Returns:
String - the value assigned to the specified key, or null if the attribute is not defined.

getAttribute

public java.lang.String getAttribute(java.lang.String name,
                                     java.lang.String defaultValue)
Retrieve the value assigned to an attribute key, returning the supplied default if the attribute is not defined.

Parameters:
name - String - the search key.
defaultValue - String - the default value to return if attribute is not set.
Returns:
String - the value assigned to the specified key, or the default if the value is not defined.

getLongAttribute

public long getLongAttribute(java.lang.String name,
                             long defaultValue)

getFloatAttribute

public float getFloatAttribute(java.lang.String name,
                               float defaultValue)

getBooleanAttribute

public boolean getBooleanAttribute(java.lang.String name,
                                   boolean defaultValue)

getRequiredAttribute

public java.lang.String getRequiredAttribute(java.lang.String name)
                                      throws ConfigurationException
Get the value of a requred property, throwing a ConfigurationException if the property is not defined.

Parameters:
name - String - the search key.
Returns:
The value assigned to the specified property.
Throws:
ConfigurationException - The propery is not defined.

getAttributeNames

public java.util.Set<java.lang.String> getAttributeNames()
obtain the list of all attribute names

Returns:
Set - the set of keys that have been assigned a non null value

attributesAsList

public java.util.List<KeyValuePair> attributesAsList()
obtain the list of all attribute as a List

Returns:
List - containing all attributes

childPropertyList

public java.util.List<KeyValuePair> childPropertyList()
obtain the list of all child "property" elements as a List

Returns:
List - containing all child elements with tag name "property"

getWholeText

public java.lang.String getWholeText()
concatenated values of all child String values that have been added to 'this'
"" (zero length String) if no String child nodes

Returns:
String - concatenation of all String segments (equivalent to xml text nodes)

getFirstTextChild

public java.lang.String getFirstTextChild(java.lang.String name)
first child containing only text, with name=arg0

Parameters:
name - String - the name to filter
Returns:
full text content of first 'pure text' child element under that name - <null> if none

getTextChildren

public java.lang.String[] getTextChildren(java.lang.String name)
Obtain all String values with the same name

Parameters:
name - String - filter for child String nodes
Returns:
String[]

addTextChild

public void addTextChild(java.lang.String value)
add a child element that consists only of the text in arg0

Parameters:
value - String - the text to assign to the added child node

getAllChildren

public ConfigTree[] getAllChildren()
retrieve list of child elements of 'this' that are instances of ConfigTree

Returns:
ConfigTree[] - Array containing all child elements of class ConfigTree

getChildren

public ConfigTree[] getChildren(java.lang.String name)
list of child elements of 'this' that are instances of ConfigTree, with name = arg0

Parameters:
name - String - the name of child nodes to filter
Returns:
ConfigTree[] - child elements of class ConfigTree with name provided

getFirstChild

public ConfigTree getFirstChild(java.lang.String name)
first child of class ConfigTree with name=arg0

Parameters:
name - String - the name to filter
Returns:
first child element under that name - <null> if none

removeAllChildren

public void removeAllChildren()
purge the list of children


removeChildrenByName

public void removeChildrenByName(java.lang.String name)
remove children by name

Parameters:
name - String - only children by that name will be removed

childCount

public int childCount()
Returns:
the number of child nodes (of any type)

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

cloneObj

public ConfigTree cloneObj()
instantiate a new ConfigTree with the same topology and contents of 'this'
Contained ConfigTree child elements will also be cloned
Transient objects are NOT copied nor cloned

Returns:
ConfigTree - Deep copy of 'this'

copyFrom

protected void copyFrom(ConfigTree other)
Deep copy of other tree

Parameters:
other - - from where to copy values

fromXml

public static ConfigTree fromXml(java.lang.String xml)
                          throws org.xml.sax.SAXException
obtain an instance of this class, from a 'normalized' xml format, with the default encoding

the 'normalized' xml format is the output of the toXml() instance method

Parameters:
xml - String - what to parse
Returns:
ConfigTree - an object of this class
Throws:
org.xml.sax.SAXException - - if xml format is invalid

fromXml

public static ConfigTree fromXml(java.lang.String xml,
                                 java.lang.String encoding)
                          throws java.io.UnsupportedEncodingException,
                                 org.xml.sax.SAXException
obtain an instance of this class, from a 'normalized' xml format, with the encoding defined in arg1

the 'normalized' xml format is the output of the toXml() instance method

Parameters:
xml - String - what to parse
encoding - String - The encoding of arg 0
Returns:
ConfigTree - an object of this class
Throws:
org.xml.sax.SAXException - - if xml format is invalid
java.io.UnsupportedEncodingException

fromInputStream

public static ConfigTree fromInputStream(java.io.InputStream input)
                                  throws org.xml.sax.SAXException,
                                         java.io.IOException
obtain an instance of this class, from a 'normalized' xml format contained in an input stream

the 'normalized' xml format is the output of the toXml() instance method

Parameters:
input - InputStream - where to parse from
Returns:
ConfigTree - an object of this class
Throws:
org.xml.sax.SAXException - - if xml format is invalid
java.io.IOException - - if an input/output error occurs

fromElement

public static ConfigTree fromElement(org.w3c.dom.Element elem)

toString

public java.lang.String toString()
Equivalent to a call to toXml()

Overrides:
toString in class java.lang.Object
Returns:
String - a String with the 'standard' xml representation of 'this', using the default encoding

toString

public java.lang.String toString(java.lang.String encoding)
Equivalent to a call to toXml(encoding)

Parameters:
encoding - String -
Returns:
String - a String with the 'standard' xml representation of 'this', using the encoding specified in arg 0

toXml

public java.lang.String toXml()
Returns:
String - a String with the 'standard' xml representation of 'this', using the default encoding

toXml

public java.lang.String toXml(java.lang.String encoding)
Serialize this object - Transient objects are

Parameters:
encoding - String - String
Returns:
String - a String with the 'standard' xml representation of 'this', using encoding specified in arg0

isPureText

public boolean isPureText()
Returns:
boolean - indicating if 'this' element has ONLY text children (and consequently no ConfigTree children)