org.jutil.xml.message
Class DefaultElement

java.lang.Object
  extended by org.jutil.xml.message.DefaultElement
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, VersionedObject, Element

public class DefaultElement
extends java.lang.Object
implements Element, java.io.Externalizable

See Also:
Serialized Form

Field Summary
protected  java.util.Map attributes
           
protected  java.util.List children
           
protected  java.lang.String name
           
protected  java.lang.String value
           
 
Constructor Summary
DefaultElement()
           
DefaultElement(Message message, java.lang.String name)
           
DefaultElement(Message message, java.lang.String name, java.lang.String value)
           
DefaultElement(java.lang.String name)
           
DefaultElement(java.lang.String name, java.lang.String value)
           
 
Method Summary
 void addChild(Element child)
          Add a new child Element
 Element createElement(java.lang.String name)
           
 Element createElement(java.lang.String element, java.lang.String value)
           
 java.lang.String getAttribute(java.lang.String attribute)
          Return the value of specified attribute.
 java.lang.String getAttribute(java.lang.String attribute, java.lang.String defaultValue)
          Returns the value of the attribute specified by its name as a String, or the default value if no attribute by that name exists or is empty.
 boolean getAttributeAsBoolean(java.lang.String attribute)
          Return the boolean value of the specified parameter contained in this node.
 boolean getAttributeAsBoolean(java.lang.String attribute, boolean defaultValue)
          Returns the value of the attribute specified by its name as a boolean, or the default value if no attribute by that name exists or is empty.
 double getAttributeAsDouble(java.lang.String attribute)
          Return the double value of the specified attribute contained in this node.
 double getAttributeAsDouble(java.lang.String attribute, double defaultValue)
          Returns the value of the attribute specified by its name as a double, or the default value if no attribute by that name exists or is empty.
 float getAttributeAsFloat(java.lang.String attribute)
          Return the float value of the specified parameter contained in this node.
 float getAttributeAsFloat(java.lang.String attribute, float defaultValue)
          Returns the value of the attribute specified by its name as a float, or the default value if no attribute by that name exists or is empty.
 int getAttributeAsInteger(java.lang.String attribute)
          Return the int value of the specified attribute contained in this node.
 int getAttributeAsInteger(java.lang.String attribute, int defaultValue)
          Returns the value of the attribute specified by its name as a int, or the default value if no attribute by that name exists or is empty.
 long getAttributeAsLong(java.lang.String attribute)
          Returns the value of the attribute specified by its name as a long.
 long getAttributeAsLong(java.lang.String attribute, long defaultValue)
          Returns the value of the attribute specified by its name as a long, or the default value if no attribute by that name exists or is empty.
 java.lang.String[] getAttributeNames()
          Return an array of all attribute names.
 Element getChild(java.lang.String child)
          Return a new Element instance encapsulating the specified child node.
 Element getChild(java.lang.String child, boolean create)
          Return a new Element instance encapsulating the specified child node.
 Element[] getChildren()
          Return an Element[]
 Element[] getChildren(java.lang.String child)
          Return an Element[] containing all node children with the specified name.
 java.lang.String getName()
          Return the name of the element
 java.lang.String getValue()
          Return the value of the element
 java.lang.String getValue(java.lang.String defaultValue)
          Return the value of the element
 Version getVersion()
          Overide the superclass getVersion() to return this sub classe's Version
 void readExternal(java.io.ObjectInput in)
           
 boolean removeChild(Element child)
           
 boolean removeChildren(java.lang.String child)
           
 void setAttribute(java.lang.String name, java.lang.String attribute)
          Add a new XMLAttribute
 void setName(java.lang.String name)
          Set the name of the Element
 void setValue(java.lang.String value)
          Set the value of the Element
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

value

protected java.lang.String value

attributes

protected java.util.Map attributes

children

protected java.util.List children
Constructor Detail

DefaultElement

public DefaultElement()

DefaultElement

public DefaultElement(Message message,
                      java.lang.String name)

DefaultElement

public DefaultElement(Message message,
                      java.lang.String name,
                      java.lang.String value)

DefaultElement

public DefaultElement(java.lang.String name)

DefaultElement

public DefaultElement(java.lang.String name,
                      java.lang.String value)
Method Detail

getName

public java.lang.String getName()
Return the name of the element

Specified by:
getName in interface Element
Returns:
String

setName

public void setName(java.lang.String name)
Set the name of the Element

Specified by:
setName in interface Element
Parameters:
name - The name String

getValue

public java.lang.String getValue()
Return the value of the element

Specified by:
getValue in interface Element
Returns:
String

getValue

public java.lang.String getValue(java.lang.String defaultValue)
Return the value of the element

Specified by:
getValue in interface Element
Returns:
String

setValue

public void setValue(java.lang.String value)
Set the value of the Element

Specified by:
setValue in interface Element
Parameters:
value - The value String

addChild

public void addChild(Element child)
Add a new child Element

Specified by:
addChild in interface Element
Parameters:
child - The child Element.

getChild

public Element getChild(java.lang.String child)
Return a new Element instance encapsulating the specified child node.

Specified by:
getChild in interface Element
Parameters:
child - The name of the child node.
Returns:
Element if Element exists otherwise return null;

getChild

public Element getChild(java.lang.String child,
                        boolean create)
Return a new Element instance encapsulating the specified child node.

Specified by:
getChild in interface Element
Parameters:
child - The name of the child node.
create - Boolean flag if true create new ElementThe name of the child node.
Returns:
Element if Element exists or create is true otherwise return null;

removeChild

