org.moremotion.adom
Class ADOMNode

java.lang.Object
  extended by org.moremotion.adom.ADOMNode
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
ADOM

public class ADOMNode
extends java.lang.Object
implements java.lang.Cloneable

Represents a single node in ADOM (Application Data Object Model).

Each node has a name, a value which can be set and used as String, Integer, Double and boolean. Each node can have a set of attributes and a set of child nodes.

Since ADOMs and ADOMNodes are used in XML content generation, a node corresponds to an XML tag. Considering this, the node names should accord to the rules of naming XML tags.

Version:
$Id: ADOMNode.java 51 2008-03-10 11:46:54Z erkan $
See Also:
Using node paths to access nodes

Field Summary
static byte DT_BOOL
           
static byte DT_INTEGER
           
static byte DT_NUMBER
           
static byte DT_STRING
           
 
Constructor Summary
ADOMNode(java.lang.String name)
          Creates a new ADOMNode and names it.
ADOMNode(java.lang.String name, java.lang.String value)
          Creates a new ADOMNode, names it and sets its value.
 
Method Summary
 java.lang.String addAttribute(java.lang.String name, java.lang.String value)
          Adds a new node attribute to this node.
 void addNode(ADOMNode node)
          Adds the given node under this node.
 void clear()
          Removes all the child nodes of this node
 java.lang.Object clone()
           
 boolean equals(java.lang.Object obj)
          Checks the equality of this node to another node with all their content.
 ADOMNode findNode(java.lang.String nodePath)
          Finds the node by the given node path and returns it.
 java.lang.String getAttribute(java.lang.String name)
          Returns the value of a node attribute.
 int getAttributeCount()
          Returns the number of attributes that this node has.
 java.util.Properties getAttributes()
          Returns the attributes of this node as a Properties object.
 java.lang.String getName()
          Returns the name of this node.
 ADOMNode getNode(java.lang.String nodePath)
          Finds the node by the given node path and returns it.
 int getNodeCount()
          Returns the number of the child nodes of this node.
 java.util.Iterator getNodes()
          Returns an Iterator interface for the first level child nodes of this node.
 ADOMNode[] getNodesArray()
          Returns an ADOMNode array from the first level child nodes of this node.
 java.lang.String getNodeValue(java.lang.String nodePath)
          Finds the node by the given node path and returns its value.
 java.util.Properties getNodeValues()
          Returns the values of the first level child nodes in a Properties object.
 ADOMNode getParent()
          Returns the parent node of this node.
 java.lang.String getPath()
          Returns the path of this node starting form the root node.
 ADOMNode getRootNode()
          Returns the root node
 ADOMNode getSubNode(java.lang.String name)
           
 java.lang.String getValue()
          Returns the value of this node as String.
 boolean getValueAsBoolean()
          Returns the value of this node as boolean.
 double getValueAsDouble()
          Return the value of the node as double.
 int getValueAsInt()
          Return the value of the node as int.
 java.lang.Object getValueAsObject()
          Returns the value of this node as Object.
 java.lang.String getValueAsString()
          Return the value of the node as String.
 java.lang.String getValueForXML()
          Returns the value of this node to build XML content.
 boolean hasChild(java.lang.String nodeName)
          Checks if this node has a child node with the given node name.
 boolean isRoot()
          Returns true if this node is the root node of the ADOM, false otherwise.
static void main(java.lang.String[] args)
          Test method.
 java.lang.String removeAttribute(java.lang.String name)
          Removes a node attribute from this node by its name.
 void removeLast()
           
 boolean removeNode(ADOMNode node)
          Removes the given child node.
 void setName(java.lang.String value)
          Sets the name of this node.
 ADOMNode setNodeValue(java.lang.String nodePath, java.lang.String value)
          Finds the node by the given node path and sets its value.
 void setNodeValues(java.util.Properties props)
          Sets the values of the child nodes using a Properties object.
 void setParent(ADOMNode value)
          Sets the parent node of this node.
 void setValue(boolean value)
          Sets value of this node as Boolean object
 void setValue(double value)
          Sets value of this node as double.
 void setValue(int value)
          Sets value of this node as Integer object
 void setValue(java.lang.Object value)
          Sets value object of this node
 void sort(java.lang.String sortDefinition)
           
 java.lang.String toString()
          Returns the string representation of this node.
 java.lang.String toXml()
          Converts this node and all its child nodes to XML string.
 java.lang.String toXml(java.lang.String tagName)
          Converts this node and all its child nodes to XML string.
 java.lang.String toXmlWithIndent()
          Converts this node and all its child nodes to XML string.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DT_STRING

public static final byte DT_STRING
See Also:
Constant Field Values

DT_NUMBER

public static final byte DT_NUMBER
See Also:
Constant Field Values

DT_BOOL

public static final byte DT_BOOL
See Also:
Constant Field Values

DT_INTEGER

public static final byte DT_INTEGER
See Also:
Constant Field Values
Constructor Detail

ADOMNode

public ADOMNode(java.lang.String name)
Creates a new ADOMNode and names it.

Parameters:
name - Node name.

ADOMNode

public ADOMNode(java.lang.String name,
                java.lang.String value)
Creates a new ADOMNode, names it and sets its value.

Parameters:
name - Node name.
value - Node value.
Method Detail

clone

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

getName

public java.lang.String getName()
Returns the name of this node.

Returns:
Node name.

setName

public void setName(java.lang.String value)
Sets the name of this node.

Parameters:
value - New name of this node.

getValue

