NetKernel APIs


org.ten60.netkernel.xml.xda
Class DOMXDA

java.lang.Object
  extended byorg.ten60.netkernel.xml.xda.DOMXDA
All Implemented Interfaces:
IXDA, IXDAIterator, IXDAReadOnly, IXDAReadOnlyIterator

public class DOMXDA
extends Object
implements IXDA, IXDAIterator, IXDAReadOnly, IXDAReadOnlyIterator

Implementation of IXDA, IXDAIterator, IXDAReadOnly and IXDAReadOnlyIterator using DOM


Field Summary
static String XMLNS_DECLARATION_URI
           
 
Constructor Summary
DOMXDA(Document aDocument)
          Creates a new instance of DOMXDA
DOMXDA(Document aDocument, boolean clone)
           
DOMXDA(DOMXDA aOther)
           
DOMXDA(Node aRoot, DOMXDA aParentXDA)
           
DOMXDA(Node aRoot, DOMXDA aParentXDA, boolean clone)
           
 
Method Summary
 void append(IXDAReadOnly aSource, String aSourceXPath, String aTargetXPath)
          Append fragment of source to this at a specified location or locations
 void appendPath(String aTargetXPath, String aNewRelativeXPath, String aOptionalValue)
          Builds and appends a chain of elements to a location or locations within this
 void applyNS(String aTargetXPath, String prefix, String uri)
          Apply namespace to target location or locations
 void declareNS(String aTargetXPath, String prefix, String uri)
           
 void delete(String aTargetXPath)
          Delete elements at target location or locations
 IXPathResult eval(String aTargetXPath)
          Evaluate the xpath against the document returning an IXPathResult
 String getCurrentXPath()
          return an xpath representation of the current context node
 Document getDocument()
           
 Document getFragment(Node node)
          Returns the document fragment located by a Node
 Document getFragment(String aXPath)
          Returns the document fragment located by an unambiguous XPath
 Map getMap(String aTargetXPath, boolean aTrim)
          Returns
 NodeList getNodeList(String aXPath)
          Evaluates the given XPath expression on the current document and returns a NodeList.
 List getNodesFor(String aXPath)
           
 String getPrefix(String aNamespace)
           
 Node getRoot()
           
 Node getSingleNode(NodeList aNodeList)
          Returns a the one and only node from a NodeList.
 Node getSingleNode(String aXpath)
          Returns the one and only node from an Xpath query.
 String getText(String aTargetXPath, boolean aTrim)
          Return the text that is contained at the element located using an XPath
 boolean hasNext()
          return true if there are more context nodes to move to
 void insertAfter(IXDAReadOnly aSource, String aSourceXPath, String aTargetXPath)
          Insert fragment of source to this after specified location or locations
 void insertBefore(IXDAReadOnly aSource, String aSourceXPath, String aTargetXPath)
          Insert fragment of source to this before specified location or locations
 boolean isTrue(String aTargetXPath)
          Evaluate and xpath against the document returning a boolean result
 IXDAIterator iterator(String aTargetXPath)
          Return an iterator over all elements match the xpath in this
 void move(String aSourceXPath, String aTargetXPath)
          Moves a fragment from one location in this to another
 boolean next()
          move to next context node, returns true if successful, false if there are no more nodes
 IXDAReadOnlyIterator readOnlyIterator(String aTargetXPath)
          Return an iterator over all elements that match the an XPath
 void removeNS(String aTargetXPath, String prefix)
          Remove namespace from target location or locations
 void rename(String aTargetXPath, String name)
          Rename elements at target location or locations
 void replace(IXDAReadOnly aSource, String aSourceXPath, String aTargetXPath)
          Replace fragments of this with fragments from source at specified location or locations
 void replaceByText(String aTargetXPath, String aText)
          Replace fragments of this with given text at specified location or locations
static Node safeDeepClone(Node aNode)
           
 void serialize(Writer aWriter, boolean indent)
          Serialize the whole document
 void serialize(Writer aWriter, String aTargetXPath, boolean indent)
          Serialize part of the document
 void setDirty()
           
 void setDirtyNS()
           
 void setText(String aTargetXPath, String aText)
          Sets the text of the element or elements at the target location of this
 Document toDOM()
           
 Document toDOMQuick()
           
 String toString()
           
 String toString(boolean aIndent)
          Returns a debug representation of the contained document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

XMLNS_DECLARATION_URI

public static final String XMLNS_DECLARATION_URI
See Also:
Constant Field Values
Constructor Detail

DOMXDA

public DOMXDA(Document aDocument,
              boolean clone)

DOMXDA

public DOMXDA(Document aDocument)
Creates a new instance of DOMXDA


DOMXDA

public DOMXDA(Node aRoot,
              DOMXDA aParentXDA)

DOMXDA

public DOMXDA(Node aRoot,
              DOMXDA aParentXDA,
              boolean clone)

DOMXDA

public DOMXDA(DOMXDA aOther)
Method Detail

getRoot

public Node getRoot()

getDocument

public Document getDocument()

setDirty

