org.jdom

Class Attribute

Implemented Interfaces:
Cloneable, Serializable

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

An XML attribute. Methods allow the user to obtain the value of the attribute as well as namespace and type information.
Version:
$Revision: 1.52 $, $Date: 2004/03/01 23:58:28 $
Authors:
Brett McLaughlin
Jason Hunter
Elliotte Rusty Harold
Wesley Biggs

Field Summary

static int
CDATA_TYPE
Attribute type: the attribute value is a string.
static int
ENTITIES_TYPE
Attribute type: the attribute value is a list of entity names.
static int
ENTITY_TYPE
Attribute type: the attribute value is the name of an entity.
static int
ENUMERATED_TYPE
Attribute type: the attribute value is a name token from an enumeration.
static int
IDREFS_TYPE
Attribute type: the attribute value is a list of references to unique identifiers.
static int
IDREF_TYPE
Attribute type: the attribute value is a reference to a unique identifier.
static int
ID_TYPE
Attribute type: the attribute value is a unique identifier.
static int
NMTOKENS_TYPE
Attribute type: the attribute value is a list of name tokens.
static int
NMTOKEN_TYPE
Attribute type: the attribute value is a name token.
static int
NOTATION_TYPE
Attribute type: the attribute value is the name of a notation.
static int
UNDECLARED_TYPE
Attribute type: the attribute has not been declared or type is unknown.
protected String
name
The local name of the Attribute
protected Namespace
namespace
The Namespace of the Attribute
protected Object
parent
Parent element, or null if none
protected int
type
The type of the Attribute
protected String
value
The value of the Attribute

Constructor Summary

Attribute()
Default, no-args constructor for implementations to use if needed.
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.
Attribute(String name, String value, int type)
This will create a new Attribute with the specified (local) name, value and type, and does not place the attribute in a Namespace.
Attribute(String name, String value, int type, Namespace namespace)
This will create a new Attribute with the specified (local) name, value, and type, and in the provided Namespace.
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.

Method Summary

Object
clone()
This will return a clone of this Attribute.
Attribute
detach()
This detaches the Attribute from its parent, or does nothing if the Attribute has no parent.
boolean
equals(Object ob)
This tests for equality of this Attribute to the supplied Object.
int
getAttributeType()
This will return the actual declared type of this Attribute.
boolean
getBooleanValue()
This gets the effective boolean value of the attribute, or throws a DataConversionException if a conversion can't be performed.
Document
getDocument()
This retrieves the owning Document for this Attribute, or null if not a currently a member of a Document.
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
String
getName()
This will retrieve the local name of the Attribute.
Namespace
getNamespace()
This will return this Attribute's Namespace.
String
getNamespacePrefix()
This will retrieve the namespace prefix of the Attribute.
String
getNamespaceURI()
This returns the URI mapped to this Attribute's prefix.
Element
getParent()
This will return the parent of this Attribute.
String
getQualifiedName()
This will retrieve the qualified name of the Attribute.
String
getValue()
This will return the actual textual value of this Attribute.
int
hashCode()
This returns the hash code for this Attribute.
Attribute
setAttributeType(int type)
This will set the type of the Attribute.
Attribute
setName(String name)
This sets the local name of the Attribute.
Attribute
setNamespace(Namespace namespace)
This sets this Attribute's Namespace.
protected Attribute
setParent(Element parent)
This will set the parent of this Attribute.
Attribute
setValue(String value)
This will set the value of the Attribute.
String
toString()
This returns a String representation of the Attribute, suitable for debugging.

Field Details

CDATA_TYPE

public static final int CDATA_TYPE
Attribute type: the attribute value is a string.
Field Value:
1

ENTITIES_TYPE

public static final int ENTITIES_TYPE
Attribute type: the attribute value is a list of entity names.
Field Value:
6

ENTITY_TYPE

public static final int ENTITY_TYPE
Attribute type: the attribute value is the name of an entity.
Field Value:
5

ENUMERATED_TYPE

