org.jvoicexml.xml
Class AbstractXmlNode

java.lang.Object
  extended by org.jvoicexml.xml.AbstractXmlNode
All Implemented Interfaces:
XmlNode, Node
Direct Known Subclasses:
AbstractCatchElement, AbstractXmlDocumentType, Accept, Alias, Assign, Assign, Audio, Block, Break, Cancel, Ccxml, Choice, Clear, Createcall, Createccxml, Createconference, Data, Desc, Destroyconference, Dialogprepare, Dialogstart, Dialogterminate, Disconnect, Disconnect, Else, Else, Elseif, Elseif, Emphasis, Enumerate, Eventprocessor, Example, Example, Exit, Exit, Fetch, Field, Filled, Foreach, Form, Goto, Goto, Grammar, Grapheme, If, If, Initial, Item, Join, Lexeme, Lexicon, Lexicon, Lexicon, Link, Log, Log, Mark, Menu, Merge, Meta, Meta, Meta, Meta, Metadata, Metadata, Metadata, Metadata, Move, ObjectTag, OneOf, Option, P, Param, Phoneme, Phoneme, Prompt, Property, Prosody, Record, Redirect, Reject, Reprompt, Return, Rule, Ruleref, S, SayAs, Script, Script, Send, Speak, Sub, Subdialog, Submit, Tag, Text, Throw, Token, Transfer, Transition, Unjoin, Value, Var, Var, Voice, VoiceXmlComment, Vxml

public abstract class AbstractXmlNode
extends Object
implements XmlNode

Abstract base class for all nodes in an XML document.

Version:
$Revision: 2914 $
Author:
Steve Doyle, Dirk Schnelle-Walka
See Also:
XmlDocument

Field Summary
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
protected AbstractXmlNode(Node n, XmlNodeFactory<? extends XmlNode> nodeFactory)
          Constructs a new XmlNode.
 
Method Summary
<T extends XmlNode>
T
addChild(Class<T> tagClass)
          Adds an instance of the specified child class to this node.
 XmlNode addChild(String tagName)
          Adds an instance of the specified child class to this node.
<T extends XmlNode>
T
appendChild(Class<T> tagClass)
          Adds an instance of the specified child class to this node and appends it to the child nodes of this node.
 Node appendChild(Node newChild)
          Adds the node newChild to the end of the list of children of this node.
 AbstractXmlNode appendDeepClone(AbstractXmlNode origin)
          Appends a deep clone of the given node to the cildren of this node.
protected abstract  boolean canContainChild(String childName)
          Can the specified sub-tag be contained within this node?
 Node cloneNode(boolean deep)
          Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
 short compareDocumentPosition(Node other)
          Compares the reference node, i.e.
 boolean equals(Object obj)
          
 String getAttribute(String attribute)
          Convenient method to get the value of an attribute.
 Collection<String> getAttributeNames()
          Returns a collection of permitted attribute names for the node.
 NamedNodeMap getAttributes()
          A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
 String getBaseURI()
          The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI.
 NodeList getChildNodes()
          A NodeList that contains all children of this node.
<T extends XmlNode>
Collection<T>
getChildNodes(Class<T> tagClass)
          Return a collection of child nodes with the specified tag class.
<T extends XmlNode>
Collection<T>
getChildren()
          Return a collection of all child nodes.
 Collection<String> getDefinedAttributeNames()
          Retrieves a list of all attributes defined in this node.
 Object getFeature(String feature, String version)
          This method returns a specialized object which implements the specialized APIs of the specified feature and version, as specified in .
 Node getFirstChild()
          The first child of this node.
 String getFirstLevelTextContent()
          Returns the text contents of this node, similar to getTextContent() but without recursion.
 Node getLastChild()
          The last child of this node.
 String getLocalName()
          Returns the local part of the qualified name of this node.
 String getNamespaceURI()
          The namespace URI of this node, or null if it is unspecified.
 Node getNextSibling()
          The node immediately following this node.
 Node getNode()
          Retrieves the encapsulated node.
 XmlNodeFactory<? extends XmlNode> getNodeFactory()
          Retrieves the factory to create node lists.
 String getNodeName()
          The name of this node, depending on its type; see the table above.
 short getNodeType()
          A code representing the type of the underlying object, as defined above.
 String getNodeValue()
          The value of this node, depending on its type; see the table above.
 Document getOwnerDocument()
          The Document object associated with this node.
