Google

Xerces 3.1.1 API: Class AttrImpl
Xerces 3.1.1

org.apache.xerces.dom
Class AttrImpl

java.lang.Object
  |
  +--org.apache.xerces.dom.NodeImpl
        |
        +--org.apache.xerces.dom.ParentNode
              |
              +--org.apache.xerces.dom.AttrImpl
Direct Known Subclasses:
AttrNSImpl, DeferredAttrImpl

public class AttrImpl
extends ParentNode
implements Attr

Attribute represents an XML-style attribute of an Element. Typically, the allowable values are controlled by its declaration in the Document Type Definition (DTD) governing this kind of document.

If the attribute has not been explicitly assigned a value, but has been declared in the DTD, it will exist and have that default. Only if neither the document nor the DTD specifies a value will the Attribute really be considered absent and have no value; in that case, querying the attribute will return null.

Attributes may have multiple children that contain their data. (XML allows attributes to contain entity references, and tokenized attribute types such as NMTOKENS may have a child for each token.) For convenience, the Attribute object's getValue() method returns the string version of the attribute's value.

Attributes are not children of the Elements they belong to, in the usual sense, and have no valid Parent reference. However, the spec says they _do_ belong to a specific Element, and an INUSE exception is to be thrown if the user attempts to explicitly share them between elements.

Note that Elements do not permit attributes to appear to be shared (see the INUSE exception), so this object's mutability is officially not an issue.

Note: The ownerNode attribute is used to store the Element the Attr node is associated with. Attr nodes do not have parent nodes. Besides, the getOwnerElement() method can be used to get the element node this attribute is associated with.

AttrImpl does not support Namespaces. AttrNSImpl, which inherits from it, does.

Since:
PR-DOM-Level-1-19980818.
Version:
 
See Also:
AttrNSImpl, Serialized Form

Field Summary
protected  java.lang.String name
          Attribute name.
 
Fields inherited from class org.apache.xerces.dom.ParentNode
firstChild, nodeListIndex, nodeListLength, nodeListNode, ownerDocument
 
Fields inherited from class org.apache.xerces.dom.NodeImpl
ELEMENT_DEFINITION_NODE, FIRSTCHILD, flags, IGNORABLEWS, MUTATION_AGGREGATE, MUTATION_ALL, MUTATION_LOCAL, MUTATION_NONE, MUTATIONEVENTS, OWNED, ownerNode, READONLY, SETVALUE, SPECIFIED, SYNCCHILDREN, SYNCDATA
 
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
protected AttrImpl()
           
protected AttrImpl(DocumentImpl ownerDocument, java.lang.String name)
          Attribute has no public constructor.
 
Method Summary
 Node cloneNode(boolean deep)
          Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
 Element getElement()
          Deprecated. Previous working draft of DOM Level 2. New method is getOwnerElement().
 java.lang.String getName()
          In Attributes, NodeName is considered a synonym for the attribute's Name
 java.lang.String getNodeName()
          Returns the attribute name
 short getNodeType()
          A short integer indicating what type of node this is.
 java.lang.String getNodeValue()
          In Attribute objects, NodeValue is considered a synonym for Value.
 Element getOwnerElement()
          Returns the element node that this attribute is associated with, or null if the attribute has not been added to an element.
 boolean getSpecified()
          The "specified" flag is true if and only if this attribute's value was explicitly specified in the original document.
 java.lang.String getValue()
          The "string value" of an Attribute is its text representation, which in turn is a concatenation of the string values of its children.
 void normalize()
          Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.
 void setNodeValue(java.lang.String value)
          Implicit in the rerouting of getNodeValue to getValue is the need to redefine setNodeValue, for symmetry's sake.
 void setSpecified(boolean arg)
          NON-DOM, for use by parser
 void setValue(java.lang.String value)
          The DOM doesn't clearly define what setValue(null) means.
 java.lang.String toString()
          NON-DOM method for debugging convenience
 
Methods inherited from class org.apache.xerces.dom.ParentNode
getChildNodes, getFirstChild, getLastChild, getLength, getOwnerDocument, hasChildNodes, insertBefore, item, removeChild, replaceChild, setReadOnly, synchronizeChildren, synchronizeChildren
 
