Class Attribute

All Implemented Interfaces:
Serializable, Cloneable, Attr, Node, Item, Namespaceable

public class Attribute extends AbstractItem implements Namespaceable, Attr
The iDOM attribute.

Design decision: Attribute is also a item. The reason is it simplifies the use of XPath. An XPath might return either elements or attributes, so...

Author:
tomyeh
See Also:
  • Field Details

    • _ns

      protected Namespace _ns
      The namespace.
    • _owner

      protected Item _owner
      The owner item.
    • _lname

      protected String _lname
      The local name.
    • _value

      protected String _value
      The value.
  • Constructor Details

    • Attribute

      public Attribute(String nsURI, String tname, String value)
      Constructor.

      Note: According to W3/DOM, the namespace of attributes must have a prefix if the uri is not empty.

      Parameters:
      nsURI - the namespace URI
      tname - the tag name
    • Attribute

      public Attribute(Namespace ns, String lname, String value)
      Constructor.
      Parameters:
      ns - the namespace
      lname - the local name
    • Attribute

      public Attribute(String lname, String value)
      Constructor.
    • Attribute

      protected Attribute()
      Constructor.
  • Method Details

    • getValue

      public final String getValue()
      Gets the value of this attribute.
      Specified by:
      getValue in interface Attr
    • setValue

      public final void setValue(String value)
      Sets the value of this attribute. According to Section 3.3.3 of XML 1.0 spec, the value is always normalized. Whether to trim depends on whether an attribute is CDATA (default). In this version, we don't normalize or trim (i.e., consider it as CDATA).
      Specified by:
      setValue in interface Attr
      Parameters:
      value - the new value; null is considered as empty
    • getOwner

      public final Item getOwner()
      Gets the item that owns this attribute.
    • setOwner

      public final void setOwner(Item owner)
      Sets the item that owns this attribute.

      DO NOT call this method. It is used internally. For user's point of view, the owner item is maintained automatically, so user never needs to update it.

    • setNamespace

      public final void setNamespace(String prefix, String nsURI)
      Sets the namespace.
    • setNamespace

      public final void setNamespace(Namespace ns)
      Sets the namespace.

      According W3C/DOM, unlike element, an attribute doesn't allow a namespace that has an URI but without a prefix.

      Specified by:
      setNamespace in interface Namespaceable
    • getNamespace

      public final Namespace getNamespace()
      Description copied from interface: Namespaceable
      Gets the namespace.
      Specified by:
      getNamespace in interface Namespaceable
      Returns:
      the namespace; never null
    • getTagName

      public final String getTagName()
      Description copied from interface: Namespaceable
      Gets the tag name of this item. The tag name is also called the fully qualified name -- the name with the namespace prefix, e.g., prefix:name.

      To get the local name (the name without prefix), Namespaceable.getLocalName could be used.

      Specified by:
      getTagName in interface Namespaceable
    • setTagName

      public final void setTagName(String tname)
      Sets the tag name.

      Changing a name improperly might cause replicated attribute names which won't be detected by this method.

      Specified by:
      setTagName in interface Namespaceable
    • getLocalName

      public final String getLocalName()
      Description copied from interface: Namespaceable
      Gets the local name of this item. The local name is the name without prefix.

      To get the tag name (the name with prefix), Namespaceable.getTagName could be used.

      Specified by:
      getLocalName in interface Namespaceable
      Specified by:
      getLocalName in interface Node
      Overrides:
      getLocalName in class AbstractItem
    • setLocalName

      public final void setLocalName(String lname)
      Sets the local name of this attribute.

      Changing a name improperly might cause replicated attribute names which won't be detected by this method.

      Specified by:
      setLocalName in interface Namespaceable
    • getName

      public final String getName()
      Description copied from interface: Item
      Gets the name of the item. For vertices that support namespace (implements Namespaceable), it is the same as getTagName.
      Specified by:
      getName in interface Attr
      Specified by:
      getName in interface Item
      See Also:
    • setName

      public final void setName(String tname)
      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
      Overrides:
      setName in class AbstractItem
      See Also:
    • getText

      public final 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
      Overrides:
      getText in class AbstractItem
    • setText

      public final void setText(String text)
      Description copied from interface: Item
      Sets the text of this item.
      Specified by:
      setText in interface Item
      Overrides:
      setText in class AbstractItem
    • getDocument

      public final Document getDocument()
      Gets the document that owns this attribute.
      Specified by:
      getDocument in interface Item
      Overrides:
      getDocument in class AbstractItem
    • detach

      public Item detach()
      Detach the attribute from its owner, if any. Only attributes that belongs to no item or the same item are allowed to be added to a item. So, detach is useful to move an attribute out from a item (and then you might add it to another item).
      Specified by:
      detach in interface Item
      Overrides:
      detach in class AbstractItem
      Returns:
      this item
    • setParent

      public void setParent(Item parent)
    • getNodeType

      public final short getNodeType()
      Specified by:
      getNodeType in interface Node
    • getOwnerDocument

      public final Document getOwnerDocument()
      Specified by:
      getOwnerDocument in interface Node
      Overrides:
      getOwnerDocument in class AbstractItem
    • getNamespaceURI

      public final String getNamespaceURI()
      Specified by:
      getNamespaceURI in interface Node
      Overrides:
      getNamespaceURI in class AbstractItem
    • getPrefix

      public final String getPrefix()
      Specified by:
      getPrefix in interface Node
      Overrides:
      getPrefix in class AbstractItem
    • setPrefix

      public final void setPrefix(String prefix)
      Sets the namespace prefix of this attribute.

      Changing a prefix improperly might cause replicated attribute names which won't be detected by this method.

      Specified by:
      setPrefix in interface Node
      Overrides:
      setPrefix in class AbstractItem
    • getSchemaTypeInfo

      public TypeInfo getSchemaTypeInfo()
      Specified by:
      getSchemaTypeInfo in interface Attr
    • isId

      public boolean isId()
      Specified by:
      isId in interface Attr
    • getSpecified

      public final boolean getSpecified()
      Specified by:
      getSpecified in interface Attr
    • getOwnerElement

      public final Element getOwnerElement()
      Specified by:
      getOwnerElement in interface Attr
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • clone

      public Object clone()
      Description copied from class: AbstractItem
      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 AbstractItem