<T extends XmlDocument>
T
getOwnerXmlDocument(Class<T> documentClass)
          Retrieves the XmlDocument containing this node.
 Node getParentNode()
          The parent of this node.
 String getPrefix()
          The namespace prefix of this node, or null if it is unspecified.
 Node getPreviousSibling()
          The node immediately preceding this node.
 String getTextContent()
          This attribute returns the text content of this node and its descendants.
 Object getUserData(String key)
          Retrieves the object associated to a key on a this node.
 boolean hasAttributes()
          Returns whether this node (if it is an element) has any attributes.
 boolean hasChildNodes()
          Returns whether this node has any children.
 int hashCode()
          
 Node insertBefore(Node newChild, Node refChild)
          Inserts the node newChild before the existing child node refChild.
 boolean isDefaultNamespace(String namespaceURI)
          This method checks if the specified namespaceURI is the default namespace or not.
 boolean isEqualNode(Node other)
          Tests whether two nodes are equal.
 boolean isSameNode(Node other)
          Returns whether this node is the same node as the given one.
 boolean isSupported(String feature, String version)
          Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.
 String lookupNamespaceURI(String prefix)
          Look up the namespace URI associated to the given prefix, starting from this node.
 String lookupPrefix(String namespaceURI)
          Look up the prefix associated to the given namespace URI, starting from this node.
 void normalize()
          Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.
 Node removeChild(Node oldChild)
          Removes the child node indicated by oldChild from the list of children, and returns it.
 Node replaceChild(Node newChild, Node oldChild)
          Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.
 void setAttribute(String name, String value)
          Convenient method to set the value of an attribute.
 void setNodeValue(String nodeValue)
          The value of this node, depending on its type; see the table above.
 void setPrefix(String prefix)
          The namespace prefix of this node, or null if it is unspecified.
 void setTextContent(String textContent)
          This attribute returns the text content of this node and its descendants.
 Object setUserData(String key, Object data, UserDataHandler handler)
          Associate an object to a key on this node.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jvoicexml.xml.XmlNode
getTagName, newInstance
 

Constructor Detail

AbstractXmlNode

protected AbstractXmlNode(Node n,
                          XmlNodeFactory<? extends XmlNode> nodeFactory)
Constructs a new XmlNode.

Parameters:
n - The encapsulated node.
nodeFactory - Node factory to create node lists.
Method Detail

getChildNodes

public final NodeList getChildNodes()
A NodeList that contains all children of this node.

Specified by:
getChildNodes in interface Node
Returns:
NodeList

getNode

public final Node getNode()
Retrieves the encapsulated node.

Specified by:
getNode in interface XmlNode
Returns:
The encapsulated node.

getNodeFactory

public final XmlNodeFactory<? extends XmlNode> getNodeFactory()
Retrieves the factory to create node lists.

Returns:
Factory to create node lists.
Since:
0.5

getAttribute

public final String getAttribute(String attribute)
Convenient method to get the value of an attribute.

Specified by:
getAttribute in interface XmlNode
Parameters:
attribute - Name of the attribute.
Returns:
Value of theattribute, null if the value of the attribute cannot be retrieved.

setAttribute

public final void setAttribute(String name,
                               String value)
Convenient method to set the value of an attribute. If the assigned value is null then the attribute is removed.

Specified by:
setAttribute in interface XmlNode
Parameters:
name - Name of the attribute.
value - New value of the attribute or null to remove the attribute.

