org.ozoneDB.xml.dom
Class ElementImpl

java.lang.Object
  extended byorg.ozoneDB.OzoneObject
      extended byorg.ozoneDB.xml.dom.NodeImpl
          extended byorg.ozoneDB.xml.dom.ElementImpl
All Implemented Interfaces:
org.w3c.dom.Element, ElementProxy, java.io.Externalizable, org.w3c.dom.NamedNodeMap, NamedNodeMapProxy, org.w3c.dom.Node, NodeProxy, org.ozoneDB.OzoneCompatible, org.ozoneDB.OzoneCompatibleOrProxy, org.ozoneDB.OzoneRemote, java.io.Serializable
Direct Known Subclasses:
HTMLElementImpl, XMLElement

public class ElementImpl
extends NodeImpl
implements ElementProxy, java.io.Externalizable

The most common node type, Element inherits the generic Node interface and adds support for retrieving and setting attributes either as nodes or as strings.

Notes:

  1. Node type is Node.ELEMENT_NODE
  2. Node supports childern
  3. Node has no value
  4. Node has attributes

To speed up implementation, all attributes are implemented as double-linked list implemented using NodeImpl#_parent, NodeImpl#_nextNode and NodeImpl#_prevNode. This support is provided to through getNamedAttr(java.lang.String), appendAttr(org.ozoneDB.xml.dom.AttrProxy) and removeAttr(org.ozoneDB.xml.dom.AttrProxy) methods.

Version:
$Revision: 1.2 $ $Date: 2003/11/20 23:18:42 $
Author:
Assaf Arkin
See Also:
Element, Attr, NamedNodeMap, AttrImpl, 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
ElementImpl()
           
ElementImpl(DocumentImpl owner, java.lang.String name)
          Constructor requires only owner document and tag name of element.
 
Method Summary
 AttrProxy appendAttr(AttrProxy newAttr)
          Append newAttr as the last attribute of this element.
 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)
           
 java.util.Enumeration elements()
           
 boolean equals(java.lang.Object other)
           
 java.lang.String getAttribute(java.lang.String name)
           
 org.w3c.dom.Attr getAttributeNode(java.lang.String name)
           
 org.w3c.dom.Attr getAttributeNodeNS(java.lang.String namespaceURI, java.lang.String localName)
           
 java.lang.String getAttributeNS(java.lang.String namespaceURI, java.lang.String localName)
           
 org.w3c.dom.NamedNodeMap getAttributes()
          Return attributes of node.
 org.w3c.dom.NodeList getElementsByTagName(java.lang.String tagName)
          Returns a list of elements extracted based on their tag name (or all of them if the tag name is "*").
 org.w3c.dom.NodeList getElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)
           
 int getLength()
           
 org.w3c.dom.Attr getNamedAttr(java.lang.String name)
          Returns the named attribute or null if attribute not found.
 org.w3c.dom.Node getNamedItem(java.lang.String name)
           
 org.w3c.dom.Node getNamedItemNS(java.lang.String namespaceURI, java.lang.String localName)
           
 short getNodeType()
          Abstract method must be implemented by each node class.
 java.lang.String getTagName()
          Returns the name of the tag, same as calling NodeImpl.getNodeName().
 boolean hasAttribute(java.lang.String name)
           
 boolean hasAttributeNS(java.lang.String namespaceURI, java.lang.String localname)
           
 boolean hasAttributes()
           
 void init(NodeProxy owner, java.util.Dictionary dictionary)
           
 org.w3c.dom.Node item(int index)
           
 void normalize()
           
 void onDelete()
           
 void readExternal(java.io.ObjectInput in)
           
 AttrProxy removeAttr(AttrProxy oldAttr)
          Remove oldAttr from this element.
 void removeAttribute(java.lang.String name)
           
 org.w3c.dom.Attr removeAttributeNode(org.w3c.dom.Attr oldAttr)
           
 void removeAttributeNS(java.lang.String namespaceURI, java.lang.String localName)
           
 org.w3c.dom.Node removeNamedItem(java.lang.String name)
           
 org.w3c.dom.Node removeNamedItemNS(java.lang.String namespaceURI, java.lang.String localName)
           
 void setAttrCount(int count)
           
 void setAttribute(java.lang.String name, java.lang.String value)
           
 org.w3c.dom.Attr setAttributeNode(org.w3c.dom.Attr newAttr)
           
 org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr newAttr)
           
 void setAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName, java.lang.String value)
           
 void setFirstAttr(org.w3c.dom.Attr attribute)
           
 void setLastAttr(org.w3c.dom.Attr attribute)
           
 org.w3c.dom.Node setNamedItem(org.w3c.dom.Node arg)
           
 org.w3c.dom.Node setNamedItemNS(org.w3c.dom.Node arg)
           
 void setNodeValue(java.lang.String value)
          Changes the value of the node.
