org.jdom
Class Attribute

java.lang.Object
  |
  +--org.jdom.Attribute

public class Attribute
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

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.

Version:
1.0
Author:
Brett McLaughlin, Jason Hunter, Elliotte Rusty Harold, Wesley Biggs
See Also:
Serialized Form

Field Summary
protected  java.lang.String name
          The local name of the Attribute
protected  Namespace namespace
          The Namespace of the Attribute
protected  java.lang.String value
          The value of the Attribute
 
Constructor Summary
protected Attribute()
           Default, no-args constructor for implementations to use if needed.
  Attribute(java.lang.String name, java.lang.String value)
           This will create a new Attribute with the specified (local) name and value, and does not place the attribute in a Namespace.
  Attribute(java.lang.String name, java.lang.String value, Namespace namespace)
           This will create a new Attribute with the specified (local) name and value, and in the provided Namespace.
  Attribute(java.lang.String name, java.lang.String prefix, java.lang.String uri, java.lang.String value)
           This will create a new Attribute with the specified (local) name and value, and place it in the specified namespace (with prefix).
 
Method Summary
 java.lang.Object clone()
           This will return a clone of this Attribute.
 boolean equals(java.lang.Object ob)
           This tests for equality of this Attribute to the supplied Object.
 boolean getBooleanValue()
           This gets the value of the attribute, in boolean form, and if no conversion can occur, throws a DataConversionException
 double getDoubleValue()
           This gets the value of the attribute, in double form, and if no conversion can occur, throws a DataConversionException
 float getFloatValue()
           This gets the value of the attribute, in float form, and if no conversion can occur, throws a DataConversionException
 int getIntValue()
           This gets the value of the attribute, in int form, and if no conversion can occur, throws a DataConversionException
 long getLongValue()
           This gets the value of the attribute, in long form, and if no conversion can occur, throws a DataConversionException
 java.lang.String getName()
           This will retrieve the local name of the Attribute.
 Namespace getNamespace()
           This will return this Attribute's Namespace.
 java.lang.String getNamespacePrefix()
           This will retrieve the namespace prefix of the Attribute.
 java.lang.String getNamespaceURI()
           This returns the URI mapped to this Attribute's prefix.
 java.lang.String getQualifiedName()
           This will retrieve the qualified name of the Attribute.
 java.lang.String getSerializedForm()
           This will return the Attribute in XML format, usable in an XML document.
 java.lang.String getValue()
           This will return the actual textual value of this Attribute.
 int hashCode()
           This returns the hash code for this Attribute.
 Attribute setValue(java.lang.String value)
           This will set the value of the Attribute.
 java.lang.String toString()
           This returns a String representation of the Attribute, suitable for debugging.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
The local name of the Attribute

namespace

protected transient Namespace namespace
The Namespace of the Attribute

value

protected java.lang.String value
The value of the Attribute
Constructor Detail

Attribute

protected Attribute()

Default, no-args constructor for implementations to use if needed.


Attribute

public Attribute(java.lang.String name,
                 java.lang.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(java.lang.String name,
                 java.lang.String prefix,
                 java.lang.String uri,
                 java.lang.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(java.lang.String name,
                 java.lang.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

getName

public java.lang.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.

getQualifiedName

public java.lang.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.

getNamespacePrefix

public java.lang.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 java.lang.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.

getNamespace

public Namespace getNamespace()

This will return this Attribute's Namespace.

Returns:
Namespace - Namespace object for this Attribute

getValue

public java.lang.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.

setValue

public Attribute setValue(java.lang.String value)

This will set the value of the Attribute.

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

toString

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

getSerializedForm

public final java.lang.String getSerializedForm()

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

Returns:
String - the serialized form of the Attribute.

equals

public final boolean equals(java.lang.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.
Overrides:
equals in class java.lang.Object

hashCode

public final int hashCode()

This returns the hash code for this Attribute.

Returns:
int - hash code.
Overrides:
hashCode in class java.lang.Object

clone

public final java.lang.Object clone()

This will return a clone of this Attribute.

Returns:
Object - clone of this Attribute.
Overrides:
clone in class java.lang.Object

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.

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.

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.

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.


Copyright © 2000 Brett McLaughlin, Jason Hunter. All Rights Reserved.