appendChild

public final Node appendChild(Node newChild)
Adds the node newChild to the end of the list of children of this node.

Specified by:
appendChild in interface Node
Parameters:
newChild - The node to add.If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node
Returns:
The node added.

appendDeepClone

public AbstractXmlNode appendDeepClone(AbstractXmlNode origin)
Appends a deep clone of the given node to the cildren of this node.

Parameters:
origin - the node to clone
Since:
0.7.5

cloneNode

public final Node cloneNode(boolean deep)
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.

Specified by:
cloneNode in interface Node
Parameters:
deep - If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element).
Returns:
The duplicate node.

getAttributes

public final NamedNodeMap getAttributes()
A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

Specified by:
getAttributes in interface Node
Returns:
NamedNodeMap

getLocalName

public final String getLocalName()
Returns the local part of the qualified name of this node.

Specified by:
getLocalName in interface Node
Returns:
String

getNamespaceURI

public final String getNamespaceURI()
The namespace URI of this node, or null if it is unspecified.

Specified by:
getNamespaceURI in interface Node
Returns:
String

getNodeName

public final String getNodeName()
The name of this node, depending on its type; see the table above.

Specified by:
getNodeName in interface Node
Returns:
String

getNodeType

public final short getNodeType()
A code representing the type of the underlying object, as defined above.

Specified by:
getNodeType in interface Node
Returns:
short

getNodeValue

public final String getNodeValue()
The value of this node, depending on its type; see the table above.

Specified by:
getNodeValue in interface Node
Returns:
String

getOwnerDocument

public final Document getOwnerDocument()
The Document object associated with this node.

Specified by:
getOwnerDocument in interface Node
Returns:
Document

getOwnerXmlDocument

public final <T extends XmlDocument> T getOwnerXmlDocument(Class<T> documentClass)
Retrieves the XmlDocument containing this node.

Type Parameters:
T - type of the owner document.
Parameters:
documentClass - owner document's class.
Returns:
document containing this class.
Since:
0.6

getPrefix

public final String getPrefix()
The namespace prefix of this node, or null if it is unspecified.

Specified by:
getPrefix in interface Node
Returns:
String

getUserData

public final Object getUserData(String key)
Retrieves the object associated to a key on a this node. The object must first have been set to this node by calling setUserData with the same key.

Specified by:
getUserData in interface Node
Parameters:
key - The key the object is associated to.
Returns:
Returns the DOMUserData associated to the given key on this node, or null if there was none.

hasAttributes

public final boolean hasAttributes()
Returns whether this node (if it is an element) has any attributes.

Specified by:
hasAttributes in interface Node
Returns:
true if this node has any attributes, false otherwise.

hasChildNodes

public final boolean hasChildNodes()
Returns whether this node has any children.

Specified by:
hasChildNodes in interface Node
Returns:
true if this node has any children, false otherwise.

insertBefore

public final Node insertBefore(Node newChild,
                               Node refChild)
Inserts the node newChild before the existing child node refChild.

Specified by:
insertBefore in interface Node
Parameters:
newChild - The node to insert.
refChild - The reference node, i.e., the node before which the new node must be inserted.
Returns:
The node being inserted.

isSupported

public final boolean isSupported(String feature,
                                 String version)
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.

Specified by:
isSupported in interface Node
Parameters:
feature - The name of the feature to test. This is the same name which can be passed to the method hasFeature on DOMImplementation.
version - This is the version number of the feature to test. In Level 2, version 1, this is the string "2.0". If the version is not specified, supporting any version of the feature will cause the method to return true.
Returns:
Returns true if the specified feature is supported on this node, false otherwise.

normalize

public final void normalize()
Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.

Specified by:
normalize in interface Node

removeChild

public final Node removeChild(Node oldChild)
Removes the child node indicated by oldChild from the list of children, and returns it.