protected  boolean supportsChildern()
           
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class org.ozoneDB.xml.dom.NodeImpl
appendChild, castNewChild, castOldChild, getChild, getChildCount, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasChildNodes, init, insertBefore, isReadOnly, isSupported, notifyIterators, removeChild, replaceChild, setNextSibling, setNodeName, setOwnerDocument, setParentNode, setPrefix, setPreviousSibling, setReadOnly, supports
 
Methods inherited from class org.ozoneDB.OzoneObject
container, database, deleteRecursive, getHandle, getObjectID, handle, hashCode, onActivate, onCreate, onPassivate, requireWriteLocking, 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, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasChildNodes, insertBefore, isSupported, 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

ElementImpl

public ElementImpl(DocumentImpl owner,
                   java.lang.String name)
Constructor requires only owner document and tag name of element. Tag name is case sensitive for XML, but converted to upper case for HTML documents.

Parameters:
owner - Owner document of this element
name - The tag name of the element

ElementImpl

public ElementImpl()
Method Detail

getNamedItemNS

public org.w3c.dom.Node getNamedItemNS(java.lang.String namespaceURI,
                                       java.lang.String localName)
Specified by:
getNamedItemNS in interface org.w3c.dom.NamedNodeMap

setNamedItemNS

public org.w3c.dom.Node setNamedItemNS(org.w3c.dom.Node arg)
                                throws org.w3c.dom.DOMException
Specified by:
setNamedItemNS in interface org.w3c.dom.NamedNodeMap
Throws:
org.w3c.dom.DOMException

removeNamedItemNS

public org.w3c.dom.Node removeNamedItemNS(java.lang.String namespaceURI,
                                          java.lang.String localName)
                                   throws org.w3c.dom.DOMException
Specified by:
removeNamedItemNS in interface org.w3c.dom.NamedNodeMap
Throws:
org.w3c.dom.DOMException

getAttributeNodeNS

public org.w3c.dom.Attr getAttributeNodeNS(java.lang.String namespaceURI,
                                           java.lang.String localName)
Specified by:
getAttributeNodeNS in interface org.w3c.dom.Element

setAttributeNodeNS

public org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr newAttr)
                                    throws org.w3c.dom.DOMException
Specified by:
setAttributeNodeNS in interface org.w3c.dom.Element
Throws:
org.w3c.dom.DOMException

getAttributeNS

public java.lang.String getAttributeNS(java.lang.String namespaceURI,
                                       java.lang.String localName)
Specified by:
getAttributeNS in interface org.w3c.dom.Element

setAttributeNS

public void setAttributeNS(java.lang.String namespaceURI,
                           java.lang.String qualifiedName,
                           java.lang.String value)
                    throws org.w3c.dom.DOMException
Specified by:
setAttributeNS in interface org.w3c.dom.Element
Throws:
org.w3c.dom.DOMException

removeAttributeNS

public void removeAttributeNS(java.lang.String namespaceURI,
                              java.lang.String localName)
                       throws org.w3c.dom.DOMException
Specified by:
removeAttributeNS in interface org.w3c.dom.Element
Throws:
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.Element

hasAttributes

public boolean hasAttributes()
Specified by:
hasAttributes in interface org.w3c.dom.Node
Overrides:
hasAttributes in class NodeImpl

hasAttribute

public boolean hasAttribute(java.lang.String name)
Specified by:
hasAttribute in interface org.w3c.dom.Element

hasAttributeNS

public boolean hasAttributeNS(java.lang.String namespaceURI,
                              java.lang.String localname)
Specified by:
hasAttributeNS in interface org.w3c.dom.Element

getNodeType

public final 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()

elements

public final java.util.Enumeration elements()
Specified by:
elements in interface NamedNodeMapProxy

setFirstAttr

public void setFirstAttr(org.w3c.dom.Attr attribute)
Specified by:
setFirstAttr in interface ElementProxy

setLastAttr

public void setLastAttr(org.w3c.dom.Attr attribute)
Specified by:
setLastAttr in interface ElementProxy

setAttrCount

public void setAttrCount(int count)
Specified by:
setAttrCount in interface ElementProxy

getTagName

public final java.lang.String getTagName()
Returns the name of the tag, same as calling NodeImpl.getNodeName(). In XML documents, the return value preserves case. In HTML documents, the return value is always upper case regardless of the original value.

Specified by:
getTagName in interface org.w3c.dom.Element
Returns:
Tag name

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

getElementsByTagName

public final org.w3c.dom.NodeList getElementsByTagName(java.lang.String tagName)
Returns a list of elements extracted based on their tag name (or all of them if the tag name is "*"). The returned list is a snapshot of the element's contents at the time of calling. Subsequent updates to the element are not reflected in the list. This might result in inaccuracies when working from multiple threads.

