XML for Java EA2

com.ibm.xml.dom
Class AttrImpl

java.lang.Object
  |
  +--com.ibm.xml.dom.NodeImpl
        |
        +--com.ibm.xml.dom.AttrImpl
Direct Known Subclasses:
DeferredAttrImpl

public class AttrImpl
extends NodeImpl
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: Attributes do not have parent nodes. In other words, the getParentNode() method is defined to return null for Attr nodes. However, the getElement() method will return the element node that this attribute is associated with.

Since:
PR-DOM-Level-1-19980818.
Version:
Revision: 50 1.7 src/com/ibm/xml/dom/AttrImpl.java, parser, xml4j2, xml4j2_0_14
See Also:
Serialized Form

Field Summary
protected  java.lang.String localName
          DOM2: localName.
protected  java.lang.String namespaceURI
          DOM2: Namespace URI.
protected  boolean owned
          Flag used for INUSE exception processing.
protected  java.lang.String prefix
          DOM2: Prefix
protected  boolean specified
          False for default attributes.
 
Fields inherited from class com.ibm.xml.dom.NodeImpl
ELEMENT_DEFINITION_NODE, firstChild, kidOK, lastChild, name, nextSibling, ownerDocument, parentNode, previousSibling, readOnly, syncChildren, syncData, userData, value
 
Constructor Summary
protected AttrImpl(DocumentImpl ownerDocument, java.lang.String name)
          Attribute has no public constructor.
protected AttrImpl(DocumentImpl ownerDocument, java.lang.String namespaceURI, java.lang.String qualifiedName)
          DOM2: Constructor for Namespace implementation.
 
Method Summary
 Element getElement()
          Deprecated. Previous working draft of DOM Level 2. New method is getOwnerElement().
 java.lang.String getLocalName()
          Introduced in DOM Level 2.
 java.lang.String getName()
          In Attributes, NodeName is considered a synonym for the attribute's Name
 java.lang.String getNamespaceURI()
          Introduced in DOM Level 2.
 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.
 Node getParentNode()
          Attributes don't have parent nodes.
 java.lang.String getPrefix()
          Introduced in DOM Level 2.
 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 setNodeValue(java.lang.String value)
          Implicit in the rerouting of getNodeValue to getValue is the need to redefine setNodeValue, for symmetry's sake.
 void setPrefix(java.lang.String prefix)
          Introduced in DOM Level 2.
 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 com.ibm.xml.dom.NodeImpl
appendChild, changed, cloneNode, getAttributes, getChildNodes, getFirstChild, getLastChild, getLength, getNextSibling, getNodeName, getOwnerDocument, getPreviousSibling, getReadOnly, getUserData, hasChildNodes, insertBefore, item, removeChild, replaceChild, setReadOnly, setUserData, supports, synchronizeChildren, synchronizeData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

owned

protected boolean owned
Flag used for INUSE exception processing.

specified

protected boolean specified
False for default attributes.

namespaceURI

protected java.lang.String namespaceURI
DOM2: Namespace URI.

prefix

protected java.lang.String prefix
DOM2: Prefix

localName

protected java.lang.String localName
DOM2: localName.
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(DocumentImpl ownerDocument,
                   java.lang.String namespaceURI,
                   java.lang.String qualifiedName)
DOM2: Constructor for Namespace implementation.
Method Detail

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

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

getNodeValue

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

getParentNode

public Node getParentNode()
Attributes don't have parent nodes.
Overrides:
getParentNode in class NodeImpl

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

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.
Since:
WD-DOM-Level-2-19990719

getNamespaceURI

public java.lang.String getNamespaceURI()
Introduced in DOM Level 2.

The namespace URI of this node, or null if it is unspecified.

This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time.

For nodes created with a DOM Level 1 method, such as createElement from the Document interface, this is null.

Overrides:
getNamespaceURI in class NodeImpl
Since:
WD-DOM-Level-2-19990923

getPrefix

public java.lang.String getPrefix()
Introduced in DOM Level 2.

The namespace prefix of this node, or null if it is unspecified.

For nodes created with a DOM Level 1 method, such as createElement from the Document interface, this is null.

Overrides:
getPrefix in class NodeImpl
Since:
WD-DOM-Level-2-19990923

setPrefix

public void setPrefix(java.lang.String prefix)
               throws DOMException
Introduced in DOM Level 2.

Note that setting this attribute changes the nodeName attribute, which holds the qualified name, as well as the tagName and name attributes of the Element and Attr interfaces, when applicable.

Throws:
INVALID_CHARACTER_ERR - Raised if the specified prefix contains an invalid character.
Overrides:
setPrefix in class NodeImpl
Since:
WD-DOM-Level-2-19990923

getLocalName

public java.lang.String getLocalName()
Introduced in DOM Level 2.

Returns the local part of the qualified name of this node.

Overrides:
getLocalName in class NodeImpl
Since:
WD-DOM-Level-2-19990923

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

XML for Java EA2