org.exolab.castor.types
Class AnyNode

java.lang.Object
  extended by org.exolab.castor.types.AnyNode
All Implemented Interfaces:
java.io.Serializable

public final class AnyNode
extends java.lang.Object
implements java.io.Serializable

A class used to represent an XML node. This is an alternative to DOM which is too heavy for our purpose (mainly handle XML Fragment when is used in an XML schema). The model is based on XPath Node. An AnyNode can be a:

Version:
$Revision: 1.2 $ $Date: 2005/03/05 13:41:56 $
Author:
Assaf Arkin, Arnaud Blandin, Keith Visco
See Also:
Serialized Form

Field Summary
static short ATTRIBUTE
          Representation for an attribute node.
static short COMMENT
          Representation for a comment node.
static short ELEMENT
          Representation for an element node.
static short NAMESPACE
          Representation for a Namespace node.
static short PI
          Representation for a processing instruction node.
static short TEXT
          Representation for a text node.
 
Constructor Summary
AnyNode()
          Default constructor: creates an empty element node
AnyNode(short type, java.lang.String localName, java.lang.String prefix, java.lang.String uri, java.lang.String value)
          Creates a node given all the necessary information: type, localName, prefix, uri and value.
 
Method Summary
 void addAnyNode(AnyNode node)
          Adds an AnyNode to the current node
 void addAttribute(AnyNode node)
          Adds an attribute to the current node.
 void addChild(AnyNode node)
          Adds a child AnyNode to this node.
 void addNamespace(AnyNode node)
          Appends an namespace to the current node.
protected  void appendSibling(AnyNode node)
          Appends a sibling AnyNode to the current node.
 AnyNode getFirstAttribute()
          Returns the first attribute of the current ELEMENT node or null.
 AnyNode getFirstChild()
          Returns the first Child node of this node.
protected  AnyNode getFirstChildNode()
          Returns the first child node in the tree.
 AnyNode getFirstNamespace()
          Returns the first namespace of the current ELEMENT node or null.
 java.lang.String getLocalName()
          Returns the local name of the node.
 java.lang.String getNamespacePrefix()
          Returns the namespace prefix associated with the namespace URI of this node.
 java.lang.String getNamespaceURI()
          Returns the namespace URI of the node.
 AnyNode getNextSibling()
          Returns the next sibling of the current node.
 short getNodeType()
          Returns the type of this node.
 java.lang.String getStringValue()
          Returns the string value of the node.
 java.lang.String toString()
          Returns the String representation of this AnyNode The String representation is a xml well-formed fragment corresponding to the representation of this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ELEMENT

public static final short ELEMENT
Representation for an element node.

See Also:
Constant Field Values

ATTRIBUTE

public static final short ATTRIBUTE
Representation for an attribute node.

See Also:
Constant Field Values

NAMESPACE

public static final short NAMESPACE
Representation for a Namespace node.

See Also:
Constant Field Values

PI

public static final short PI
Representation for a processing instruction node.

See Also:
Constant Field Values

COMMENT

public static final short COMMENT
Representation for a comment node.

See Also:
Constant Field Values

TEXT

public static final short TEXT
Representation for a text node.

See Also:
Constant Field Values
Constructor Detail

AnyNode

public AnyNode()
Default constructor: creates an empty element node


AnyNode

public AnyNode(short type,
               java.lang.String localName,
               java.lang.String prefix,
               java.lang.String uri,
               java.lang.String value)
Creates a node given all the necessary information: type, localName, prefix, uri and value. This constructor is not user-friendly and launched RunTime exception is you try to instantiate non-valid node.

Parameters:
type - the node type.
localName - the name of the node.
prefix - the prefix if any of the namespace.
uri - the namespace uri of this node.
value - the value of this node.
Method Detail

addAnyNode

public void addAnyNode(AnyNode node)
Adds an AnyNode to the current node

Parameters:
node - the node to append

addChild

public void addChild(AnyNode node)

Adds a child AnyNode to this node. A 'child' can be either an ELEMENT node, a COMMENT node, a TEXT node or a PROCESSING INSTRUCTION. If the current node already has a child then the node to add will be append as a sibling.

Note: you cannot add a child to a TEXT node.

Parameters:
node - the node to add.

addAttribute

public void addAttribute(AnyNode node)
Adds an attribute to the current node.

Parameters:
node - the attribute to add.

addNamespace

public void addNamespace(AnyNode node)
Appends an namespace to the current node.

Parameters:
node - the attribute to add.

getFirstAttribute

public AnyNode getFirstAttribute()
Returns the first attribute of the current ELEMENT node or null. The next attribute,if any,is the sibling of the returned node.


getFirstNamespace

public AnyNode getFirstNamespace()
Returns the first namespace of the current ELEMENT node or null. The next attribute if any is the sibling of the returned node.


getFirstChild

public AnyNode getFirstChild()
Returns the first Child node of this node. A 'child' can be either an ELEMENT node, a COMMENT node, a TEXT node or a PROCESSING INSTRUCTION.

Returns:
the first child of this node

getNextSibling

public AnyNode getNextSibling()
Returns the next sibling of the current node. When the AnyNode is an ATTRIBUTE, it will return the next ATTRIBUTE node. When the AnyNode is a NAMESPACE, it will return the next NAMESPACE node.

Returns:
the next sibling of the current node

getNodeType

public short getNodeType()
Returns the type of this node.

Returns:
The type of this node

getLocalName

public java.lang.String getLocalName()
Returns the local name of the node. Returns the local name of an element or attribute, the prefix of a namespace node, the target of a processing instruction, or null for all other node types.

Returns:
The local name of the node, or null if the node has no name

getNamespaceURI

public java.lang.String getNamespaceURI()
Returns the namespace URI of the node. Returns the namespace URI of an element, attribute or namespace node, or null for all other node types.

Returns:
The namespace URI of the node, or null if the node has no namespace URI

getStringValue

public java.lang.String getStringValue()
Returns the string value of the node. The string value of a text node or an attribute node is its text value. The string value of an element or a root node is the concatenation of the string value of all its child nodes. The string value of a namespace node is its namespace URI. The string value of a processing instruction is the instruction, and the string value of a comment is the comment text.

Returns:
The string value of the node

getNamespacePrefix

public java.lang.String getNamespacePrefix()
Returns the namespace prefix associated with the namespace URI of this node. Returns null if no prefix. is defined for this namespace URI. Returns an empty string if the default prefix is associated with this namespace URI.

Returns:
The namespace prefix, or null

toString

public java.lang.String toString()
Returns the String representation of this AnyNode The String representation is a xml well-formed fragment corresponding to the representation of this node.

Overrides:
toString in class java.lang.Object

appendSibling

protected void appendSibling(AnyNode node)
Appends a sibling AnyNode to the current node. The node to append will be added at the end of the sibling branch.

Parameters:
node - the node to add

getFirstChildNode

protected AnyNode getFirstChildNode()
Returns the first child node in the tree.

Returns:
the first child node in the tree.


Intalio Inc. (C) 1999-2004. All rights reserved http://www.intalio.com