org.zkoss.idom
Class Attribute

java.lang.Object
  extended by org.zkoss.idom.impl.AbstractItem
      extended by org.zkoss.idom.Attribute
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, org.w3c.dom.Attr, org.w3c.dom.Node, Item, Namespaceable

public class Attribute
extends AbstractItem
implements Namespaceable, org.w3c.dom.Attr

The iDOM attribute.

Design decision: Attribute is also a item. The reason is it simplifies the use of xpath. A xpath migt return either elements or attributes, so...

Author:
tomyeh
See Also:
Element, Serialized Form

Field Summary
protected  java.lang.String _lname
          The local name.
protected  Namespace _ns
          The namespace.
protected  Item _owner
          The owner item.
protected  java.lang.String _value
          The value.
 
Fields inherited from class org.zkoss.idom.impl.AbstractItem
_modified
 
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
 
Fields inherited from interface org.zkoss.idom.Item
FIND_BY_PREFIX, FIND_BY_REGEX, FIND_BY_TAGNAME, FIND_IGNORE_CASE, FIND_RECURSIVE
 
Constructor Summary
protected Attribute()
          Constructor.
  Attribute(Namespace ns, java.lang.String lname, java.lang.String value)
          Constructor.
  Attribute(java.lang.String lname, java.lang.String value)
          Constructor.
  Attribute(java.lang.String nsURI, java.lang.String tname, java.lang.String value)
          Constructor.
 
Method Summary
 Item clone(boolean preserveModified)
          Clones this item.
 Item detach()
          Detach the attribute from its owner, if any.
 Document getDocument()
          Gets the document that owns this attribute.
 java.lang.String getLocalName()
          Gets the local name of this item.
 java.lang.String getName()
          Gets the name of the item.
 Namespace getNamespace()
          Gets the namespace.
 java.lang.String getNamespaceURI()
           
 short getNodeType()
           
 Item getOwner()
          Gets the item that owns this attribute.
 org.w3c.dom.Document getOwnerDocument()
           
 org.w3c.dom.Element getOwnerElement()
           
 java.lang.String getPrefix()
           
 org.w3c.dom.TypeInfo getSchemaTypeInfo()
           
 boolean getSpecified()
           
 java.lang.String getTagName()
          Gets the tag name of this item.
 java.lang.String getText()
          Gets the text of this item, or null if it is neither Textual nor Element.
 java.lang.String getValue()
          Gets the value of this attribute.
 boolean isId()
           
 boolean isReadonly()
          Tests whether this attribute is read-only.
 void setLocalName(java.lang.String lname)
          Sets the local name of this attribute.
 void setModified()
          Sets the modification flag.
 void setName(java.lang.String tname)
          Sets the name of the item.
 void setNamespace(Namespace ns)
          Sets the namespace.
 void setNamespace(java.lang.String prefix, java.lang.String nsURI)
          Sets the namespace.
 void setOwner(Item owner)
          Sets the item that owns this attribute.
 void setParent(Item parent)
           
 void setPrefix(java.lang.String prefix)
          Sets the namespace prefix of this attribute.
 void setTagName(java.lang.String tname)
          Sets the tag name.
 void setText(java.lang.String text)
          Sets the text of this item.
 void setValue(java.lang.String value)
          Sets the value of this attribute.
 java.lang.String toString()
           
 
Methods inherited from class org.zkoss.idom.impl.AbstractItem
appendChild, checkWritable, clearModified, clone, cloneNode, compareDocumentPosition, equals, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocator, getNextSibling, getNodeName, getNodeValue, getParent, getParentNode, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, hashCode, insertBefore, isDefaultNamespace, isEqualNode, isModified, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, match, normalize, removeChild, replaceChild, setLocator, setNodeValue, setParent, setReadonly, setTextContent, setUserData
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getNextSibling, getNodeName, getNodeValue, getParentNode, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setTextContent, setUserData
 

Field Detail

_ns

protected Namespace _ns
The namespace.


_owner

protected Item _owner
The owner item.


_lname

protected java.lang.String _lname
The local name.


_value

protected java.lang.String _value
The value.

Constructor Detail

Attribute

public Attribute(java.lang.String nsURI,
                 java.lang.String tname,
                 java.lang.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,
                 java.lang.String lname,
                 java.lang.String value)
Constructor.

Parameters:
ns - the namespace
lname - the local name

Attribute

public Attribute(java.lang.String lname,
                 java.lang.String value)
Constructor.


Attribute

protected Attribute()
Constructor.

Method Detail

getValue

public final java.lang.String getValue()
Gets the value of this attribute.

Specified by:
getValue in interface org.w3c.dom.Attr

setValue

public final void setValue(java.lang.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 org.w3c.dom.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(java.lang.String prefix,
                               java.lang.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 java.lang.String getTagName()
Description copied from interface: Namespaceable
Gets the tag name of this item. The tag name is also called the full qualitifed 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(java.lang.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 java.lang.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 org.w3c.dom.Node
Specified by:
getLocalName in interface Namespaceable
Overrides:
getLocalName in class AbstractItem

setLocalName

public final void setLocalName(java.lang.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

isReadonly

public final boolean isReadonly()
Tests whether this attribute is read-only. Note: An attribute is read-only if the read-only flag is set (setReadonly) or any of its owner item is read-only (getOwner().isReadonly()).

Specified by:
isReadonly in interface Item
Overrides:
isReadonly in class AbstractItem

setModified

public void setModified()
Description copied from interface: Item
Sets the modification flag. Unlike Item.clearModified(boolean), it won't set children's modification flags, rather it sets its parent's modification flag.

The modifiaction flag is maintain automatically, so you rarely needs to call this method.

Unlike other methods, it doesn't affected by the read-only flag.

Specified by:
setModified in interface Item
Overrides:
setModified in class AbstractItem

getName

public final java.lang.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 org.w3c.dom.Attr
Specified by:
getName in interface Item
See Also:
Namespaceable.getTagName()

setName

public final void setName(java.lang.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:
Namespaceable.setTagName(java.lang.String)

getText

public final java.lang.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
Overrides:
getText in class AbstractItem

setText

public final void setText(java.lang.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 org.w3c.dom.Node

getOwnerDocument

public final org.w3c.dom.Document getOwnerDocument()
Specified by:
getOwnerDocument in interface org.w3c.dom.Node
Overrides:
getOwnerDocument in class AbstractItem

getNamespaceURI

public final java.lang.String getNamespaceURI()
Specified by:
getNamespaceURI in interface org.w3c.dom.Node
Overrides:
getNamespaceURI in class AbstractItem

getPrefix

public final java.lang.String getPrefix()
Specified by:
getPrefix in interface org.w3c.dom.Node
Overrides:
getPrefix in class AbstractItem

setPrefix

public final void setPrefix(java.lang.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 org.w3c.dom.Node
Overrides:
setPrefix in class AbstractItem

getSchemaTypeInfo

public org.w3c.dom.TypeInfo getSchemaTypeInfo()
Specified by:
getSchemaTypeInfo in interface org.w3c.dom.Attr

isId

public boolean isId()
Specified by:
isId in interface org.w3c.dom.Attr

getSpecified

public final boolean getSpecified()
Specified by:
getSpecified in interface org.w3c.dom.Attr

getOwnerElement

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

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object

clone

public Item clone(boolean preserveModified)
Description copied from interface: Item
Clones this item. Unlike other objects, it does a deep cloning. Also, the returned object is detached by default. The readonly flags are cleaned. If preserveModified is false, all modification flags of the returned object are cleaned, too.

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


Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo