bill.util.xml
Class SimpleXMLObject

java.lang.Object
  |
  +--bill.util.xml.SimpleXMLObject

public class SimpleXMLObject
extends Object

Holds an object, or node, in the XML document. May have a value associated with it and may have a list of attributes associated with it.


Constructor Summary
SimpleXMLObject(SimpleXMLObject object)
          Copy contructor.
SimpleXMLObject(SimpleXMLObject object, boolean copyChildren)
          Copy contructor.
SimpleXMLObject(String name)
          Simple creator that just sets the object's name to the specified value.
SimpleXMLObject(String name, String value)
          Simple creator that just sets the object's name and value to the specified values.
 
Method Summary
 void addAttribute(SimpleXMLAttribute attr)
          Adds the specified attribute to the list of attributes for this object.
 void addAttribute(String attrName, String attrValue)
          Adds the specified attribute to the list of attributes for this object.
 void addChild(SimpleXMLObject child)
          Adds the specified node as a child of this node.
 boolean equals(Object other)
          Checks if two SimpleXMLObject objects are equal.
 SimpleXMLAttribute getAttribute(String attrName)
          Retrieves the attribute object for the specified attribute name.
 Vector getAttributes()
          Retrieves the attributes of this object.
 String getAttributeValue(String attrName)
          Retrieves the value for the specified attribute name.
 Vector getChildren()
          Retrieves the child objects of this object.
static String getLineSeparator()
          Retrieves the string that represents a line separator.
 String getName()
          Retrieves the name of this object.
 String getValue()
          Retrieves the value of this object.
 boolean isCData()
          Checks to see if this object's value should be treated as CData.
 void mergeChildren(SimpleXMLObject source)
          Adds the children of the source node to the children of this node.
static String replace(String string, String oldPattern, String newPattern)
          Replaces all instances of a pattern in a string with another pattern.
 void setAttributes(Vector attributes)
          Sets the attribute list for this object.
 void setAttributesCopies(Vector attributes)
          Sets the attribute list for this object, but rather than just assign the passed vector, it creates new attribute objects using the data from the passed vector.
 void setAttributeValue(String attrName, String attrValue)
          Adds the specified attribute to the list of attributes for this object if it does not already exist, updates the value of the attribute if it does exist.
 void setCData(boolean cdata)
          Sets the cdata indicator the the specified value.
 void setName(String name)
          Sets the name of this object.
 void setValue(String value)
          Sets the value of this object.
 String toXML()
          Dumps out the object in valid XML string representation.
 String toXML(boolean includeChildren)
          Dumps out the object in valid XML string representation.
 SimpleXMLAttribute updateAttribute(String name, String value)
          Updates the value of the specified attribute.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleXMLObject

public SimpleXMLObject(String name)
Simple creator that just sets the object's name to the specified value.
Parameters:
name - The name you wish to assign to the object.

SimpleXMLObject

public SimpleXMLObject(String name,
                       String value)
Simple creator that just sets the object's name and value to the specified values.
Parameters:
name - The name you wish to assign to the object.
value - The value you wish to assign to the object.

SimpleXMLObject

public SimpleXMLObject(SimpleXMLObject object)
Copy contructor. Makes a deep copy of the specified object. This includes copying the object's attributes, but not it's descendants.
Parameters:
object - The object to be copied.

SimpleXMLObject

public SimpleXMLObject(SimpleXMLObject object,
                       boolean copyChildren)
Copy contructor. Makes a deep copy of the specified object.
Parameters:
object - The object to be copied.
copyChildren - Used to indicate if descendants should also be copied, true indicates they should, false indicates they should not.
Method Detail

getLineSeparator

public static String getLineSeparator()
Retrieves the string that represents a line separator. Since this can differ by OS, we need to dynamically determine what it is. The value is used in making a 'pretty' XML output string.
Returns:
The string representation of the line separator.

getName

public String getName()
Retrieves the name of this object.
Returns:
The name of this object.

setName

public void setName(String name)
Sets the name of this object.
Parameters:
name - The new name of this object.

getValue

public String getValue()
Retrieves the value of this object.
Returns:
The value of this object

setValue

public void setValue(String value)
Sets the value of this object.
Parameters:
value - The new value of this object

