XML for Java Compatibility API 2.0.13

com.ibm.xml.parser
Class TXAttribute

java.lang.Object
  |
  +--com.ibm.xml.parser.Child
        |
        +--com.ibm.xml.parser.Parent
              |
              +--com.ibm.xml.parser.TXAttribute

public class TXAttribute
extends Parent
implements org.w3c.dom.Attr, Namespace

The TXAttribute class implements the Attr interface as defined by the Document Object Model (DOM), and implements the namespace interface as defined by the W3C.

Attr Nodes represent an attribute in an Element object; in other words, an attribute name and an attribute object. Typically the allowable values for the attribute are defined in a document type definition.

The attribute's effective value is determined as follows: if the attribute has been explicitly assigned any value, that value is the attribute's effective value. Otherwise, if there is a declaration for this attribute, and that declaration includes a default value, then that default value is the attribute's effective value. Otherwise, the attribute has no effective value.

In XML, the value of an attribute is represented by a list because the value can be an arbitrarily complex list of entity references.

Version:
Revision: 96 1.7 src/com/ibm/xml/parser/TXAttribute.java, parser, xml4j2, xml4j2_0_13
See Also:
Attr, Namespace, Parent, Serialized Form

Fields inherited from class com.ibm.xml.parser.Child
ATTDEF, ATTLIST, ELEMENT_DECL, NAME_ATTDEF, NAME_ATTLIST, NAME_CDATA, NAME_COMMENT, NAME_DOCFRAGMENT, NAME_DOCUMENT, NAME_ELEMENT_DECL, NAME_PSEUDONODE, NAME_TEXT, PSEUDONODE
 
Constructor Summary
TXAttribute(java.lang.String name, java.lang.String value)
          Constructor.
 
Method Summary
 void acceptPost(Visitor visitor)
          Implements the accept operation of the visitor design pattern when the end of a TXAttribute Node is recognized when traversing the document object tree.
 void acceptPre(Visitor visitor)
          Implements the accept operation of the visitor design pattern when the start of a TXAttribute Node is recognized when traversing the document object tree.
protected  void checkChildType(org.w3c.dom.Node child)
          Check whether child is allowed to be insered in this node or not.
 java.lang.Object clone()
          Clone this TXAttribute Node using the appropriate factory.
 org.w3c.dom.Node cloneNode(boolean deep)
          This method is defined by DOM.
 java.lang.String createExpandedName()
          Returns an expanded name of this attribute.
 boolean equals(org.w3c.dom.Node arg, boolean deep)
           
 boolean equals(java.lang.Object object)
          Returns whether the specified object matches this attribute Node.
 java.lang.String getName()
          Returns the qualified name of this attribute.
 org.w3c.dom.Node getNextSibling()
          Returns null.
 java.lang.String getNodeName()
          This method is defined by DOM.
 short getNodeType()
          Returns that this object is an Attribute Node.
 java.lang.String getNodeValue()
          Returns the value of this attribute.
 java.lang.String getNSLocalName()
          Returns the local name of the Namespace.
 java.lang.String getNSName()
          Returns the Namespace URI.
 org.w3c.dom.Node getOwnerElement()
          Reuurns owner element node.
 org.w3c.dom.Node getParentNode()
          Returns null.
 org.w3c.dom.Node getPreviousSibling()
          Returns null.
 boolean getSpecified()
          Returns whether this attribute was explicitly given a value in the original document (=true), or was allowed to default according to the DTD specification.
 int getType()
          Returns the type of the attribute.
 java.lang.String[] getTypedValue()
          Returns the type values of the attribute.
 java.lang.String getUniversalName()
          Deprecated. Use createExpandedName().
 java.lang.String getValue()
          Returns the value of this attribute.
 int hashCode()
           
protected  void realInsert(org.w3c.dom.Node child, int index)
          Insert a Node into the specified position.
 org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
          Removes the child Node indicated by oldChild from this Nodes list of children, and returns it.
 org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)
          Replaces the child Node oldChild with newChild in this Node's list of children, and return the oldChild Node.
 void setNodeValue(java.lang.String value)
          Sets the value of this attribute.
 void setSpecified(boolean specified)
          Sets whether this attribute was explicitly given a value in the original document (=true), or was allowed to default according to the DTD specification.
 void setType(int type, java.lang.String[] typedValue)
          Sets the type and type values of the attribute.
 void setValue(java.lang.String value)
          Sets the value of this attribute.
 java.lang.String toString()
          Returns the value of this attribute.
 java.lang.String toXMLString()
          Returns this Node in XML format, in name="value" format, and using the default character encoding.
 java.lang.String toXMLString(java.lang.String encoding)
          Returns this Node in XML format, in name="value" format, and using the specified character encoding.
 
Methods inherited from class com.ibm.xml.parser.Parent
addElement, appendChild, elements, expandEntityReferences, getChildNodes, getChildrenArray, getFirstChild, getFirstWithoutReference, getLastChild, getLastWithoutReference, getText, hasChildNodes, insert, insertAfter, insertBefore, insertFirst, insertLast, processAfterRemove
 