Specified by:
removeChild in interface Node
Parameters:
oldChild - The node being removed.
Returns:
The node removed.

replaceChild

public final Node replaceChild(Node newChild,
                               Node oldChild)
Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.

Specified by:
replaceChild in interface Node
Parameters:
newChild - The new node to put in the child list.
oldChild - The node being replaced in the list.
Returns:
The node replaced.

setNodeValue

public final void setNodeValue(String nodeValue)
The value of this node, depending on its type; see the table above.

Specified by:
setNodeValue in interface Node
Parameters:
nodeValue - String

setPrefix

public final void setPrefix(String prefix)
The namespace prefix of this node, or null if it is unspecified.

Specified by:
setPrefix in interface Node
Parameters:
prefix - String

setUserData

public final Object setUserData(String key,
                                Object data,
                                UserDataHandler handler)
Associate an object to a key on this node. The object can later be retrieved from this node by calling getUserData with the same key.

Specified by:
setUserData in interface Node
Parameters:
key - The key to associate the object to.
data - The object to associate to the given key, or null to remove any existing association to that key.
handler - The handler to associate to that key, or null
Returns:
Returns the DOMUserData previously associated to the given key on this node, or null if there was none.

getFirstChild

public final Node getFirstChild()
The first child of this node.

Specified by:
getFirstChild in interface Node
Returns:
Node

getLastChild

public final Node getLastChild()
The last child of this node.

Specified by:
getLastChild in interface Node
Returns:
Node

getNextSibling

public final Node getNextSibling()
The node immediately following this node.

Specified by:
getNextSibling in interface Node
Returns:
Node

getPreviousSibling

public final Node getPreviousSibling()
The node immediately preceding this node.

Specified by:
getPreviousSibling in interface Node
Returns:
Node

getParentNode

public final Node getParentNode()
The parent of this node.

Specified by:
getParentNode in interface Node
Returns:
Node

getBaseURI

public final String getBaseURI()
The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI.

Specified by:
getBaseURI in interface Node
Returns:
String

compareDocumentPosition

public final short compareDocumentPosition(Node other)
Compares the reference node, i.e.

Specified by:
compareDocumentPosition in interface Node
Parameters:
other - The node to compare against the reference node.
Returns:
Returns how the node is positioned relatively to the reference node.

getTextContent

public final String getTextContent()
This attribute returns the text content of this node and its descendants.

Specified by:
getTextContent in interface Node
Returns:
String

getFirstLevelTextContent

public final String getFirstLevelTextContent()
Returns the text contents of this node, similar to getTextContent() but without recursion.

Returns:
text content.
Since:
0.6

setTextContent

public final void setTextContent(String textContent)
This attribute returns the text content of this node and its descendants.

Specified by:
setTextContent in interface Node
Parameters:
textContent - String

isSameNode

public final boolean isSameNode(Node other)
Returns whether this node is the same node as the given one.

Specified by:
isSameNode in interface Node
Parameters:
other - The node to test against.
Returns:
Returns true if the nodes are the same, false otherwise.

lookupPrefix

public final String lookupPrefix(String namespaceURI)
Look up the prefix associated to the given namespace URI, starting from this node.

Specified by:
lookupPrefix in interface Node
Parameters:
namespaceURI - The namespace URI to look for.
Returns:
Returns an associated namespace prefix if found or null if none is found. If more than one prefix are associated to the namespace prefix, the returned namespace prefix is implementation dependent.

isDefaultNamespace

public final boolean isDefaultNamespace(String namespaceURI)
This method checks if the specified namespaceURI is the default namespace or not.

Specified by:
isDefaultNamespace in interface Node
Parameters:
namespaceURI - The namespace URI to look for.
Returns:
Returns true if the specified namespaceURI is the default namespace, false otherwise.

lookupNamespaceURI

public final String lookupNamespaceURI(String prefix)
Look up the namespace URI associated to the given prefix, starting from this node.

