org.ozoneDB.xml.dom
Class DocumentImpl

java.lang.Object
  |
  +--org.ozoneDB.OzoneObject
        |
        +--org.ozoneDB.xml.dom.NodeImpl
              |
              +--org.ozoneDB.xml.dom.DocumentImpl
All Implemented Interfaces:
org.w3c.dom.Document, DocumentProxy, org.w3c.dom.DOMImplementation, java.io.Externalizable, org.w3c.dom.Node, NodeProxy, org.ozoneDB.OzoneCompatible, org.ozoneDB.OzoneCompatibleOrProxy, org.ozoneDB.OzoneRemote, java.io.Serializable
Direct Known Subclasses:
DocumentTypeImpl, HTMLDocumentImpl, XMLDocument

public class DocumentImpl
extends NodeImpl
implements DocumentProxy

Implements an XML document, and also derived to implement an HTML document. Provides access to the top level element in the document (getDocumentElement()), to the DTD if one exists (getDoctype(), and to all node operations.

Several methods create new nodes of all basic types (comment, text, element, etc.). These methods create new nodes but do not place them in the document tree. The nodes may be placed in the document tree using Node.appendChild(org.w3c.dom.Node) or Node.insertBefore(org.w3c.dom.Node, org.w3c.dom.Node), or they may be placed in some other document tree.

Notes:

  1. Node type is Node.DOCUMENT_NODE
  2. Node supports childern
  3. Node name is always "#document"
  4. Node does not have a value
  5. Node may not be added to other nodes
This class contains some extensions beyond the DOM API definition. For a list of all extensions, see org.openxml.XMLDocument.

Version:
$Revision: 1.2 $ $Date: 2002/07/21 19:02:02 $
Author:
Assaf Arkin
See Also:
Document, NodeImpl, DOMImplementation, Serialized Form

Field Summary
 
Fields inherited from class org.ozoneDB.xml.dom.NodeImpl
ATTLIST_DECL_NODE, ELEMENT_DECL_NODE, PARAM_ENTITY_NODE
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
  DocumentImpl()
           
protected DocumentImpl(java.lang.String rootElement)
           
 
Method Summary
 void acquire(long lockTimeout)
          Called to acquire access to a possible locked resource.
 void assignDoctype(DocumentTypeProxy docType)
           
 void clearDocument()
          Deletes all child Nodes from this Document to provide a fresh and empty Document.
 java.lang.Object clone()
           
 void cloneInto(NodeProxy into, boolean deep)
          This clone method is called after a new node has been constructed to copy the contents of this node into the new one.
 org.w3c.dom.Node cloneNode(boolean deep)
           
 org.w3c.dom.Attr createAttribute(java.lang.String name)
           
 org.w3c.dom.Attr createAttribute(java.lang.String name, java.lang.String defValue)
          Creates an attribute with the default value specified in the DTD.
 org.w3c.dom.Attr createAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
           
 org.w3c.dom.CDATASection createCDATASection(java.lang.String data)
           
 org.w3c.dom.Comment createComment(java.lang.String data)
           
 org.w3c.dom.Document createDocument(java.lang.String namespaceURI, java.lang.String qualifiedName, org.w3c.dom.DocumentType doctype)
           
 org.w3c.dom.DocumentFragment createDocumentFragment()
           
 org.w3c.dom.DocumentType createDocumentType(java.lang.String qualifiedName, java.lang.String publicId, java.lang.String systemId)
           
 org.w3c.dom.Element createElement(java.lang.String tagName)
           
 org.w3c.dom.Element createElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
           
 org.w3c.dom.EntityReference createEntityReference(java.lang.String name)
           
 org.w3c.dom.ProcessingInstruction createProcessingInstruction(java.lang.String target, java.lang.String data)
           
 org.w3c.dom.Text createTextNode(java.lang.String data)
           
 boolean equals(java.lang.Object other)
           
 XMLContainerHelper getContainer()
          Get the container of this document.
 org.w3c.dom.DocumentType getDoctype()
           
 org.w3c.dom.Element getDocumentElement()
           
 org.w3c.dom.Element getElementById(java.lang.String elementId)
           
 org.w3c.dom.NodeList getElementsByTagName(java.lang.String tagName)
          Creates a document type with the specified name (the name follows the !DOCTYPE entity) and associates it with the document.
 org.w3c.dom.NodeList getElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)
           
 org.w3c.dom.DOMImplementation getImplementation()
           
 short getNodeType()
          Abstract method must be implemented by each node class.
 boolean hasFeature(java.lang.String feature, java.lang.String version)
          Return true if certain feature for specific DOM version supported by this implementation.
 org.w3c.dom.Node importNode(org.w3c.dom.Node importedNode, boolean deep)
           
 void lock()
          Obtains a lock, preventing other threads from gaining access to the locked resource.
 void onDelete()
           
 void readExternal(java.io.ObjectInput in)
           
 void registerElement(java.lang.String tagName, java.lang.Class elementClass)
          Register an application-defined element type.
 void setContainer(XMLContainerHelper _container)
          Set the container of this document.
 void setDoctype(org.w3c.dom.DocumentType docType)
           
 void setElementTypes(java.util.Hashtable elementTypes)
           
 void setNodeValue(java.lang.String value)
          Changes the value of the node.