Methods inherited from class com.ibm.xml.parser.Child
clearDigest, getAttributes, getDigest, getFactory, getNextWithoutReference, getOwnerDocument, getParentWithoutReference, getPreviousWithoutReference, getUserData, makeXPointer, print, print, searchAncestors, searchAncestors, setFactory, setUserData, toXMLString, toXMLString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TXAttribute

public TXAttribute(java.lang.String name,
                   java.lang.String value)
Constructor.
Parameters:
name - The name of this attribute.
value - The string value of this attribute.
Method Detail

clone

public java.lang.Object clone()
Clone this TXAttribute Node using the appropriate factory. Note that this method does not clone Parent or sibling Nodes.

This method is defined by Child.

Returns:
Cloned TXAttribute Node.
Overrides:
clone in class Child
See Also:
Child.clone()

cloneNode

public org.w3c.dom.Node cloneNode(boolean deep)

This method is defined by DOM.

Overrides:
cloneNode in class Child

equals

public boolean equals(org.w3c.dom.Node arg,
                      boolean deep)
Overrides:
equals in class Child

getNodeType

public short getNodeType()
Returns that this object is an Attribute Node.

This method is defined by DOM.

Returns:
Attr Node indicator.

getNodeName

public java.lang.String getNodeName()

This method is defined by DOM.

See Also:
getName()

getName

public java.lang.String getName()
Returns the qualified name of this attribute. If the attribute name has a namespace prefix, the prefix will still be attached.

This method is defined by DOM.

Specified by:
getName in interface org.w3c.dom.Attr
Returns:
The name of this attribute (should never be null)

getValue

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

This method is defined by DOM.

Specified by:
getValue in interface org.w3c.dom.Attr
Returns:
The value of this attribute, or "" if no value.
See Also:
getTypedValue(), setValue(java.lang.String), toString()

getNodeValue

public java.lang.String getNodeValue()
Returns the value of this attribute.
Returns:
The value of this attribute, or "" if no value.

This method is defined by DOM.

Overrides:
getNodeValue in class Child

toString

public java.lang.String toString()
Returns the value of this attribute.
Returns:
The value of this attribute, or "" if no value.
Overrides:
toString in class java.lang.Object
See Also:
getValue(), toXMLString(java.lang.String)

setValue

public void setValue(java.lang.String value)
Sets the value of this attribute.
Specified by:
setValue in interface org.w3c.dom.Attr
Parameters:
value - The value of this attribute.
See Also:
getValue(), setNodeValue(java.lang.String), getTypedValue()

setNodeValue

public void setNodeValue(java.lang.String value)
Sets the value of this attribute.

This method is defined by DOM.

Parameters:
value - The value of this attribute.
Overrides:
setNodeValue in class Child
See Also:
getNodeValue(), getValue(), setValue(java.lang.String), getTypedValue()

realInsert

protected void realInsert(org.w3c.dom.Node child,
                          int index)
                   throws LibraryException
Insert a Node into the specified position.
Parameters:
child - The Node being inserted. Text or EntityReference.
index - 0-based index into the list of children.
Throws:
LibraryException - Thrown if the document's root element is set twice.
Overrides:
realInsert in class Parent

replaceChild

public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
                                     org.w3c.dom.Node oldChild)
                              throws org.w3c.dom.DOMException
Replaces the child Node oldChild with newChild in this Node's list of children, and return the oldChild Node. If oldChild was not already a Child of this Node, a DOMException is thrown.

This method is defined by DOM.

Parameters:
newChild - The child Node to replace with. Text or EntityReference.
oldChild - The child Node being replaced.
Returns:
The child Node being replaced.
Throws:
org.w3c.dom.DOMException - Thrown if oldChild is not a child of this object.
Overrides:
replaceChild in class Parent
See Also:
removeChild(org.w3c.dom.Node)

removeChild

public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
                             throws org.w3c.dom.DOMException
Removes the child Node indicated by oldChild from this Nodes list of children, and returns it. If oldChild was not a Child of this Node, a DOMException is thrown.

This method is defined by DOM.

Parameters:
oldChild - The child Node being removed.
Returns:
The child Node being removed.
Throws:
org.w3c.dom.DOMException - Thrown if oldChild is not a child of this object.
Overrides:
removeChild in class Parent
See Also:
replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)

getSpecified

public boolean getSpecified()
Returns whether this attribute was explicitly given a value in the original document (=true), or was allowed to default according to the DTD specification.
Specified by:
getSpecified in interface org.w3c.dom.Attr
Returns:
=true if value explicitly defined; otherwise, false.
See Also:
setSpecified(boolean)

setSpecified

public void setSpecified(boolean specified)
Sets whether this attribute was explicitly given a value in the original document (=true), or was allowed to default according to the DTD specification.
Parameters:
specified - =true if value explicitly defined; otherwise, false.
See Also:
getSpecified()

getNSLocalName

public java.lang.String getNSLocalName()
Returns the local name of the Namespace.

This method is defined by Namespace.

Specified by:
getNSLocalName in interface Namespace
Returns:
The Namespace local name, or null if no local name.
See Also:
Namespace

getNSName