public void setDirty()

setDirtyNS

public void setDirtyNS()

getSingleNode

public Node getSingleNode(String aXpath)
                   throws XPathLocationException
Returns the one and only node from an Xpath query.

Parameters:
aXpath - The Xpath which is expected to have only one node.
Returns:
The node.
Throws:
NullTargetException - Thrown if the Xpath has zero nodes.
AmbiguousTargetException - Thrown if the Xpath has more than one node.
MalformedTargetException - Thrown if the Xpath is not valid.
AccessViolationException - Thrown when lock is not held on bean.
XPathLocationException

getSingleNode

public Node getSingleNode(NodeList aNodeList)
                   throws XPathLocationException
Returns a the one and only node from a NodeList.

Parameters:
aNodeList - The NodeList which is expected to have only one node.
Returns:
The node.
Throws:
NullTargetException - Thrown if the NodeList has zero nodes.
AmbiguousTargetException - Thrown if the node list has more than one node.
XPathLocationException

getNodeList

public NodeList getNodeList(String aXPath)
                     throws XPathLocationException
Evaluates the given XPath expression on the current document and returns a NodeList.

Parameters:
aXPath - The XPath to evaluate
Returns:
Returns a NodeList with zero or more matching nodes.
Throws:
MalformedTargetException - Thrown if the XPath cannot be parsed.
XPathLocationException

getNodesFor

public List getNodesFor(String aXPath)
                 throws XPathLocationException
Throws:
XPathLocationException

getFragment

public Document getFragment(String aXPath)
                     throws XPathLocationException
Returns the document fragment located by an unambiguous XPath

Throws:
XPathLocationException

getFragment

public Document getFragment(Node node)
                     throws DOMException
Returns the document fragment located by a Node

Throws:
DOMException

safeDeepClone

public static Node safeDeepClone(Node aNode)

getMap

public Map getMap(String aTargetXPath,
                  boolean aTrim)
           throws XPathLocationException
Returns

Parameters:
aTrim - If true the resulting string is trimed at beginning and end for whitespace.
Returns:
Returns a Map of node name to value for all nodes found by the XPath expression.
Throws:
AccessViolationException - Thrown when lock is not held on bean.
MalformedTargetException - Thrown if aXPath cannot be parsed.
XPathLocationException

append

public void append(IXDAReadOnly aSource,
                   String aSourceXPath,
                   String aTargetXPath)
            throws XPathLocationException,
                   XDOIncompatibilityException
Description copied from interface: IXDA
Append fragment of source to this at a specified location or locations

Specified by:
append in interface IXDA
Throws:
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element
XDOIncompatibilityException - throw if the implementation doesn't support this operation

appendPath

public void appendPath(String aTargetXPath,
                       String aNewRelativeXPath,
                       String aOptionalValue)
                throws XPathLocationException
Description copied from interface: IXDA
Builds and appends a chain of elements to a location or locations within this

Specified by:
appendPath in interface IXDA
Parameters:
aNewRelativeXPath - a simple xpath of form a/b/c to name a chain of elements to append.
aOptionalValue - a text value to assign to the leaf node, may be null
Throws:
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

applyNS

public void applyNS(String aTargetXPath,
                    String prefix,
                    String uri)
             throws XPathLocationException
Description copied from interface: IXDA
Apply namespace to target location or locations

Specified by:
applyNS in interface IXDA
Parameters:
prefix - prefix for the namespace
uri - uri for the namespace
Throws:
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

declareNS

public void declareNS(String aTargetXPath,
                      String prefix,
                      String uri)
               throws XPathLocationException
Throws:
XPathLocationException

delete

public void delete(String aTargetXPath)
            throws XPathLocationException
Description copied from interface: IXDA
Delete elements at target location or locations

Specified by:
delete in interface IXDA
Throws:
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

eval

public IXPathResult eval(String aTargetXPath)
                  throws XPathLocationException
Description copied from interface: IXDAReadOnly
Evaluate the xpath against the document returning an IXPathResult

Specified by:
eval in interface IXDAReadOnly
Throws:
XPathLocationException - throw if the xpath is malformed

getText

public String getText(String aTargetXPath,
                      boolean aTrim)
               throws XPathLocationException
Description copied from interface: IXDAReadOnly
Return the text that is contained at the element located using an XPath

Specified by:
getText in interface IXDAReadOnly
Parameters:
aTargetXPath - the xpath
aTrim - if true trim whitespace from the String
Returns:
the string
Throws:
XPathLocationException - throw if the xpath is malformed or doesn't point to a single unique element

hasNext

public boolean hasNext()
Description copied from interface: IXDAIterator
return true if there are more context nodes to move to

Specified by:
hasNext in interface IXDAIterator

insertAfter

public void insertAfter(IXDAReadOnly aSource,
                        String aSourceXPath,
                        String aTargetXPath)
                 throws XPathLocationException,
                        XDOIncompatibilityException
Description copied from interface: IXDA
Insert fragment of source to this after specified location or locations

