org.jdom
Class Attribute


public class Attribute
implements Cloneable, Serializable

Attribute defines behavior for an XML attribute, modeled in Java. Methods allow the user to obtain the value of the attribute as well as namespace information.

Author:
Brett McLaughlin, Jason Hunter, Elliotte Rusty Harold, Wesley Biggs
Version: 1.0

Constructor Summary
Attribute(String name, String value, Namespace namespace)
           This will create a new Attribute with the specified (local) name and value, and in the provided Namespace.
Attribute(String name, String prefix, String uri, String value)
           This will create a new Attribute with the specified (local) name and value, and place it in the specified namespace (with prefix).
Attribute(String name, String value)
           This will create a new Attribute with the specified (local) name and value, and does not place the attribute in a Namespace.

Method Summary
 Objectclone()
           This will return a clone of this Attribute.
 final booleanequals(Object ob)
           This tests for equality of this Attribute to the supplied Object.
 booleangetBooleanValue()
           This gets the value of the attribute, in boolean form, and if no conversion can occur, throws a DataConversionException
 doublegetDoubleValue()
           This gets the value of the attribute, in double form, and if no conversion can occur, throws a DataConversionException
 floatgetFloatValue()
           This gets the value of the attribute, in float form, and if no conversion can occur, throws a DataConversionException
 intgetIntValue()
           This gets the value of the attribute, in int form, and if no conversion can occur, throws a DataConversionException
 longgetLongValue()
           This gets the value of the attribute, in long form, and if no conversion can occur, throws a DataConversionException
 StringgetName()
           This will retrieve the local name of the Attribute.
 NamespacegetNamespace()
           This will return this Attribute's Namespace.
 StringgetNamespacePrefix()
           This will retrieve the namespace prefix of the Attribute.
 StringgetNamespaceURI()
           This returns the URI mapped to this Attribute's prefix.
 ElementgetParent()
           This will return the parent of this Attribute.
 StringgetQualifiedName()
           This will retrieve the qualified name of the Attribute.
 final StringgetSerializedForm()
           This will return the Attribute in XML format, usable in an XML document.
 StringgetValue()
           This will return the actual textual value of this Attribute.
 final inthashCode()
           This returns the hash code for this Attribute.
 AttributesetValue(String value)
           This will set the value of the Attribute.
 StringtoString()
           This returns a String representation of the Attribute, suitable for debugging.

Constructor Detail

Attribute

public Attribute(String name, String value, Namespace namespace)

This will create a new Attribute with the specified (local) name and value, and in the provided Namespace.

Parameters:
name - String name of Attribute.
value - String value for new attribute.

Attribute

public Attribute(String name, String prefix, String uri, String value)

This will create a new Attribute with the specified (local) name and value, and place it in the specified namespace (with prefix).

Parameters:
name - String name of Attribute.
prefix - String prefix for Attribute.
uri - String URI for namespace this Attribute is in.
value - String value for new attribute.

Attribute

public Attribute(String name, String value)

This will create a new Attribute with the specified (local) name and value, and does not place the attribute in a Namespace.

Note: This actually explicitly puts the Attribute in the "empty" Namespace (Namespace.NO_NAMESPACE).

Parameters:
name - String name of Attribute.
value - String value for new attribute.
Method Detail

clone

public Object clone()

This will return a clone of this Attribute.

Returns: Object - clone of this Attribute.

equals

public final boolean equals(Object ob)

This tests for equality of this Attribute to the supplied Object.

Parameters:
ob - Object to compare to.
Returns: boolean - whether the Attribute is equal to the supplied Object.

getBooleanValue

public boolean getBooleanValue()
throws DataConversionException

This gets the value of the attribute, in boolean form, and if no conversion can occur, throws a DataConversionException

Returns: boolean value of attribute.
Throws:
DataConversionException - - when conversion fails.

getDoubleValue

public double getDoubleValue()
throws DataConversionException

This gets the value of the attribute, in double form, and if no conversion can occur, throws a DataConversionException

Returns: double value of attribute.
Throws:
DataConversionException - - when conversion fails.

getFloatValue

public float getFloatValue()
throws DataConversionException

This gets the value of the attribute, in float form, and if no conversion can occur, throws a DataConversionException

Returns: float value of attribute.
Throws:
DataConversionException - - when conversion fails.

getIntValue

public int getIntValue()
throws DataConversionException

This gets the value of the attribute, in int form, and if no conversion can occur, throws a DataConversionException

Returns: int value of attribute.
Throws:
DataConversionException - - when conversion fails.

getLongValue

public long getLongValue()
throws DataConversionException

This gets the value of the attribute, in long form, and if no conversion can occur, throws a DataConversionException

Returns: long value of attribute.
Throws:
DataConversionException - - when conversion fails.

getName

public String getName()

This will retrieve the local name of the Attribute. For any XML attribute which appears as [namespacePrefix]:[attributeName], the local name of the attribute would be [attributeName]. When the attribute has no namespace, the local name is simply the attribute name.

To obtain the namespace prefix for this attribute, the getNamespacePrefix() method should be used.

Returns: String - name of this attribute, without any namespace prefix.

getNamespace

public Namespace getNamespace()

This will return this Attribute's Namespace.

Returns: Namespace - Namespace object for this Attribute

getNamespacePrefix

public String getNamespacePrefix()

This will retrieve the namespace prefix of the Attribute. For any XML attribute which appears as [namespacePrefix]:[attributeName], the namespace prefix of the attribute would be [namespacePrefix]. When the attribute has no namespace, an empty String is returned.

Returns: String - namespace prefix of this attribute.

getNamespaceURI

public String getNamespaceURI()

This returns the URI mapped to this Attribute's prefix. If no mapping is found, an empty String is returned.

Returns: String - namespace URI for this Attribute.

getParent

public Element getParent()

This will return the parent of this Attribute. If there is no parent, then this returns null.

Returns: parent of this Attribute

getQualifiedName

public String getQualifiedName()

This will retrieve the qualified name of the Attribute. For any XML attribute whose name is [namespacePrefix]:[elementName], the qualified name of the attribute would be everything (both namespace prefix and element name). When the attribute has no namespace, the qualified name is simply the attribute's local name.

To obtain the local name of the attribute, the getName() method should be used.

To obtain the namespace prefix for this attribute, the getNamespacePrefix() method should be used.

Returns: String - full name for this element.

getSerializedForm

public final String getSerializedForm()

This will return the Attribute in XML format, usable in an XML document.

Returns: String - the serialized form of the Attribute.

getValue

public String getValue()

This will return the actual textual value of this Attribute. This will include all text within the quotation marks.

Returns: String - value for this attribute.

hashCode

public final int hashCode()

This returns the hash code for this Attribute.

Returns: int - hash code.

setValue

public Attribute setValue(String value)

This will set the value of the Attribute.

Parameters:
value - String value for the attribute.
Returns: Attribute - this Attribute modified.

toString

public String toString()

This returns a String representation of the Attribute, suitable for debugging. If the XML representation of the Attribute is desired, getSerializedForm() should be used.

Returns: String - information about the Attribute

Association Links

to Class java.lang.String

The local name of the Attribute

to Class org.jdom.Namespace

The {@link Namespace} of the Attribute

to Class java.lang.String

The value of the Attribute

to Class org.jdom.Element

Parent element, or null if none