public java.lang.String getNSName()
Returns the Namespace URI.

This method is defined by Namespace.

Specified by:
getNSName in interface Namespace
Returns:
The Namespace URI, or null if the attribute name does not contain a prefix or XML4J parser namespace processing is disabled.
See Also:
Parser.setProcessNamespace(boolean), Namespace

getUniversalName

public java.lang.String getUniversalName()
Deprecated. Use createExpandedName().
If namespace support is enabled and this Attribute's name contains a prefix name, return a string of getNSName()+":"+getNSLocalName(); otherwise, return getNSLocalName() .
Specified by:
getUniversalName in interface Namespace
Returns:
The universal name, or null if this attribute's name does not contain a prefix name or XML4J parser namespace processing is disabled.
See Also:
getNSName(), getNSLocalName(), Parser.setProcessNamespace(boolean)

createExpandedName

public java.lang.String createExpandedName()
Returns an expanded name of this attribute. The expanded name is a set of [a namespace URI, an attribute localPart] (if this attribute has a prefix) or [a namespace URI, an element localPart, an attribute localPart] (if this attribute has no prefix) connected by TXDocument#expandedNameSeparator.

This method is defined by Namespace.

Specified by:
createExpandedName in interface Namespace
Throws:
LibraryException - Thrown if this attribute doesn't belong to any element.
See Also:
TXDocument.expandedNameSeparator, Parser.setProcessNamespace(boolean)

getType

public int getType()
Returns the type of the attribute. Attribute types are only set when a grammar definition (DTD) is available.
Returns:
The attribute type as defined by AttDef.
See Also:
AttDef, setType(int, java.lang.String[]), getTypedValue()

getTypedValue

public java.lang.String[] getTypedValue()
Returns the type values of the attribute. Attribute type values are only set when a grammar definition (DTD) is available.
Returns:
getTypeValue()[0] = getValue() when getType() = CDATA, NOTATION, ID, IDREF, ENTITY, NMTOKEN; otherwise, multiple values are returned.
See Also:
AttDef, setType(int, java.lang.String[]), getType()

setType

public void setType(int type,
                    java.lang.String[] typedValue)
Sets the type and type values of the attribute. Attribute types are only set when a grammar definition (DTD) is available.
Parameters:
type - The attribute type as defined by AttDef.
typedValue - getTypeValue()[0] = getValue() when getType() = CDATA, NOTATION, ID, IDREF, ENTITY, NMTOKEN; otherwise, multiple values are returned.
See Also:
AttDef, setType(int, java.lang.String[]), getType(), getTypedValue()

toXMLString

public java.lang.String toXMLString(java.lang.String encoding)
Returns this Node in XML format, in name="value" format, and using the specified character encoding.
Parameters:
encoding - Java character encoding to use.
Returns:
XML formatted string expressed as name="value".
See Also:
Parent.getText()

toXMLString

public java.lang.String toXMLString()
Returns this Node in XML format, in name="value" format, and using the default character encoding.
Returns:
XML formatted string expressed as name="value".
See Also:
Parent.getText()

equals

public boolean equals(java.lang.Object object)
Returns whether the specified object matches this attribute Node. A match is defined when the specified object's name matches the name of this attribute.
Returns:
=true if the names match; otherwise, false.
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

acceptPre

public void acceptPre(Visitor visitor)
               throws java.lang.Exception
Implements the accept operation of the visitor design pattern when the start of a TXAttribute Node is recognized when traversing the document object tree.
Parameters:
visitor - The implemention of the Visitor operation (toXMLString, digest, ...)
Throws:
java.lang.Exception - Thrown if this Node can not be visitted, or traversal modification is requested.
See Also:
Visitor, TreeTraversal, NonRecursivePreorderTreeTraversal, TreeTraversalException

acceptPost

public void acceptPost(Visitor visitor)
                throws java.lang.Exception
Implements the accept operation of the visitor design pattern when the end of a TXAttribute Node is recognized when traversing the document object tree.
Parameters:
visitor - The implemention of the Visitor operation (toXMLString, digest, ...)
Throws:
java.lang.Exception - Thrown if this Node can not be visitted, or traversal modification is requested.
See Also:
Visitor, TreeTraversal, NonRecursivePreorderTreeTraversal, TreeTraversalException

getOwnerElement

public org.w3c.dom.Node getOwnerElement()
Reuurns owner element node.

In this DOM implementation, any attribute node is not shared in more than one element.


getParentNode

public org.w3c.dom.Node getParentNode()
Returns null.
Overrides:
getParentNode in class Child

getPreviousSibling

public org.w3c.dom.Node getPreviousSibling()
Returns null.
Overrides:
getPreviousSibling in class Child

getNextSibling

public org.w3c.dom.Node getNextSibling()
Returns null.
Overrides:
getNextSibling in class Child

checkChildType

protected void checkChildType(org.w3c.dom.Node child)
                       throws org.w3c.dom.DOMException
Check whether child is allowed to be insered in this node or not. When not allowed, a DOMException with HIERARCHY_REQUEST_ERR is thrown.
Overrides:
checkChildType in class Parent

XML for Java Compatibility API 2.0.13