Class AbstractNode
- All Implemented Interfaces:
Serializable, Cloneable, Node
- Direct Known Subclasses:
AbstractAttribute, AbstractBranch, AbstractCharacterData, AbstractDocumentType, AbstractEntity, AbstractProcessingInstruction, Namespace
AbstractNode is an abstract base class for tree implementors
to use for implementation inheritence.
- Version:
- $Revision: 1.31 $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final DocumentFactoryTheDocumentFactoryinstance used by defaultprotected static final String[]Fields inherited from interface Node
ANY_NODE, ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, MAX_NODE_TYPE, NAMESPACE_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE, UNKNOWN_NODE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasXPathResult(Element parent) asXPathResultreturns a version of this node which is capable of being an XPath result.clone()clonewill return a deep clone or if this node is read-only then clone will return the same instance.createPattern(String patternText) createXPath(String xpathExpression) createXPathcreates an XPath object for the given xpathExpression.createXPathFilter(String patternText) protected NodecreateXPathResult(Element parent) detach()Removes this node from its parent if there is one.getDocumentreturns theDocumentthat thisNodeis part of if this node supports the parent relationship.protected DocumentFactorygetName()getNamereturns the name of this node.shortReturns the code according to the type of node.DOCUMENT ME!getParentreturns the parentElementif this node supports the parent relationship or null if it is the root element or does not support the parent relationship.getPath()Returns the XPath expression which will return a node set containing the given node such as /a/b/@c.Returns the XPath string-value of this node.getText()Returns the text of this node.Returns the XPath expression which will return a nodeset of one node which is the current node.booleanhasContentreturns true if this node is a Branch (either an Element or a Document) and it contains at least one content node such as a child Element or Text node.booleanisReadOnlyreturns true if this node is read only and cannot be modified.booleanmatchesreturns true if evaluating the given XPath expression on this node returns a non-empty node set containing this node.numberValueOf(String xpathExpression) numberValueOfevaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results in a number, or null if the result is not a number.selectNodes(String xpathExpression) selectNodesevaluates an XPath expression and returns the result as aListofNodeinstances orStringinstances depending on the XPath expression.selectNodes(String xpathExpression, String comparisonXPathExpression) selectNodesevaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sortedListofNodeinstances.selectNodes(String xpathExpression, String comparisonXPathExpression, boolean removeDuplicates) selectNodesevaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sortedListofNodeinstances.selectObject(String xpathExpression) selectObjectevaluates an XPath expression and returns the result as anObject.selectSingleNode(String xpathExpression) selectSingleNodeevaluates an XPath expression and returns the result as a singleNodeinstance.voidsetDocument(Document document) setDocumentsets the document of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.voidSets the text data of this node or this method will throw anUnsupportedOperationExceptionif it is read-only.voidsetParentsets the parent relationship of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.voidSets the text data of this node or this method will throw anUnsupportedOperationExceptionif it is read-only.booleansupportsParentreturns true if this node supports the parent relationship.valueOfevaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.voidwritewrites this node as the default XML notation for this node.Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Node
accept, asXML, getPath, getUniquePath
-
Field Details
-
NODE_TYPE_NAMES
-
DOCUMENT_FACTORY
TheDocumentFactoryinstance used by default
-
-
Constructor Details
-
AbstractNode
public AbstractNode()
-
-
Method Details
-
getNodeType
public short getNodeType()Description copied from interface:NodeReturns the code according to the type of node. This makes processing nodes polymorphically much easier as the switch statement can be used instead of multiple if (instanceof) statements.- Specified by:
getNodeTypein interfaceNode- Returns:
- a W3C DOM complient code for the node type such as ELEMENT_NODE or ATTRIBUTE_NODE
-
getNodeTypeName
Description copied from interface:NodeDOCUMENT ME!- Specified by:
getNodeTypeNamein interfaceNode- Returns:
- the name of the type of node such as "Document", "Element", "Attribute" or "Text"
-
getDocument
Description copied from interface:NodegetDocumentreturns theDocumentthat thisNodeis part of if this node supports the parent relationship.This method is an optional feature and may not be supported for all
Nodeimplementations.- Specified by:
getDocumentin interfaceNode- Returns:
- the document of this node or null if this feature is not
supported or the node is not associated with a
Document
-
setDocument
Description copied from interface:NodesetDocumentsets the document of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.This method should only be called from inside a
Documentimplementation method and is not intended for general use.- Specified by:
setDocumentin interfaceNode- Parameters:
document- is the new document of this node.
-
getParent
Description copied from interface:NodegetParentreturns the parentElementif this node supports the parent relationship or null if it is the root element or does not support the parent relationship.This method is an optional feature and may not be supported for all
Nodeimplementations. -
setParent
Description copied from interface:NodesetParentsets the parent relationship of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.This method should only be called from inside an
Elementimplementation method and is not intended for general use. -
supportsParent
public boolean supportsParent()Description copied from interface:NodesupportsParentreturns true if this node supports the parent relationship.Some XML tree implementations are singly linked and only support downward navigation through children relationships. The default case is that both parent and children relationships are supported though for memory and performance reasons the parent relationship may not be supported.
- Specified by:
supportsParentin interfaceNode- Returns:
- true if this node supports the parent relationship or false it is not supported
-
isReadOnly
public boolean isReadOnly()Description copied from interface:NodeisReadOnlyreturns true if this node is read only and cannot be modified. Any attempt to modify a read-onlyNodewill result in anUnsupportedOperationExceptionbeing thrown.- Specified by:
isReadOnlyin interfaceNode- Returns:
- true if this
Nodeis read only and cannot be modified otherwise false.
-
hasContent
public boolean hasContent()Description copied from interface:NodehasContentreturns true if this node is a Branch (either an Element or a Document) and it contains at least one content node such as a child Element or Text node.- Specified by:
hasContentin interfaceNode- Returns:
- true if this
Nodeis a Branch with a nodeCount() of one or more.
-
getPath
Description copied from interface:NodeReturns the XPath expression which will return a node set containing the given node such as /a/b/@c. No indexing will be used to restrict the path if multiple elements with the same name occur on the path.
-
getUniquePath
Description copied from interface:NodeReturns the XPath expression which will return a nodeset of one node which is the current node. This method will use the XPath index operator to restrict the path if multiple elements with the same name occur on the path.
- Specified by:
getUniquePathin interfaceNode- Returns:
- the XPath expression which will return a nodeset containing just this node.
-
clone
-
detach
Description copied from interface:NodeRemoves this node from its parent if there is one. If this node is the root element of a document then it is removed from the document as well.
This method is useful if you want to remove a node from its source document and add it to another document. For example
Node node = ...; Element someOtherElement = ...; someOtherElement.add( node.detach() ); -
getName
Description copied from interface:NodegetNamereturns the name of this node. This is the XML local name of the element, attribute, entity or processing instruction. For CDATA and Text nodes this method will return null. -
setName
-
getText
-
getStringValue
Description copied from interface:NodeReturns the XPath string-value of this node. The behaviour of this method is defined in the XPath specification .- Specified by:
getStringValuein interfaceNode- Returns:
- the text from all the child Text and Element nodes appended together.
-
setText
-
write
Description copied from interface:Nodewritewrites this node as the default XML notation for this node. If you wish to control the XML output (such as for pretty printing, changing the indentation policy etc.) then please useXMLWriteror its derivations.- Specified by:
writein interfaceNode- Parameters:
writer- is theWriterto output the XML to- Throws:
IOException- DOCUMENT ME!
-
selectObject
-
selectNodes
Description copied from interface:NodeselectNodesevaluates an XPath expression and returns the result as aListofNodeinstances orStringinstances depending on the XPath expression.- Specified by:
selectNodesin interfaceNode- Parameters:
xpathExpression- is the XPath expression to be evaluated- Returns:
- the list of
NodeorStringinstances depending on the XPath expression
-
selectNodes
Description copied from interface:NodeselectNodesevaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sortedListofNodeinstances.- Specified by:
selectNodesin interfaceNode- Parameters:
xpathExpression- is the XPath expression to be evaluatedcomparisonXPathExpression- is the XPath expression used to compare the results by for sorting- Returns:
- the list of
Nodeinstances sorted by the comparisonXPathExpression
-
selectNodes
public List<Node> selectNodes(String xpathExpression, String comparisonXPathExpression, boolean removeDuplicates) Description copied from interface:NodeselectNodesevaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sortedListofNodeinstances.- Specified by:
selectNodesin interfaceNode- Parameters:
xpathExpression- is the XPath expression to be evaluatedcomparisonXPathExpression- is the XPath expression used to compare the results by for sortingremoveDuplicates- if this parameter is true then duplicate values (using the comparisonXPathExpression) are removed from the result List.- Returns:
- the list of
Nodeinstances sorted by the comparisonXPathExpression
-
selectSingleNode
Description copied from interface:NodeselectSingleNodeevaluates an XPath expression and returns the result as a singleNodeinstance.- Specified by:
selectSingleNodein interfaceNode- Parameters:
xpathExpression- is the XPath expression to be evaluated- Returns:
- the
Nodematching the XPath expression
-
valueOf
Description copied from interface:NodevalueOfevaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node. The string-value for a given node type is defined in the XPath specification . -
numberValueOf
Description copied from interface:NodenumberValueOfevaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results in a number, or null if the result is not a number.- Specified by:
numberValueOfin interfaceNode- Parameters:
xpathExpression- is the XPath expression to be evaluated- Returns:
- the numeric result of the XPath expression or null if the result is not a number.
-
matches
Description copied from interface:Nodematchesreturns true if evaluating the given XPath expression on this node returns a non-empty node set containing this node.This method does not behave like the <xsl:if> element - if you want that behaviour, to evaluate if an XPath expression matches something, then you can use the following code to be equivalent...
if ( node.selectSingleNode( "/some/path" ) != nulll ) -
createXPath
Description copied from interface:NodecreateXPathcreates an XPath object for the given xpathExpression. The XPath object allows the variable context to be specified.- Specified by:
createXPathin interfaceNode- Parameters:
xpathExpression- is the XPath expression to be evaluated- Returns:
- an XPath object represeting the given expression
-
createXPathFilter
-
createPattern
-
asXPathResult
Description copied from interface:NodeasXPathResultreturns a version of this node which is capable of being an XPath result. The result of an XPath expression should always support the parent relationship, whether the original XML tree was singly or doubly linked. If the node does not support the parent relationship then a new node will be created which is linked to its parent and returned.- Specified by:
asXPathResultin interfaceNode- Parameters:
parent- DOCUMENT ME!- Returns:
- a
Nodewhich supports the parent relationship
-
getDocumentFactory
-
createXPathResult
-