org.zkoss.idom.impl
Class AbstractItem

java.lang.Object
  extended by org.zkoss.idom.impl.AbstractItem
All Implemented Interfaces:
Serializable, Cloneable, Node, Item
Direct Known Subclasses:
AbstractGroup, AbstractTextual, Attribute, DocType, ProcessingInstruction

public abstract class AbstractItem
extends Object
implements Item, Node, Serializable, Cloneable

A semi-implemented item for leaf vertices. A leaf item is a item without any children. For cores having child cores, use Group.

Important methods that the deriving might want to override.

Item.getName
It must be overrided to provide a local name.
Item.setName
Overrid it if it allows to change the name. Default: throws an exception.
Item.getText
Override it if it has a text representation. Default: returns null.
Item.setText
Overrid it if it allows to change the text. Default: throws an exception.
Node.getNodeType
It must be overrided to provide the type.
Item.clone
Override it if any other members to handle specially. Note: by definition, we do deep clone only.
Object.toString
Override if you want a representation other than XMLOutputter does.

Author:
tomyeh
See Also:
Item, Serialized Form

Field Summary
 
Fields inherited from interface org.zkoss.idom.Item
FIND_BY_PREFIX, FIND_BY_REGEX, FIND_BY_TAGNAME, FIND_IGNORE_CASE, FIND_RECURSIVE
 
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
protected AbstractItem()
          Constructor.
 
Method Summary
 Node appendChild(Node newChild)
           
 void clearModified(boolean includingDescendant)
          Deprecated. As of release 5.0.8, it does nothing.
 Object clone()
          Clones this object (a deep cloning not including contents contained in Textual nodes).
 Item clone(boolean reserved)
          Deprecated. As of release 5.0.8, replaced with clone().
 Node cloneNode(boolean deep)
           
 short compareDocumentPosition(Node other)
           
 Item detach()
          Detach this item from its parent.
 boolean equals(Object o)
          Overriding this method is prohibited.
 NamedNodeMap getAttributes()
           
 String getBaseURI()
           
 NodeList getChildNodes()
           
 Document getDocument()
          Gets the document that owns this item.
 Object getFeature(String feature, String version)
           
 Node getFirstChild()
           
 Node getLastChild()
           
 String getLocalName()
           
 Locator getLocator()
          Gets the locator of this item.
 String getNamespaceURI()
           
 Node getNextSibling()
           
 String getNodeName()
           
 String getNodeValue()
           
 Document getOwnerDocument()
           
 Group getParent()
          Gets the parent item.
 Node getParentNode()
           
 String getPrefix()
           
 Node getPreviousSibling()
           
 String getText()
          Gets the text of this item, or null if it is neither Textual nor Element.
 String getTextContent()
           
 Object getUserData(String key)
           
 boolean hasAttributes()
           
 boolean hasChildNodes()
           
 int hashCode()
          Overriding this method is prohibited.
 Node insertBefore(Node newChild, Node refChild)
           
 boolean isDefaultNamespace(String namespaceURI)
           
 boolean isEqualNode(Node arg)
           
 boolean isModified()
          Deprecated. As of release 5.0.8, it always returns false.
 boolean isReadonly()
          Deprecated. As of release 5.0.8, it always returns false.
 boolean isSameNode(Node other)
           
 boolean isSupported(String feature, String version)
           
 String lookupNamespaceURI(String prefix)
           
 String lookupPrefix(String namespaceURI)
           
protected static boolean match(Namespaceable vtx, String namespace, String name, Pattern ptn, int mode)
          Tests whether a namespaceable item matches the criteria.
 void normalize()
           
 Node removeChild(Node oldChild)
           
 Node replaceChild(Node newChild, Node oldChild)
           
 void setLocator(Locator loc)
          Sets the locator of this item.
 void setModified()
          Deprecated. As of release 5.0.8, it does nothing.
 void setName(String name)
          Sets the name of the item.
 void setNodeValue(String nodeValue)
           
 void setParent(Group parent)
          Sets the parent item.
 void setPrefix(String prefix)
           
 void setReadonly(boolean readonly)
          Deprecated. As of release 5.0.8, it does nothing.
 void setText(String text)
          Sets the text of this item.
 void setTextContent(String textContent)
           
 Object setUserData(String key, Object data, UserDataHandler handler)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.zkoss.idom.Item
getName
 
Methods inherited from interface org.w3c.dom.Node
getNodeType
 

Constructor Detail

AbstractItem

protected AbstractItem()
Constructor.

Method Detail

match

protected static boolean match(Namespaceable vtx,
                               String namespace,
                               String name,
                               Pattern ptn,
                               int mode)
Tests whether a namespaceable item matches the criteria. If mode don't contain FIND_BY_REGEX, ptn is ignored.


isReadonly

public boolean isReadonly()
Deprecated. As of release 5.0.8, it always returns false.

Specified by:
isReadonly in interface Item

setReadonly

public void setReadonly(boolean readonly)
Deprecated. As of release 5.0.8, it does nothing.

Specified by:
setReadonly in interface Item

isModified

public boolean isModified()
Deprecated. As of release 5.0.8, it always returns false.

Specified by:
isModified in interface Item

clearModified