setCData

public void setCData(boolean cdata)
Sets the cdata indicator the the specified value. A value of true indicates that the object's value should be treated as CData.
Parameters:
cdata - The value to set the CData indicator to.

isCData

public boolean isCData()
Checks to see if this object's value should be treated as CData.
Returns:
Returns true if the value should be treated as CData, otherwise returns false.

getChildren

public Vector getChildren()
Retrieves the child objects of this object.
Returns:
The child objects of this object

addChild

public void addChild(SimpleXMLObject child)
Adds the specified node as a child of this node.
Parameters:
child - The node to be added as a child.

mergeChildren

public void mergeChildren(SimpleXMLObject source)
Adds the children of the source node to the children of this node. This always adds new objects to the XML, it does not update existing objects with the same name. Note that this method does not make a 'deep' copy of the nodes being added, so changes to them after this merge will be reflected in the original node and the 'copied' node.
Parameters:
source - The node to take the children out of.

setAttributes

public void setAttributes(Vector attributes)
Sets the attribute list for this object.
Parameters:
attributes - The new attribute list for this object

setAttributesCopies

public void setAttributesCopies(Vector attributes)
Sets the attribute list for this object, but rather than just assign the passed vector, it creates new attribute objects using the data from the passed vector.
Parameters:
attributes - The new attribute list to copy.

getAttributes

public Vector getAttributes()
Retrieves the attributes of this object.
Returns:
The attributes of this object

getAttribute

public SimpleXMLAttribute getAttribute(String attrName)
Retrieves the attribute object for the specified attribute name.
Parameters:
attrName - Name of the attribute to retrieve.
Returns:
Returns a reference to the attribute if one by that name exists, otherwise returns null.

getAttributeValue

public String getAttributeValue(String attrName)
Retrieves the value for the specified attribute name.
Parameters:
attrName - Name of the attribute to retrieve.
Returns:
Returns the value of the attribute if one by that name exists, otherwise returns null.

addAttribute

public void addAttribute(String attrName,
                         String attrValue)
Adds the specified attribute to the list of attributes for this object. Note that no checking is done, so be sure not to call this with an attribute name that duplicates one already in the object.
Parameters:
attrName - The name of the attribute to be added to the attribute list.
attrValue - The value to assign to the new attribute.

addAttribute

public void addAttribute(SimpleXMLAttribute attr)
Adds the specified attribute to the list of attributes for this object. Note that no checking is done, so be sure not to call this with an attribute name that duplicates one already in the object.
Parameters:
attr - The attribute to be added to the attribute list.

setAttributeValue

public void setAttributeValue(String attrName,
                              String attrValue)
Adds the specified attribute to the list of attributes for this object if it does not already exist, updates the value of the attribute if it does exist.
Parameters:
attrName - The name of the attribute to set the value of.
attrValue - The value to assign to the attribute.

updateAttribute

public SimpleXMLAttribute updateAttribute(String name,
                                          String value)
Updates the value of the specified attribute. If the attribute does not exist it is created.
Parameters:
name - The name of the attribute to update.
value - The value to set the attribute to.
Returns:
The updated (or added) attribute object.

toXML

public String toXML()
Dumps out the object in valid XML string representation. Includes all the children of this object as well.
Returns:
The XML in string format.

toXML

public String toXML(boolean includeChildren)
Dumps out the object in valid XML string representation.
Parameters:
includeChildren - Indicates if child objects should be included in the generated XML string, true indicates they should, false indicates they should not.
Returns:
The XML in string format.

replace

public static String replace(String string,
                             String oldPattern,
                             String newPattern)
Replaces all instances of a pattern in a string with another pattern.
Parameters:
string - The string to perform the replacements against.
oldPattern - The pattern to be replaced in the original string.
newPattern - The pattern to replace the old pattern with.
Returns:
Returns the original string with all instances of the old pattern replaced with the new one.

equals

public boolean equals(Object other)
Checks if two SimpleXMLObject objects are equal. They are concidered equal if their names and values match.
Overrides:
equals in class Object
Parameters:
other - The other object to check for equality.
Returns:
Returns true if the object are equal, returns false otherwise.