public java.lang.String getValue()
Returns the value of this node as String.

Returns:
Node value. Note that the node values can be null.

getValueForXML

public java.lang.String getValueForXML()
Returns the value of this node to build XML content.

Note that some nodes can contain secret information which should not be included in XML in clear format.

Returns:
Either node's value or {HIDDEN_VALUE} if the value of this node is a HiddenString

setValue

public void setValue(java.lang.Object value)
Sets value object of this node

Parameters:
value - Value to be set.

setValue

public void setValue(double value)
Sets value of this node as double.

Parameters:
value - double value.

setValue

public void setValue(int value)
Sets value of this node as Integer object

Parameters:
value - int value.

setValue

public void setValue(boolean value)
Sets value of this node as Boolean object

Parameters:
value - boolean value.

getValueAsObject

public java.lang.Object getValueAsObject()
Returns the value of this node as Object.


getValueAsString

public java.lang.String getValueAsString()
Return the value of the node as String.


getValueAsInt

public int getValueAsInt()
Return the value of the node as int. If the value of the node cannot be converted to integer '0' is returned.


getValueAsDouble

public double getValueAsDouble()
Return the value of the node as double. If the value of the node cannot be converted to a number, '0' is returned.


getValueAsBoolean

public boolean getValueAsBoolean()
Returns the value of this node as boolean. Returns false if the value of the node cannot be converted to boolean.


isRoot

public boolean isRoot()
Returns true if this node is the root node of the ADOM, false otherwise.


getParent

public ADOMNode getParent()
Returns the parent node of this node.

Returns:
null if this node is the root node, otherwise the parent node.

setParent

public void setParent(ADOMNode value)
Sets the parent node of this node.


getRootNode

public ADOMNode getRootNode()
Returns the root node


getPath

public java.lang.String getPath()
Returns the path of this node starting form the root node.


addAttribute

public java.lang.String addAttribute(java.lang.String name,
                                     java.lang.String value)
Adds a new node attribute to this node.

Parameters:
name - Name of the attribute
value - Value of the attribute
Returns:
null if the attribute does not already exists, its value Otherwise.

removeAttribute

public java.lang.String removeAttribute(java.lang.String name)
Removes a node attribute from this node by its name.

Parameters:
name - Name of the attribute.
Returns:
Value of the removed attribute. If no attribute is found by the name given then null value is returned.

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Returns the value of a node attribute.

Parameters:
name - Name of the attribute.
Returns:
Value of the attribute, null if attribute does not exist.

getAttributes

public java.util.Properties getAttributes()
Returns the attributes of this node as a Properties object.


getAttributeCount

public int getAttributeCount()
Returns the number of attributes that this node has.


addNode

public void addNode(ADOMNode node)
Adds the given node under this node.


removeNode

public boolean removeNode(ADOMNode node)
Removes the given child node.


removeLast

public void removeLast()

getNodes

public java.util.Iterator getNodes()
Returns an Iterator interface for the first level child nodes of this node.


getNodesArray

public ADOMNode[] getNodesArray()
Returns an ADOMNode array from the first level child nodes of this node. If this node has no children then returns an empty array (zero-length).


getNode

public ADOMNode getNode(java.lang.String nodePath)
Finds the node by the given node path and returns it.

Note that the nodes that do not exist in the node path are created

Returns:
The found existing node or the created node.

findNode

public ADOMNode findNode(java.lang.String nodePath)
Finds the node by the given node path and returns it.

Returns:
The node found or null if the node is not found.

hasChild

public boolean hasChild(java.lang.String nodeName)
Checks if this node has a child node with the given node name.

Parameters:
nodeName - Name of the child.
Returns:
true if the child node exists, false otherwise.

getSubNode

public ADOMNode getSubNode(java.lang.String name)

getNodeValue

public java.lang.String getNodeValue(java.lang.String nodePath)
Finds the node by the given node path and returns its value. If no node is found then returns an empty string.


getNodeValues

public java.util.Properties getNodeValues()
Returns the values of the first level child nodes in a Properties object.


setNodeValue

public ADOMNode setNodeValue(java.lang.String nodePath,
                             java.lang.String value)
Finds the node by the given node path and sets its value.

Note that the nodes that do not exist in the node path are created.

Parameters:
nodePath - Path name.
value - Value to set.
Returns:
ADOMNode that this method has modified.

setNodeValues

public void setNodeValues(java.util.Properties props)
Sets the values of the child nodes using a Properties object. The keys of the Properties object are used as node paths which define the nodes to be modified and the values are used as the values of the nodes.

Parameters:
props - Properties object that contains Node path/Value pairs.

getNodeCount

public int getNodeCount()
Returns the number of the child nodes of this node.


clear

public void clear()
Removes all the child nodes of this node


toString

public java.lang.String toString()
Returns the string representation of this node.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Checks the equality of this node to another node with all their content.

Overrides:
equals in class java.lang.Object

sort

public void sort(java.lang.String sortDefinition)

toXml

public java.lang.String toXml()
Converts this node and all its child nodes to XML string.


toXml

public java.lang.String toXml(java.lang.String tagName)
Converts this node and all its child nodes to XML string.

Parameters:
tagName - The name of the XML tag. If parameter is null then no tag will be included in the XML.

toXmlWithIndent

public java.lang.String toXmlWithIndent()
Converts this node and all its child nodes to XML string. The XML elements in the returned string are indented with new line and tab characters.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test method.

Throws:
java.lang.Exception


Copyright © 2002-2008 MOR YAZILIM. All Rights Reserved.