public boolean removeChild(Element child)
Specified by:
removeChild in interface Element

getChildren

public Element[] getChildren()
Return an Element[]
Specified by:
getChildren in interface Element
Returns:
All the child Elements, if no child Elements return an empty array return new Element[0];

getChildren

public Element[] getChildren(java.lang.String child)
Return an Element[] containing all node children with the specified name.

Specified by:
getChildren in interface Element
Parameters:
child - The name of the children to get.
Returns:
The child Elements with name, if no child Elements return an empty array return new Element[0];

removeChildren

public boolean removeChildren(java.lang.String child)
Specified by:
removeChildren in interface Element

getAttributeNames

public java.lang.String[] getAttributeNames()
Return an array of all attribute names.

Specified by:
getAttributeNames in interface Element

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String attribute)
Add a new XMLAttribute

Specified by:
setAttribute in interface Element
Parameters:
attribute - The attribute name.
value - The attribute value.

getAttribute

public java.lang.String getAttribute(java.lang.String attribute)
Return the value of specified attribute.

Specified by:
getAttribute in interface Element
Parameters:
attribute - The name of the attribute you ask the value of.
Returns:
String value of attribute, or null if attribute does not exist.

getAttributeAsInteger

public int getAttributeAsInteger(java.lang.String attribute)
                          throws AttributeNotFoundException,
                                 ValueParseException
Return the int value of the specified attribute contained in this node.

Specified by:
getAttributeAsInteger in interface Element
Parameters:
attribute - The name of the attribute you ask the value of.
Returns:
int value of attribute
Throws:
AttributeNotFoundException - If no attribute with that name exists.
NumberParseException - or if conversion to int fails.
ValueParseException

getAttributeAsLong

public long getAttributeAsLong(java.lang.String attribute)
                        throws AttributeNotFoundException,
                               ValueParseException
Returns the value of the attribute specified by its name as a long.

Specified by:
getAttributeAsLong in interface Element
Parameters:
attribute - The name of the attribute you ask the value of.
Returns:
long value of attribute
Throws:
AttributeNotFoundException - If no attribute with that name exists.
ValueParseException - or if conversion to long fails.

getAttributeAsFloat

public float getAttributeAsFloat(java.lang.String attribute)
                          throws AttributeNotFoundException,
                                 ValueParseException
Return the float value of the specified parameter contained in this node.

Specified by:
getAttributeAsFloat in interface Element
Parameters:
attribute - The name of the attribute you ask the value of.
Returns:
float value of attribute
Throws:
AttributeNotFoundException - If no attribute with that name exists.
ValueParseException - or if conversion to float fails.

getAttributeAsDouble

public double getAttributeAsDouble(java.lang.String attribute)
                            throws AttributeNotFoundException,
                                   ValueParseException
Return the double value of the specified attribute contained in this node.

Specified by:
getAttributeAsDouble in interface Element
Parameters:
name - The name of the attribute you ask the value of.
Returns:
double value of attribute
Throws:
AttributeNotFoundException - If no attribute with that name exists.
NumberParseException - or if conversion to double fails.
ValueParseException

getAttributeAsBoolean

public boolean getAttributeAsBoolean(java.lang.String attribute)
                              throws AttributeNotFoundException,
                                     ValueParseException
Return the boolean value of the specified parameter contained in this node.

Specified by:
getAttributeAsBoolean in interface Element
Parameters:
attribute - The name of the attribute you ask the value of.
Returns:
boolean value of attribute
Throws:
AttributeNotFoundException - If no attribute with that name exists.
ValueParseException - or if conversion to boolean fails.

getAttribute

public java.lang.String getAttribute(java.lang.String attribute,
                                     java.lang.String defaultValue)
Returns the value of the attribute specified by its name as a String, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttribute in interface Element
Parameters:
attribute - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
String value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.

getAttributeAsInteger

public int getAttributeAsInteger(java.lang.String attribute,
                                 int defaultValue)
Returns the value of the attribute specified by its name as a int, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttributeAsInteger in interface Element
Parameters:
attribute - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
int value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.

getAttributeAsLong

public long getAttributeAsLong(java.lang.String attribute,
                               long defaultValue)
Returns the value of the attribute specified by its name as a long, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttributeAsLong in interface Element
Parameters:
attribute - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
long value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.

getAttributeAsFloat

public float getAttributeAsFloat(java.lang.String attribute,
                                 float defaultValue)
Returns the value of the attribute specified by its name as a float, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttributeAsFloat in interface Element
Parameters:
attribute - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
float value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.

getAttributeAsDouble

public double getAttributeAsDouble(java.lang.String attribute,
                                   double defaultValue)
Returns the value of the attribute specified by its name as a double, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttributeAsDouble in interface Element
Parameters:
name - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
double value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.

getAttributeAsBoolean

public boolean getAttributeAsBoolean(java.lang.String attribute,
                                     boolean defaultValue)
Returns the value of the attribute specified by its name as a boolean, or the default value if no attribute by that name exists or is empty.

Specified by:
getAttributeAsBoolean in interface Element
Parameters:
attribute - The name of the attribute you ask the value of.
defaultValue - The default value desired.
Returns:
boolean value of attribute. It will return the default value if the named attribute does not exist, or if the value is not set.

createElement

public final Element createElement(java.lang.String name)
Specified by:
createElement in interface Element

createElement

public final Element createElement(java.lang.String element,
                                   java.lang.String value)
Specified by:
createElement in interface Element

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

getVersion

public Version getVersion()
Overide the superclass getVersion() to return this sub classe's Version

Specified by:
getVersion in interface VersionedObject