protected  boolean supportsChildern()
           
 java.lang.String toString()
           
 void unlock()
          Releases a lock, so other thread may gain access to the resource.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class org.ozoneDB.xml.dom.NodeImpl
appendChild, castNewChild, castOldChild, getAttributes, getChild, getChildCount, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, init, insertBefore, isReadOnly, isSupported, normalize, notifyIterators, removeChild, replaceChild, setNextSibling, setNodeName, setOwnerDocument, setParentNode, setPrefix, setPreviousSibling, setReadOnly, supports
 
Methods inherited from class org.ozoneDB.OzoneObject
container, database, deleteRecursive, getObjectID, handle, hashCode, onCreate, self, setContainer, toXML
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ozoneDB.OzoneCompatibleOrProxy
getObjectID
 
Methods inherited from interface org.w3c.dom.Node
appendChild, getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, insertBefore, isSupported, normalize, removeChild, replaceChild, setPrefix
 
Methods inherited from interface org.ozoneDB.xml.dom.NodeProxy
getChild, getChildCount, getChildNodes, init, isReadOnly, setNextSibling, setNodeName, setOwnerDocument, setParentNode, setPreviousSibling, setReadOnly
 

Constructor Detail

DocumentImpl

public DocumentImpl()

DocumentImpl

protected DocumentImpl(java.lang.String rootElement)
Method Detail

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Overrides:
writeExternal in class NodeImpl
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Overrides:
readExternal in class NodeImpl
java.io.IOException
java.lang.ClassNotFoundException

setContainer

public void setContainer(XMLContainerHelper _container)
Set the container of this document. This is needed to find the container that is responsible for a given Node.

Specified by:
setContainer in interface DocumentProxy

getContainer

public XMLContainerHelper getContainer()
Get the container of this document. This is needed to find the container that is responsible for a given Node.

Specified by:
getContainer in interface DocumentProxy

importNode

public org.w3c.dom.Node importNode(org.w3c.dom.Node importedNode,
                                   boolean deep)
                            throws org.w3c.dom.DOMException
Specified by:
importNode in interface org.w3c.dom.Document
org.w3c.dom.DOMException

createElementNS

public org.w3c.dom.Element createElementNS(java.lang.String namespaceURI,
                                           java.lang.String qualifiedName)
                                    throws org.w3c.dom.DOMException
Specified by:
createElementNS in interface org.w3c.dom.Document
org.w3c.dom.DOMException

createAttributeNS

public org.w3c.dom.Attr createAttributeNS(java.lang.String namespaceURI,
                                          java.lang.String qualifiedName)
                                   throws org.w3c.dom.DOMException
Specified by:
createAttributeNS in interface org.w3c.dom.Document
org.w3c.dom.DOMException

getElementsByTagNameNS

public org.w3c.dom.NodeList getElementsByTagNameNS(java.lang.String namespaceURI,
                                                   java.lang.String localName)
Specified by:
getElementsByTagNameNS in interface org.w3c.dom.Document

getElementById

public org.w3c.dom.Element getElementById(java.lang.String elementId)
Specified by:
getElementById in interface org.w3c.dom.Document

createDocument

public org.w3c.dom.Document createDocument(java.lang.String namespaceURI,
                                           java.lang.String qualifiedName,
                                           org.w3c.dom.DocumentType doctype)
                                    throws org.w3c.dom.DOMException