public static final int ENUMERATED_TYPE
Attribute type: the attribute value is a name token from an enumeration.
Field Value:
10

IDREFS_TYPE

public static final int IDREFS_TYPE
Attribute type: the attribute value is a list of references to unique identifiers.
Field Value:
4

IDREF_TYPE

public static final int IDREF_TYPE
Attribute type: the attribute value is a reference to a unique identifier.
Field Value:
3

ID_TYPE

public static final int ID_TYPE
Attribute type: the attribute value is a unique identifier.
Field Value:
2

NMTOKENS_TYPE

public static final int NMTOKENS_TYPE
Attribute type: the attribute value is a list of name tokens.
Field Value:
8

NMTOKEN_TYPE

public static final int NMTOKEN_TYPE
Field Value:
7

NOTATION_TYPE

public static final int NOTATION_TYPE
Attribute type: the attribute value is the name of a notation.
Field Value:
9

UNDECLARED_TYPE

public static final int UNDECLARED_TYPE
Attribute type: the attribute has not been declared or type is unknown.
Field Value:
0

name

protected String name
The local name of the Attribute

namespace

protected Namespace namespace
The Namespace of the Attribute

parent

protected Object parent
Parent element, or null if none

type

protected int type
The type of the Attribute

value

protected String value
The value of the Attribute

Constructor Details

Attribute

protected Attribute()
Default, no-args constructor for implementations to use if needed.

Attribute

public Attribute(String name,
                 String value)
Parameters:
name - String name of Attribute.
value - String value for new attribute.

Attribute

public Attribute(String name,
                 String value,
                 int type)
Parameters:
name - String name of Attribute.
value - String value for new attribute.
type - int type for new attribute.

Attribute

public Attribute(String name,
                 String value,
                 int type,
                 Namespace namespace)
This will create a new Attribute with the specified (local) name, value, and type, and in the provided Namespace.
Parameters:
name - String name of Attribute.
value - String value for new attribute.
type - int type for new attribute.
namespace - Namespace namespace for new attribute.

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.
namespace - Namespace namespace for new attribute.

Method Details

clone

public Object clone()
This will return a clone of this Attribute.
Returns:
Object - clone of this Attribute.

detach

public Attribute detach()
This detaches the Attribute from its parent, or does nothing if the Attribute has no parent.
Returns:
Attribute - this Attribute modified.

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.

getAttributeType

public int getAttributeType()
This will return the actual declared type of this Attribute.
Returns:
int - type for this attribute.

getBooleanValue

public boolean getBooleanValue()
            throws DataConversionException
This gets the effective boolean value of the attribute, or throws a DataConversionException if a conversion can't be performed. True values are: "true", "on", "1", and "yes". False values are: "false", "off", "0", and "no". Values are trimmed before comparison. Values other than those listed here throw the exception.
Returns:
boolean value of attribute.
Throws:
DataConversionException - when conversion fails.

getDocument

public Document getDocument()
This retrieves the owning Document for this Attribute, or null if not a currently a member of a Document.
Returns:
Document owning this Attribute, or null.

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()
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()
Returns:
String - full name for this element.

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.

setAttributeType

public Attribute setAttributeType(int type)
This will set the type of the Attribute.
Parameters:
type - int type for the attribute.
Returns:
Attribute - this Attribute modified.

setName

public Attribute setName(String name)
This sets the local name of the Attribute.
Parameters:
name - the new local name to set
Returns:
Attribute - the attribute modified.

setNamespace

public Attribute setNamespace(Namespace namespace)
This sets this Attribute's Namespace. If the provided namespace is null, the attribute will have no namespace. The namespace must have a prefix.
Parameters:
namespace - the new namespace
Returns:
Element - the element modified.

setParent

protected Attribute setParent(Element parent)
This will set the parent of this Attribute.
Parameters:
parent - Element to be new parent.
Returns:
this Attribute modified.

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.
Returns:
String - information about the Attribute

Copyright B) 2004 Jason Hunter, Brett McLaughlin. All Rights Reserved.