Specified by:
insertAfter in interface IXDA
Throws:
XDOIncompatibilityException - throw if the implementation doesn't support this operation
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

insertBefore

public void insertBefore(IXDAReadOnly aSource,
                         String aSourceXPath,
                         String aTargetXPath)
                  throws XPathLocationException,
                         XDOIncompatibilityException
Description copied from interface: IXDA
Insert fragment of source to this before specified location or locations

Specified by:
insertBefore in interface IXDA
Throws:
XDOIncompatibilityException - throw if the implementation doesn't support this operation
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

isTrue

public boolean isTrue(String aTargetXPath)
               throws XPathLocationException
Description copied from interface: IXDAReadOnly
Evaluate and xpath against the document returning a boolean result

Specified by:
isTrue in interface IXDAReadOnly
Throws:
XPathLocationException - throw if the xpath is malformed

iterator

public IXDAIterator iterator(String aTargetXPath)
                      throws XPathLocationException
Description copied from interface: IXDA
Return an iterator over all elements match the xpath in this

Specified by:
iterator in interface IXDA
Throws:
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

readOnlyIterator

public IXDAReadOnlyIterator readOnlyIterator(String aTargetXPath)
                                      throws XPathLocationException
Description copied from interface: IXDAReadOnly
Return an iterator over all elements that match the an XPath

Specified by:
readOnlyIterator in interface IXDAReadOnly
Parameters:
aTargetXPath - the xpath
Returns:
the iterator
Throws:
XPathLocationException - throw if the xpath is malformed

move

public void move(String aSourceXPath,
                 String aTargetXPath)
          throws XPathLocationException
Description copied from interface: IXDA
Moves a fragment from one location in this to another

Specified by:
move in interface IXDA
Throws:
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

next

public boolean next()
Description copied from interface: IXDAIterator
move to next context node, returns true if successful, false if there are no more nodes

Specified by:
next in interface IXDAIterator

removeNS

public void removeNS(String aTargetXPath,
                     String prefix)
              throws XPathLocationException
Description copied from interface: IXDA
Remove namespace from target location or locations

Specified by:
removeNS in interface IXDA
Parameters:
prefix - prefix for the namespace
Throws:
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

rename

public void rename(String aTargetXPath,
                   String name)
            throws XPathLocationException
Description copied from interface: IXDA
Rename elements at target location or locations

Specified by:
rename in interface IXDA
Parameters:
name - the new element name
Throws:
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

replace

public void replace(IXDAReadOnly aSource,
                    String aSourceXPath,
                    String aTargetXPath)
             throws XPathLocationException,
                    XDOIncompatibilityException
Description copied from interface: IXDA
Replace fragments of this with fragments from source at specified location or locations

Specified by:
replace in interface IXDA
Throws:
XDOIncompatibilityException - throw if the implementation doesn't support this operation
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

replaceByText

public void replaceByText(String aTargetXPath,
                          String aText)
                   throws XPathLocationException
Description copied from interface: IXDA
Replace fragments of this with given text at specified location or locations

Specified by:
replaceByText in interface IXDA
Parameters:
aText - the text to place at locations
Throws:
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

setText

public void setText(String aTargetXPath,
                    String aText)
             throws XPathLocationException
Description copied from interface: IXDA
Sets the text of the element or elements at the target location of this

Specified by:
setText in interface IXDA
Throws:
XPathLocationException - throw if the xpath is malformed, xpaths don't result in well defined element

serialize

public void serialize(Writer aWriter,
                      String aTargetXPath,
                      boolean indent)
               throws XPathLocationException,
                      IOException
Description copied from interface: IXDAReadOnly
Serialize part of the document

Specified by:
serialize in interface IXDAReadOnly
Parameters:
aWriter - the writer to write the serialized document to
aTargetXPath - the xpath
indent - true if the document should be re-indented
Throws:
XPathLocationException - throw if the xpath is malformed or doesn't point to a single unique element
IOException - throw if the writer cannot be written to

serialize

public void serialize(Writer aWriter,
                      boolean indent)
               throws IOException
Description copied from interface: IXDAReadOnly
Serialize the whole document

Specified by:
serialize in interface IXDAReadOnly
Parameters:
aWriter - the writer to write the serialized document to
indent - true if the document should be re-indented
Throws:
IOException - throw if the writer cannot be written to

toString

public String toString(boolean aIndent)
Returns a debug representation of the contained document.

Parameters:
aIndent - Set to true to cause tidy (human-readable) output of the document.
Returns:
Returns a debug representation of the contained document.
Throws:
AccessViolationException - Thrown when the client thread doesn't have a lock.

toString

public String toString()

toDOMQuick

public Document toDOMQuick()

toDOM

public Document toDOM()

getCurrentXPath

public String getCurrentXPath()
Description copied from interface: IXDAIterator
return an xpath representation of the current context node

Specified by:
getCurrentXPath in interface IXDAIterator

getPrefix

public String getPrefix(String aNamespace)

NetKernel APIs


Copyright © 2002-2004 1060 Research Ltd. All Rights Reserved.