Specified by:
lookupNamespaceURI in interface Node
Parameters:
prefix - The prefix to look for. If this parameter is null, the method will return the default namespace URI if any.
Returns:
Returns the associated namespace URI or null if none is found.

isEqualNode

public final boolean isEqualNode(Node other)
Tests whether two nodes are equal.

Specified by:
isEqualNode in interface Node
Parameters:
other - The node to compare equality with.
Returns:
Returns true if the nodes are equal, false otherwise.

getFeature

public final Object getFeature(String feature,
                               String version)
This method returns a specialized object which implements the specialized APIs of the specified feature and version, as specified in .

Specified by:
getFeature in interface Node
Parameters:
feature - The name of the feature requested. Note that any plus sign "+" prepended to the name of the feature will be ignored since it is not significant in the context of this method.
version - This is the version number of the feature to test.
Returns:
Returns an object which implements the specialized APIs of the specified feature and version, if any, or null if there is no object which implements interfaces associated with that feature. If the DOMObject returned by this method implements the Node interface, it must delegate to the primary core Node and not return results inconsistent with the primary core Node such as attributes, childNodes, etc.

addChild

public final <T extends XmlNode> T addChild(Class<T> tagClass)
Adds an instance of the specified child class to this node. This causes a new node to be created and appended to this node. The type of the node to add must be a subclass of the XmlNode class.

Type Parameters:
T - Node type to load.
Parameters:
tagClass - The class type of the node to add.
Returns:
Newly created and appended node or null if the child is not allowed on this node.
Since:
0.6

appendChild

public final <T extends XmlNode> T appendChild(Class<T> tagClass)
Adds an instance of the specified child class to this node and appends it to the child nodes of this node.

Type Parameters:
T - Node type to load.
Parameters:
tagClass - The class type of the node to add.
Returns:
Newly created and appended node or null if the child is not allowed on this node.

addChild

public final XmlNode addChild(String tagName)
Adds an instance of the specified child class to this node. This causes a new node to be created and appended to this node. The type of the node to add must be a subclass of the XmlNode class.

Specified by:
addChild in interface XmlNode
Parameters:
tagName - the tag name of the node to add without any attributes.
Returns:
Newly created and appended node or null if the child is not allowed on this node.

getChildNodes

public final <T extends XmlNode> Collection<T> getChildNodes(Class<T> tagClass)
Return a collection of child nodes with the specified tag class.

Specified by:
getChildNodes in interface XmlNode
Type Parameters:
T - Type of the child nodes.
Parameters:
tagClass - Class of child node to return.
Returns:
A collection of child nodes of the specified type. If this node does not contain any child nodes of the specified type then an empty collection is returned.

getChildren

public final <T extends XmlNode> Collection<T> getChildren()
Return a collection of all child nodes.

Specified by:
getChildren in interface XmlNode
Type Parameters:
T - Type of the child nodes.
Returns:
A collection of child nodes of the specified type. If this node does not contain any child nodes of the specified type then an empty collection is returned.

canContainChild

protected abstract boolean canContainChild(String childName)
Can the specified sub-tag be contained within this node?

Parameters:
childName - Name of child.
Returns:
True if the sub-tag is allowed on this node.

toString

public String toString()

Overrides:
toString in class Object

getAttributeNames

public Collection<String> getAttributeNames()
Returns a collection of permitted attribute names for the node.

Specified by:
getAttributeNames in interface XmlNode
Returns:
A collection of attribute names that are allowed for the node

getDefinedAttributeNames

public final Collection<String> getDefinedAttributeNames()
Retrieves a list of all attributes defined in this node.

Returns:
list of all defined attributes
Since:
0.7.5

equals

public final boolean equals(Object obj)

Overrides:
equals in class Object
Since:
0.7

hashCode

public final int hashCode()

Overrides:
hashCode in class Object
Since:
0.7


Copyright © 2005-2009JVoiceXML group.