Class AbstractItem

java.lang.Object
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 overridden to provide a local name.
Item.setName
Override 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
Override it if it allows to change the text. Default: throws an exception.
Node.getNodeType
It must be overridden 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:
  • Constructor Details

    • AbstractItem

      protected AbstractItem()
      Constructor.
  • Method Details

    • 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.
    • 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:
    • 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 concatenation 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
    • 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