public void clearModified(boolean includingDescendant)
Deprecated. As of release 5.0.8, it does nothing.

Specified by:
clearModified in interface Item

setModified

public void setModified()
Deprecated. As of release 5.0.8, it does nothing.

Specified by:
setModified in interface Item

setName

public void setName(String name)
Description copied from interface: Item
Sets the name of the item. For vertices that support namespace (implements Namespaceable), it is the same as setTagName.

Specified by:
setName in interface Item
See Also:
Namespaceable.setTagName(java.lang.String)

getText

public String getText()
Description copied from interface: Item
Gets the text of this item, or null if it is neither Textual nor Element. For Element, the text is the catenation of all its textual children, including Text, CDATA, and Binary.

Besides String-type value, some item, e.g., Binary, allows any type of objects. Caller could test whether a item implements the Binable interface, and use Binable.getValue instead. For binable vertices, getText is actually getValue().toString().

The returned value is neither trimmed nor normalized.

Specified by:
getText in interface Item

setText

public void setText(String text)
Description copied from interface: Item
Sets the text of this item.

Specified by:
setText in interface Item

getDocument

public Document getDocument()
Description copied from interface: Item
Gets the document that owns this item. The owning document is the first document in its ancestor. For DOM, the document can only be the root, so the owning documents of vertices in a DOM tree are all the same.

Specified by:
getDocument in interface Item

detach

public Item detach()
Description copied from interface: Item
Detach this item from its parent.

Because each item can belong to at most one parent at a time, it is important to detach it first, before added to another tree -- even if it is the same tree/parent.

It has the similar effect as:
getParent().getChildren().remove(this).

Naming reason: we don't call this method as getChildren() to be compatible with the naming style of Attributable.attributes -- which is limited to org.w3c.dom.Attr.getAttributes. Also, it doesn't have the setter and it is "live", so it 'seem' better to call it getChildren().

Specified by:
detach in interface Item
Returns:
this item

clone

public Item clone(boolean reserved)
Deprecated. As of release 5.0.8, replaced with clone().

Specified by:
clone in interface Item

getParent

public final Group getParent()
Description copied from interface: Item
Gets the parent item.

Specified by:
getParent in interface Item

setParent

public void setParent(Group parent)
Description copied from interface: Item
Sets the parent item.

DO NOT call this method. It is used internally. Instead, use detach or thru getChildren().

Specified by:
setParent in interface Item

getLocator

public final Locator getLocator()
Description copied from interface: Item
Gets the locator of this item.

Specified by:
getLocator in interface Item
Returns:
the locator; null if not available (default)

setLocator

public final void setLocator(Locator loc)
Description copied from interface: Item
Sets the locator of this item.

Unlike other methods, it won't change the modification flag.

Specified by:
setLocator in interface Item
Parameters:
loc - the locator; null if not available

getNodeName

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

getNodeValue

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

setNodeValue

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

getOwnerDocument

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

cloneNode

public final Node cloneNode(boolean deep)
Specified by:
cloneNode in interface Node

getParentNode

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

getPreviousSibling

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

getNextSibling

public final Node getNextSibling()
Specified by:
getNextSibling 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

hasChildNodes

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

insertBefore

public Node insertBefore(Node newChild,
                         Node refChild)
Specified by:
insertBefore in interface Node

replaceChild

public Node replaceChild(Node newChild,
                         Node oldChild)
Specified by:
replaceChild in interface Node

removeChild

public Node removeChild(Node oldChild)
Specified by:
removeChild in interface Node

appendChild

public Node appendChild(Node newChild)
Specified by:
appendChild in interface Node

normalize

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

isSupported

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

getLocalName

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

setPrefix

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

getAttributes

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

hasAttributes

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

getBaseURI

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

compareDocumentPosition

public short compareDocumentPosition(Node other)
                              throws DOMException
Specified by:
compareDocumentPosition in interface Node
Throws:
DOMException

getTextContent

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

setTextContent

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

isSameNode

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

lookupPrefix

public String lookupPrefix(String namespaceURI)
Specified by:
lookupPrefix in interface Node

isDefaultNamespace

public boolean isDefaultNamespace(String namespaceURI)
Specified by:
isDefaultNamespace in interface Node

lookupNamespaceURI

public String lookupNamespaceURI(String prefix)
Specified by:
lookupNamespaceURI in interface Node

isEqualNode

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

getFeature

public Object getFeature(String feature,
                         String version)
Specified by:
getFeature in interface Node

setUserData

public Object setUserData(String key,
                          Object data,
                          UserDataHandler handler)
Specified by:
setUserData in interface Node

getUserData

public Object getUserData(String key)
Specified by:
getUserData in interface Node

equals

public final boolean equals(Object o)
Overriding this method is prohibited.

Overrides:
equals in class Object

hashCode

public final int hashCode()
Overriding this method is prohibited.

Overrides:
hashCode in class Object

clone

public Object clone()
Clones this object (a deep cloning not including contents contained in Textual nodes). Note: after cloning, the read-only flag always becomes false, and the parent becomes null (i.e., detached).

Specified by:
clone in interface Item
Overrides:
clone in class Object


Copyright © 2012. All Rights Reserved.