Methods inherited from class org.apache.xerces.dom.NodeImpl
addEventListener, appendChild, changed, changes, dispatchEvent, getAttributes, getLocalName, getNamespaceURI, getNextSibling, getParentNode, getPrefix, getPreviousSibling, getReadOnly, getUserData, hasAttributes, isSupported, removeEventListener, setPrefix, setUserData, synchronizeData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
Attribute name.
Constructor Detail

AttrImpl

protected AttrImpl(DocumentImpl ownerDocument,
                   java.lang.String name)
Attribute has no public constructor. Please use the factory method in the Document class.

AttrImpl

protected AttrImpl()
Method Detail

cloneNode

public Node cloneNode(boolean deep)
Description copied from interface: Node
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent; ( parentNode is null.).
Cloning an Element copies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any text it contains unless it is a deep clone, since the text is contained in a child Text node. Cloning an Attribute directly, as opposed to be cloned as part of an Element cloning operation, returns a specified attribute ( specified is true). Cloning any other type of node simply returns a copy of this node.
Note that cloning an immutable subtree results in a mutable copy, but the children of an EntityReference clone are readonly . In addition, clones of unspecified Attr nodes are specified. And, cloning Document, DocumentType, Entity, and Notation nodes is implementation dependent.
Overrides:
cloneNode in class ParentNode
Tags copied from interface: Node
Parameters:
deepIf - true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element).
Returns:
The duplicate node.

getNodeType

public short getNodeType()
A short integer indicating what type of node this is. The named constants for this value are defined in the org.w3c.dom.Node interface.
Overrides:
getNodeType in class NodeImpl

getNodeName

public java.lang.String getNodeName()
Returns the attribute name
Overrides:
getNodeName in class NodeImpl

setNodeValue

public void setNodeValue(java.lang.String value)
                  throws DOMException
Implicit in the rerouting of getNodeValue to getValue is the need to redefine setNodeValue, for symmetry's sake. Note that since we're explicitly providing a value, Specified should be set true.... even if that value equals the default.
Overrides:
setNodeValue in class NodeImpl
Tags copied from class: NodeImpl
Throws:
DOMException(NO_MODIFICATION_ALLOWED_ERR) -  

getNodeValue

public java.lang.String getNodeValue()
In Attribute objects, NodeValue is considered a synonym for Value.
Overrides:
getNodeValue in class NodeImpl
See Also:
getValue()

getName

public java.lang.String getName()
In Attributes, NodeName is considered a synonym for the attribute's Name
Specified by:
getName in interface Attr

setValue

public void setValue(java.lang.String value)
The DOM doesn't clearly define what setValue(null) means. I've taken it as "remove all children", which from outside should appear similar to setting it to the empty string.
Specified by:
setValue in interface Attr

getValue

public java.lang.String getValue()
The "string value" of an Attribute is its text representation, which in turn is a concatenation of the string values of its children.
Specified by:
getValue in interface Attr
Tags copied from interface: Attr
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.

getSpecified

public boolean getSpecified()
The "specified" flag is true if and only if this attribute's value was explicitly specified in the original document. Note that the implementation, not the user, is in charge of this property. If the user asserts an Attribute value (even if it ends up having the same value as the default), it is considered a specified attribute. If you really want to revert to the default, delete the attribute from the Element, and the Implementation will re-assert the default (if any) in its place, with the appropriate specified=false setting.
Specified by:
getSpecified in interface Attr

getElement

public Element getElement()
Deprecated. Previous working draft of DOM Level 2. New method is getOwnerElement().

Returns the element node that this attribute is associated with, or null if the attribute has not been added to an element.
See Also:
getOwnerElement()

getOwnerElement

public Element getOwnerElement()
Returns the element node that this attribute is associated with, or null if the attribute has not been added to an element.
Specified by:
getOwnerElement in interface Attr
Since:
WD-DOM-Level-2-19990719

normalize

public void normalize()
Description copied from interface: Node
Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.In cases where the document contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.
Overrides:
normalize in class ParentNode

setSpecified

public void setSpecified(boolean arg)
NON-DOM, for use by parser

toString

public java.lang.String toString()
NON-DOM method for debugging convenience
Overrides:
toString in class NodeImpl

Xerces 3.1.1