Specified by:
createDocument in interface org.w3c.dom.DOMImplementation
org.w3c.dom.DOMException

createDocumentType

public org.w3c.dom.DocumentType createDocumentType(java.lang.String qualifiedName,
                                                   java.lang.String publicId,
                                                   java.lang.String systemId)
                                            throws org.w3c.dom.DOMException
Specified by:
createDocumentType in interface org.w3c.dom.DOMImplementation
org.w3c.dom.DOMException

getNodeType

public short getNodeType()
Description copied from class: NodeImpl
Abstract method must be implemented by each node class.

Specified by:
getNodeType in interface org.w3c.dom.Node
Specified by:
getNodeType in class NodeImpl
See Also:
Node.getNodeType()

setNodeValue

public final void setNodeValue(java.lang.String value)
Description copied from class: NodeImpl
Changes the value of the node. Not all node types support the notion of a value. If the value is not supported by a particular node type, it will throw an exception when calling this method. The following table specifies which node types support values:
 Element                  Not supported
 Attr                     Value supported
 Text                     Value supported
 CDATASection             Value supported
 EntityReference          Not supported
 Entity                   Not supported
 ProcessingInstruction    Value supported
 Comment                  Value supported
 Document                 Not supported
 DocumentType             Not supported
 DocumentFragment         Not supported
 Notation                 Not supported
 
For most node types, if the value is set to null, NodeImpl.getNodeValue() will return an empty string instead.

Specified by:
setNodeValue in interface org.w3c.dom.Node
Overrides:
setNodeValue in class NodeImpl
Parameters:
value - New value of node

getDoctype

public final org.w3c.dom.DocumentType getDoctype()
Specified by:
getDoctype in interface org.w3c.dom.Document

setDoctype

public final void setDoctype(org.w3c.dom.DocumentType docType)
Specified by:
setDoctype in interface DocumentProxy

getImplementation

public final org.w3c.dom.DOMImplementation getImplementation()
Specified by:
getImplementation in interface org.w3c.dom.Document

getDocumentElement

public org.w3c.dom.Element getDocumentElement()
Specified by:
getDocumentElement in interface org.w3c.dom.Document

setElementTypes

public void setElementTypes(java.util.Hashtable elementTypes)
Specified by:
setElementTypes in interface DocumentProxy

createElement

public org.w3c.dom.Element createElement(java.lang.String tagName)
                                  throws org.w3c.dom.DOMException
Specified by:
createElement in interface org.w3c.dom.Document
org.w3c.dom.DOMException

createDocumentFragment

public final org.w3c.dom.DocumentFragment createDocumentFragment()
Specified by:
createDocumentFragment in interface org.w3c.dom.Document

createTextNode

public final org.w3c.dom.Text createTextNode(java.lang.String data)
Specified by:
createTextNode in interface org.w3c.dom.Document

createComment

public final org.w3c.dom.Comment createComment(java.lang.String data)
Specified by:
createComment in interface org.w3c.dom.Document

createCDATASection

public final org.w3c.dom.CDATASection createCDATASection(java.lang.String data)
                                                  throws org.w3c.dom.DOMException
Specified by:
createCDATASection in interface org.w3c.dom.Document
org.w3c.dom.DOMException

createProcessingInstruction

public final org.w3c.dom.ProcessingInstruction createProcessingInstruction(java.lang.String target,
                                                                           java.lang.String data)
                                                                    throws org.w3c.dom.DOMException
Specified by:
createProcessingInstruction in interface org.w3c.dom.Document
org.w3c.dom.DOMException

createAttribute

public final org.w3c.dom.Attr createAttribute(java.lang.String name)
                                       throws org.w3c.dom.DOMException
Specified by:
createAttribute in interface org.w3c.dom.Document
org.w3c.dom.DOMException

createAttribute

public final org.w3c.dom.Attr createAttribute(java.lang.String name,
                                              java.lang.String defValue)
                                       throws org.w3c.dom.DOMException
Creates an attribute with the default value specified in the DTD. This method is not defined in the DOM but is used by the parser.

Parameters:
name - The name of the attribute
defValue - The default value of the attribute
org.w3c.dom.DOMException

createEntityReference

public final org.w3c.dom.EntityReference createEntityReference(java.lang.String name)
                                                        throws org.w3c.dom.DOMException
Specified by:
createEntityReference in interface org.w3c.dom.Document
org.w3c.dom.DOMException