Specified by:
getElementsByTagName in interface org.w3c.dom.Element
Parameters:
tagName - The element tag name to look for or "*" for all elements
Returns:
A snapshot of the named elements contained within this element

normalize

public final void normalize()
Specified by:
normalize in interface org.w3c.dom.Node
Overrides:
normalize in class NodeImpl

getAttributes

public final org.w3c.dom.NamedNodeMap getAttributes()
Description copied from class: NodeImpl
Return attributes of node. Returns null unless node is of type Element, in which case the returned NamedNodeMap will provide access to all the element's attributes.

Specified by:
getAttributes in interface org.w3c.dom.Node
Overrides:
getAttributes in class NodeImpl
Returns:
Attributes of node or null

getAttribute

public final java.lang.String getAttribute(java.lang.String name)
Specified by:
getAttribute in interface org.w3c.dom.Element

setAttribute

public final void setAttribute(java.lang.String name,
                               java.lang.String value)
                        throws org.w3c.dom.DOMException
Specified by:
setAttribute in interface org.w3c.dom.Element
Throws:
org.w3c.dom.DOMException

removeAttribute

public final void removeAttribute(java.lang.String name)
Specified by:
removeAttribute in interface org.w3c.dom.Element

getAttributeNode

public final org.w3c.dom.Attr getAttributeNode(java.lang.String name)
Specified by:
getAttributeNode in interface org.w3c.dom.Element

setAttributeNode

public final org.w3c.dom.Attr setAttributeNode(org.w3c.dom.Attr newAttr)
                                        throws org.w3c.dom.DOMException
Specified by:
setAttributeNode in interface org.w3c.dom.Element
Throws:
org.w3c.dom.DOMException

removeAttributeNode

public final org.w3c.dom.Attr removeAttributeNode(org.w3c.dom.Attr oldAttr)
Specified by:
removeAttributeNode in interface org.w3c.dom.Element

getNamedItem

public final org.w3c.dom.Node getNamedItem(java.lang.String name)
Specified by:
getNamedItem in interface NamedNodeMapProxy

setNamedItem

public final org.w3c.dom.Node setNamedItem(org.w3c.dom.Node arg)
                                    throws org.w3c.dom.DOMException
Specified by:
setNamedItem in interface org.w3c.dom.NamedNodeMap
Throws:
org.w3c.dom.DOMException

removeNamedItem

public final org.w3c.dom.Node removeNamedItem(java.lang.String name)
                                       throws org.w3c.dom.DOMException
Specified by:
removeNamedItem in interface org.w3c.dom.NamedNodeMap
Throws:
org.w3c.dom.DOMException

item

public final org.w3c.dom.Node item(int index)
Specified by:
item in interface org.w3c.dom.NamedNodeMap

getLength

public int getLength()
Specified by:
getLength in interface ElementProxy

equals

public boolean equals(java.lang.Object other)

clone

public final java.lang.Object clone()

cloneNode

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

toString

public java.lang.String toString()

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 OzoneObject.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 boolean supportsChildern()
Returns:
True if childern supported by this node type

getNamedAttr

public final org.w3c.dom.Attr getNamedAttr(java.lang.String name)
Returns the named attribute or null if attribute not found.

Specified by:
getNamedAttr in interface ElementProxy
Parameters:
name - The name of the attribute to return
Returns:
The named attribute or null

appendAttr

public final AttrProxy appendAttr(AttrProxy newAttr)
Append newAttr as the last attribute of this element. If newAttr is not an attribute of this DOM, or is already in use by some element, an exception is thrown.

Specified by:
appendAttr in interface ElementProxy
Parameters:
newAttr - The new attribute to add
Returns:
The newly added attribute
Throws:
org.w3c.dom.DOMException - NO_MODIFICATION_ALLOWED_ERR Node is read-only and cannot be modified
org.w3c.dom.DOMException - WRONG_DOCUMENT_ERR newAttr is not an attribute in this DOM
org.w3c.dom.DOMException - INUSE_ATTRIBUTE_ERR newAttr is already in use by some other element

removeAttr

public final AttrProxy removeAttr(AttrProxy oldAttr)
                           throws org.w3c.dom.DOMException
Remove oldAttr from this element. If oldAttr is not an attribute of this element, an exception is thrown.

Parameters:
oldAttr - The attribute to remove
Returns:
The removed attribute
Throws:
org.w3c.dom.DOMException - NO_MODIFICATION_ALLOWED_ERR Node is read-only and cannot be modified
org.w3c.dom.DOMException - NOT_FOUND_ERR oldAttr is not an attribute of this element

init

public void init(NodeProxy owner,
                 java.util.Dictionary dictionary)
Specified by:
init in interface NamedNodeMapProxy

onDelete

public void onDelete()
Specified by:
onDelete in interface org.ozoneDB.OzoneCompatible

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
Throws:
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
Throws:
java.io.IOException
java.lang.ClassNotFoundException


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