uk.ac.starlink.hdx
Class HdxDocument

java.lang.Object
  extended by uk.ac.starlink.hdx.HdxDocument
All Implemented Interfaces:
Cloneable, Document, Node

public class HdxDocument
extends Object
implements Document

Hdx implementation of the org.w3c.dom.Document interface. This implements allows clients to create mutually consistent implementations of the various org.w3c.dom interfaces. It also extends the interface by adding creation method createElement(HdxFacade).

To avoid confusion, note that, despite its name, HdxDocumentFactory is not a general factory for creating empty instances of HdxDocument. If you wish to create a blank HdxDocument (perhaps because you are implementing HdxDocumentFactory.makeHdxDocument(java.net.URL)), you do so simply with a call to

   HdxDOMImplementation.getInstance().createDocument(null,<el>,null)
 
(where <el> represents the name of the document element.

Note that only DOM Level 2 methods are currently implemented. If this class is built using JDK1.5, then the DOM Level 3 methods will be present, but they do not implement the functionality defined by the DOM Level 3 specification (mostly they throw NOT_SUPPORTED_ERR type DOMExceptions).

Version:
$Id$
Author:
Norman Gray, Starlink

Nested Class Summary
static class HdxDocument.NodeUtil
          Collection of rather ragged Node utilities.
 
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
HdxDocument()
           
 
Method Summary
 Node adoptNode(Node source)
           
 Node appendChild(Node newChild)
          
 Object clone()
          Creates and returns a copy of this Node.
protected  Object clone(boolean deep)
          Creates and returns a copy of this Node.
 Node cloneNode(boolean deep)
          Returns a duplicate of this Node.
 short compareDocumentPosition(Node other)
          Not implemented
 Attr createAttribute(String name)
           
 Attr createAttributeNS(String namespaceURI, String qualifiedName)
           
 CDATASection createCDATASection(String data)
           
 Comment createComment(String data)
           
 DocumentFragment createDocumentFragment()
           
 Element createElement(HdxFacade facade)
          Creates an element which manages its children using a HdxFacade.
 Element createElement(String tagName)
           
 Element createElementNS(String namespaceURI, String qualifiedName)
           
 EntityReference createEntityReference(String name)
           
 ProcessingInstruction createProcessingInstruction(String target, String data)
           
 Text createTextNode(String data)
           
 boolean equals(Object t)
          Indicates whether some other object is `equal to' this one.
 NamedNodeMap getAttributes()
           
 String getBaseURI()
          Not implemented
 NodeList getChildNodes()
           
 DocumentType getDoctype()
           
 Element getDocumentElement()
           
 String getDocumentURI()
           
 DOMConfiguration getDomConfig()
          Not implemented
 Element getElementById(String elementId)
           
 NodeList getElementsByTagName(String tagname)
           
 NodeList getElementsByTagNameNS(String namespaceURI, String localName)
          Returns a NodeList of all the descendant Elements with a given local name and namespace URI in the order in which they are encountered in a preorder traversal of this Element tree.
 Object getFeature(String feature, String version)
          Not implemented
 Node getFirstChild()
           
 DOMImplementation getImplementation()
           
 String getInputEncoding()
          Not implemented
 Node getLastChild()
           
 String getLocalName()
          Returns the local part of the qualified name of this node.
 String getNamespaceURI()
           
 Node getNextSibling()
           
 String getNodeName()
           
 short getNodeType()
           
 String getNodeValue()
           
 Document getOwnerDocument()
           
 Node getParentNode()
           
 String getPrefix()
           
 Node getPreviousSibling()
           
 boolean getStrictErrorChecking()
          Not implemented
 String getTextContent()
           
 Object getUserData(String key)
          Not implemented
 String getXmlEncoding()
          Not implemented
 boolean getXmlStandalone()
          Not implemented
 String getXmlVersion()
          Not implemented
 boolean hasAttributes()
           
 boolean hasChildNodes()
           
 int hashCode()
           
 Node importNode(Node importedNode, boolean deep)
           
 Node insertBefore(Node newChild, Node refChild)
          
 boolean isDefaultNamespace(String namespaceURI)
          Not implemented
 boolean isEqualNode(Node node)
           
 boolean isSameNode(Node other)
           
 boolean isSupported(String feature, String version)
           
 String lookupNamespaceURI(String prefix)
          Not implemented
 String lookupPrefix(String namespaceURI)
          Not implemented
 void normalize()
           
 void normalizeDocument()
          Not implemented
 Node removeChild(Node oldChild)
          
 Node renameNode(Node n, String namespaceURI, String qualifiedName)
          Not implemented
 Node replaceChild(Node newChild, Node oldChild)
          
 void setDocumentURI(String documentURI)
           
 void setInputEncoding(String value)
          Not implemented
 void setNodeValue(String nodeValue)
           
 void setPrefix(String prefix)
           
 void setStrictErrorChecking(boolean check)
          Not implemented
 void setTextContent(String textContent)
           
 Object setUserData(String key, Object data, UserDataHandler handler)
          Not implemented
 void setXmlEncoding(String value)
          Not implemented
 void setXmlStandalone(boolean value)
          Not implemented
 void setXmlVersion(String value)
          Not implemented
 String toString()
           
protected  void unimplementedMethod(String methodName)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
 

Constructor Detail

HdxDocument

public HdxDocument()
Method Detail

getDoctype

public DocumentType getDoctype()
Specified by:
getDoctype in interface Document

getNodeName

public String getNodeName()
Specified by:
getNodeName in interface Node

getImplementation

public DOMImplementation getImplementation()
Specified by:
getImplementation in interface Document

getDocumentElement

public Element getDocumentElement()
Specified by:
getDocumentElement in interface Document

createElement

public Element createElement(String tagName)
                      throws DOMException
Specified by:
createElement in interface Document
Throws:
DOMException

createElement

public Element createElement(HdxFacade facade)
                      throws DOMException
Creates an element which manages its children using a HdxFacade. The tagName of the resulting element is that corresponding to the HdxResourceType.

This is an extension to the org.w3c.dom.Document interface.

The resulting element has the property that if it is cloned using clone(), the resulting element is also a facade for the underlying object; if it is cloned using cloneNode, however, the resulting element is an ordinary element, which is now independent of the underlying object.

Parameters:
facade - an implementation of the HdxFacade interface
Throws:
IllegalArgumentException - if the facade is invalid.
DOMException

createDocumentFragment

public DocumentFragment createDocumentFragment()
Specified by:
createDocumentFragment in interface Document

createTextNode

public Text createTextNode(String data)
Specified by:
createTextNode in interface Document

createComment

public Comment createComment(String data)
Specified by:
createComment in interface Document

createCDATASection

public CDATASection createCDATASection(String data)
                                throws DOMException
Specified by:
createCDATASection in interface Document
Throws:
DOMException

createProcessingInstruction

public ProcessingInstruction createProcessingInstruction(String target,
                                                         String data)
                                                  throws DOMException
Specified by:
createProcessingInstruction in interface Document
Throws:
DOMException

createAttribute

public Attr createAttribute(String name)
                     throws DOMException
Specified by:
createAttribute in interface Document
Throws:
DOMException

createEntityReference

public EntityReference createEntityReference(String name)
                                      throws DOMException
Specified by:
createEntityReference in interface Document
Throws:
DOMException

getElementsByTagName

public NodeList getElementsByTagName(String tagname)
Specified by:
getElementsByTagName in interface Document

getElementsByTagNameNS

public NodeList getElementsByTagNameNS(String namespaceURI,
                                       String localName)
Returns a NodeList of all the descendant Elements with a given local name and namespace URI in the order in which they are encountered in a preorder traversal of this Element tree. In this implementation this is always an empty list, since this tree always represents elements in the empty namespace.

Specified by:
getElementsByTagNameNS in interface Document

importNode

public Node importNode(Node importedNode,
                       boolean deep)
                throws DOMException
Specified by:
importNode in interface Document
Throws:
DOMException

createElementNS

public Element createElementNS(String namespaceURI,
                               String qualifiedName)
                        throws DOMException
Specified by:
createElementNS in interface Document
Throws:
DOMException

createAttributeNS

public Attr createAttributeNS(String namespaceURI,
                              String qualifiedName)
                       throws DOMException
Specified by:
createAttributeNS in interface Document
Throws:
DOMException

getElementById

public Element getElementById(String elementId)
Specified by:
getElementById in interface Document

renameNode

public Node renameNode(Node n,
                       String namespaceURI,
                       String qualifiedName)
Not implemented

Specified by:
renameNode in interface Document

normalizeDocument

public void normalizeDocument()
Not implemented

Specified by:
normalizeDocument in interface Document

getDomConfig

public DOMConfiguration getDomConfig()
Not implemented

Specified by:
getDomConfig in interface Document

adoptNode

public Node adoptNode(Node source)
Specified by:
adoptNode in interface Document

setDocumentURI

public void setDocumentURI(String documentURI)
Specified by:
setDocumentURI in interface Document

getDocumentURI

public String getDocumentURI()
Specified by:
getDocumentURI in interface Document

setStrictErrorChecking

public void setStrictErrorChecking(boolean check)
Not implemented

Specified by:
setStrictErrorChecking in interface Document

getStrictErrorChecking

public boolean getStrictErrorChecking()
Not implemented

Specified by:
getStrictErrorChecking in interface Document

setXmlVersion

public void setXmlVersion(String value)
Not implemented

Specified by:
setXmlVersion in interface Document

getXmlVersion

public String getXmlVersion()
Not implemented

Specified by:
getXmlVersion in interface Document

setXmlStandalone

public void setXmlStandalone(boolean value)
Not implemented

Specified by:
setXmlStandalone in interface Document

getXmlStandalone

public boolean getXmlStandalone()
Not implemented

Specified by:
getXmlStandalone in interface Document

setXmlEncoding

public void setXmlEncoding(String value)
Not implemented


getXmlEncoding

public String getXmlEncoding()
Not implemented

Specified by:
getXmlEncoding in interface Document

getInputEncoding

public String getInputEncoding()
Not implemented

Specified by:
getInputEncoding in interface Document

setInputEncoding

public void setInputEncoding(String value)
Not implemented


toString

public String toString()
Overrides:
toString in class Object

getNodeValue

public String getNodeValue()
                    throws DOMException
Specified by:
getNodeValue in interface Node
Throws:
DOMException

setNodeValue

public void setNodeValue(String nodeValue)
                  throws DOMException
Specified by:
setNodeValue in interface Node
Throws:
DOMException

getNodeType

public short getNodeType()
Specified by:
getNodeType in interface Node

hasAttributes

public boolean hasAttributes()
Specified by:
hasAttributes in interface Node

getAttributes

public NamedNodeMap getAttributes()
Specified by:
getAttributes in interface Node

getParentNode

public Node getParentNode()
Specified by:
getParentNode in interface Node

getChildNodes

public NodeList getChildNodes()
Specified by:
getChildNodes in interface Node

getFirstChild

public Node getFirstChild()
Specified by:
getFirstChild in interface Node

getLastChild

public Node getLastChild()
Specified by:
getLastChild in interface Node

getPreviousSibling

public Node getPreviousSibling()
Specified by:
getPreviousSibling in interface Node

getNextSibling

public Node getNextSibling()
Specified by:
getNextSibling in interface Node

getOwnerDocument

public Document getOwnerDocument()
Specified by:
getOwnerDocument in interface Node

insertBefore

public Node insertBefore(Node newChild,
                         Node refChild)
                  throws DOMException

Specified by:
insertBefore in interface Node
Throws:
IllegalArgumentException - (unchecked) if newChild is null
DOMException

replaceChild

public Node replaceChild(Node newChild,
                         Node oldChild)
                  throws DOMException

Specified by:
replaceChild in interface Node
Throws:
IllegalArgumentException - (unchecked) if newChild or oldChild is null
DOMException

removeChild

public Node removeChild(Node oldChild)
                 throws DOMException

Specified by:
removeChild in interface Node
Throws:
IllegalArgumentException - (unchecked) if oldChild is null
DOMException

appendChild

public Node appendChild(Node newChild)
                 throws DOMException

Specified by:
appendChild in interface Node
Throws:
IllegalArgumentException - (unchecked) if newChild is null
DOMException

hasChildNodes

public boolean hasChildNodes()
Specified by:
hasChildNodes in interface Node

cloneNode

public Node cloneNode(boolean deep)
Returns a duplicate of this Node. The difference between this method and the clone(boolean) method is that the node returned by this method has no parent.

Although it's not completely specified in the documentation, here, the cloned node does not not retain references to the original's siblings. If the clone is a shallow one, then the result node has no children either.

Implementation node: classes which extend HdxNode should preserve the distinction between cloneNode() and clone(). You may use clone(false) to copy the object fields if that is convenient, but we recurse using cloneNode(true). This means that we can implement different behaviour for the two methods if we need to, in extending classes. This distinction is admittedly under-specified right now: if you are writing code where the details matter, you might want to contact the code authors to see if (a) you are attempting something you oughtn't (wicked!), or (b) it's time to pin this specification down more precisely.

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

clone

public Object clone()
Creates and returns a copy of this Node. The difference between this method and a deep clone using cloneNode(boolean) is that the clone and the original share a reference to their parent.

Overrides:
clone in class Object
Returns:
a clone of this instance

clone

protected Object clone(boolean deep)
Creates and returns a copy of this Node. The difference between this method and a deep clone using cloneNode(boolean) is that the clone and the original share a reference to their parent.

Parameters:
deep - if true, recursively clone the subtree under this node; if false, clone only the node itself
Returns:
a clone of this instance

equals

public boolean equals(Object t)
Indicates whether some other object is `equal to' this one.

Two Nodes are equal to one another if their types, names and values are equal. However, to avoid a potentially very expensive recursion, this test does not depend on whether the two nodes' children are also equal.

Note that this is overridden for Element tests.

Overrides:
equals in class Object
Parameters:
t - an object to be tested for equality with this one
Returns:
true if the Nodes should be regarded as equivalent
See Also:
HdxElement.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

normalize

public void normalize()
Specified by:
normalize in interface Node

isSupported

public boolean isSupported(String feature,
                           String version)
Specified by:
isSupported in interface Node

getNamespaceURI

public String getNamespaceURI()
Specified by:
getNamespaceURI in interface Node

getPrefix

public String getPrefix()
Specified by:
getPrefix in interface Node

setPrefix

public void setPrefix(String prefix)
               throws DOMException
Specified by:
setPrefix in interface Node
Throws:
DOMException

getLocalName

public String getLocalName()
Returns the local part of the qualified name of this node. Since Hdx elements are always in no namespace, this is always null.

Specified by:
getLocalName in interface Node
Returns:
null

setUserData

public Object setUserData(String key,
                          Object data,
                          UserDataHandler handler)
Not implemented

Specified by:
setUserData in interface Node

getUserData

public Object getUserData(String key)
Not implemented

Specified by:
getUserData in interface Node

getFeature

public Object getFeature(String feature,
                         String version)
Not implemented

Specified by:
getFeature in interface Node

isEqualNode

public boolean isEqualNode(Node node)
Specified by:
isEqualNode in interface Node

lookupNamespaceURI

public String lookupNamespaceURI(String prefix)
Not implemented

Specified by:
lookupNamespaceURI in interface Node

isDefaultNamespace

public boolean isDefaultNamespace(String namespaceURI)
Not implemented

Specified by:
isDefaultNamespace in interface Node

lookupPrefix

public String lookupPrefix(String namespaceURI)
Not implemented

Specified by:
lookupPrefix in interface Node

isSameNode

public boolean isSameNode(Node other)
Specified by:
isSameNode in interface Node

setTextContent

public void setTextContent(String textContent)
Specified by:
setTextContent in interface Node

getTextContent

public String getTextContent()
Specified by:
getTextContent in interface Node

compareDocumentPosition

public short compareDocumentPosition(Node other)
Not implemented

Specified by:
compareDocumentPosition in interface Node

getBaseURI

public String getBaseURI()
Not implemented

Specified by:
getBaseURI in interface Node

unimplementedMethod

protected void unimplementedMethod(String methodName)
                            throws UnsupportedOperationException
Throws:
UnsupportedOperationException


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.