getElementsByTagName

public final org.w3c.dom.NodeList getElementsByTagName(java.lang.String tagName)
Creates a document type with the specified name (the name follows the !DOCTYPE entity) and associates it with the document. If the document is HTML or already has a DTD associated with it, throws an exception. This method is not defined in the DOM but is used by the parser.

Specified by:
getElementsByTagName in interface org.w3c.dom.Document
Throws:
org.w3c.dom.DOMException - NOT_SUPPORTED_ERR Document is HTML or already has a DTD

hasFeature

public boolean hasFeature(java.lang.String feature,
                          java.lang.String version)
Return true if certain feature for specific DOM version supported by this implementation.

Specified by:
hasFeature in interface org.w3c.dom.DOMImplementation
Parameters:
feature - Name of feature to check
version - Optional version number
Returns:
True if supported

registerElement

public void registerElement(java.lang.String tagName,
                            java.lang.Class elementClass)
Register an application-defined element type. The element's tag name and class are specified. When a so named element is created with createElement(java.lang.String), an object of the specified class is created and returned. This allows applications to define classes for specific element types.

Parameters:
tagName - The name of the element tag
elementClass - Class derived from org.openxml.XMLElement, used to construct the element

assignDoctype

public void assignDoctype(DocumentTypeProxy docType)

lock

public void lock()
          throws java.lang.RuntimeException
Obtains a lock, preventing other threads from gaining access to the locked resource. The lock is retained across multiple calls, until unlock() is called. Attempts to call acquire(long) from another thread will be blocked.

If the resource is already locked by another thread, the method will block until the lock is released or until the block has timedout.

lock() may be called any number of times, and unlock() must be called that number of times to release the lock.

java.lang.RuntimeException
See Also:
unlock()

unlock

public void unlock()
Releases a lock, so other thread may gain access to the resource. unlock() must be called as many times as lock() was called to release the lock. unlock() may be called an additional number of times, if so required by the implementation (e.g. to assure that a lock is released at the end of a thread).

See Also:
lock()

acquire

public void acquire(long lockTimeout)
             throws java.lang.RuntimeException
Called to acquire access to a possible locked resource. If the resource was locked by the current thread, the method will return immediately. If the resource was locked by some other thread, the method will block until the resource is unlocked, or the block has timed out.

java.lang.RuntimeException
See Also:
lock(), unlock()

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

cloneNode

public org.w3c.dom.Node cloneNode(boolean deep)
Specified by:
cloneNode in interface org.w3c.dom.Node

toString

public java.lang.String toString()
Overrides:
toString in class org.ozoneDB.OzoneObject

cloneInto

public void cloneInto(NodeProxy into,
                      boolean deep)
Description copied from class: NodeImpl
This clone method is called after a new node has been constructed to copy the contents of this node into the new one. It clones in contents but not in context, and guarantees that the cloned node will pass the equality test (see Object.equals(java.lang.Object)).

into must be a valid node of the exact same class as this one. deep is true if deep cloning (includes all children nodes) is to be performed. If deep is false, the clone might not pass the equality test.

Derived classes override and call this method to add per-class variable copying. This method is called by Node.cloneNode(boolean) and the default Object.clone() method.

Contents cloning duplicates the node's name and value, and its children. It does not duplicate it's context, that is, the node's parent or sibling. Initially a clone node has no parents or siblings. However, the node does belong to the same document, since all nodes must belong to some document. The cloned node is never read-only.

Specified by:
cloneInto in interface NodeProxy
Overrides:
cloneInto in class NodeImpl
Parameters:
into - A node into which to duplicate this one
deep - True if deep cloning is required

supportsChildern

protected final boolean supportsChildern()
Overrides:
supportsChildern in class NodeImpl

onDelete

public void onDelete()
              throws java.lang.Exception
Specified by:
onDelete in interface org.ozoneDB.OzoneCompatible
Overrides:
onDelete in class org.ozoneDB.OzoneObject
java.lang.Exception

clearDocument

public void clearDocument()
                   throws java.lang.Exception
Deletes all child Nodes from this Document to provide a fresh and empty Document. Attention: This methods permanently removes the existing content!

Specified by:
clearDocument in interface DocumentProxy
java.lang.Exception


Copyright © 2002 The Ozone Database Project - www.ozone-db.org. All Rights Reserved.