Top Description Fields Constructors Methods
org.jdom

public Class Attribute

extends Object
implements Serializable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Serializable
Imports
java.io.*

An XML attribute. Methods allow the user to obtain the value of the attribute as well as namespace and type information.
Authors
Brett McLaughlin, Jason Hunter, Elliotte Rusty Harold, Wesley Biggs, Victor Toni
Version
$Revision: 1.56 $, $Date: 2007/11/10 05:28:58 $

Field Summary

Modifier and TypeField and Description
public static final int
CDATA_TYPE

Attribute type: the attribute value is a string.

private static final String
public static final int
ENTITIES_TYPE

Attribute type: the attribute value is a list of entity names.

public static final int
ENTITY_TYPE

Attribute type: the attribute value is the name of an entity.

public static final int
ENUMERATED_TYPE

Attribute type: the attribute value is a name token from an enumeration.

public static final int
ID_TYPE

Attribute type: the attribute value is a unique identifier.

public static final int
IDREF_TYPE

Attribute type: the attribute value is a reference to a unique identifier.

public static final int
IDREFS_TYPE

Attribute type: the attribute value is a list of references to unique identifiers.

protected String
name

The local name of the Attribute

protected transient Namespace
namespace

The Namespace of the Attribute

public static final int
NMTOKEN_TYPE

Attribute type: the attribute value is a name token.

public static final int
NMTOKENS_TYPE

Attribute type: the attribute value is a list of name tokens.

public static final int
NOTATION_TYPE

Attribute type: the attribute value is the name of a notation.

protected Element
parent

Parent element, or null if none

protected int
type

The type of the Attribute

public static final int
UNDECLARED_TYPE

Attribute type: the attribute has not been declared or type is unknown.

protected String
value

The value of the Attribute

Constructor Summary

AccessConstructor and Description
protected
Attribute()

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

public
Attribute(final String
String name of Attribute.
name
,
final String
String value for new attribute.
value
,
final Namespace
Namespace namespace for new attribute.
namespace
)

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

public
Attribute(final String
String name of Attribute.
name
,
final String
String value for new attribute.
value
,
final int
int type for new attribute.
type
,
final Namespace
Namespace namespace for new attribute.
namespace
)

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

public
Attribute(final String
String name of Attribute.
name
,
final String
String value for new attribute.
value
)

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

public
Attribute(final String
String name of Attribute.
name
,
final String
String value for new attribute.
value
,
final int
int type for new attribute.
type
)

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

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

Object - clone of this Attribute.
clone
()

Overrides java.lang.Object.clone.

This will return a clone of this Attribute.
public Attribute

Returns:

Attribute - this Attribute modified.
detach
()

This detaches the Attribute from its parent, or does nothing if the Attribute has no parent.

public final boolean

Returns:

boolean - whether the Attribute is equal to the supplied Object.
equals
(final Object
Object to compare to.
ob
)

Overrides java.lang.Object.equals.

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

Returns:

int - type for this attribute.
getAttributeType
()

This will return the actual declared type of this Attribute.

public boolean

Returns:

boolean value of attribute.
getBooleanValue
()

This gets the effective boolean value of the attribute, or throws a DataConversionException if a conversion can't be performed.

public Document

Returns:

Document owning this Attribute, or null.
getDocument
()

This retrieves the owning Document for this Attribute, or null if not a currently a member of a Document.

public double

Returns:

double value of attribute.
getDoubleValue
()

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

public float

Returns:

float value of attribute.
getFloatValue
()

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

public int

Returns:

int value of attribute.
getIntValue
()

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

public long

Returns:

long value of attribute.
getLongValue
()

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

public String

Returns:

String - name of this attribute, without any namespace prefix.
getName
()

This will retrieve the local name of the Attribute.

public Namespace

Returns:

Namespace - Namespace object for this Attribute
getNamespace
()

This will return this Attribute's Namespace.

public String

Returns:

String - namespace prefix of this attribute.
getNamespacePrefix
()

This will retrieve the namespace prefix of the Attribute.

public String

Returns:

String - namespace URI for this Attribute.
getNamespaceURI
()

This returns the URI mapped to this Attribute's prefix.

public Element

Returns:

parent of this Attribute
getParent
()

This will return the parent of this Attribute.

public String

Returns:

String - full name for this element.
getQualifiedName
()

This will retrieve the qualified name of the Attribute.

public String

Returns:

String - value for this attribute.
getValue
()

This will return the actual textual value of this Attribute.

public final int

Returns:

int - hash code.
hashCode
()

Overrides java.lang.Object.hashCode.

This returns the hash code for this Attribute.
private void
public Attribute

Returns:

Attribute - this Attribute modified.
setAttributeType
(final int
int type for the attribute.
type
)

This will set the type of the Attribute.

public Attribute

Returns:

Attribute - the attribute modified.
setName
(final String
the new local name to set
name
)

This sets the local name of the Attribute.

public Attribute

Returns:

Element - the element modified.
setNamespace
(Namespace
the new namespace
namespace
)

This sets this Attribute's Namespace.

protected Attribute

Returns:

this Attribute modified.
setParent
(final Element
Element to be new parent.
parent
)

This will set the parent of this Attribute.

public Attribute

Returns:

Attribute - this Attribute modified.
setValue
(final String
String value for the attribute.
value
)

This will set the value of the Attribute.

public String

Returns:

String - information about the Attribute
toString
()

Overrides java.lang.Object.toString.

This returns a String representation of the Attribute, suitable for debugging.
private void
Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

CDATA_TYPEback to summary
public static final int CDATA_TYPE

Attribute type: the attribute value is a string.

See Also
getAttributeType
CVS_IDback to summary
private static final String CVS_ID
ENTITIES_TYPEback to summary
public static final int ENTITIES_TYPE

Attribute type: the attribute value is a list of entity names.

See Also
getAttributeType
ENTITY_TYPEback to summary
public static final int ENTITY_TYPE

Attribute type: the attribute value is the name of an entity.

See Also
getAttributeType
ENUMERATED_TYPEback to summary
public static final int ENUMERATED_TYPE

Attribute type: the attribute value is a name token from an enumeration.

See Also
getAttributeType
ID_TYPEback to summary
public static final int ID_TYPE

Attribute type: the attribute value is a unique identifier.

See Also
getAttributeType
IDREF_TYPEback to summary
public static final int IDREF_TYPE

Attribute type: the attribute value is a reference to a unique identifier.

See Also
getAttributeType
IDREFS_TYPEback to summary
public static final int IDREFS_TYPE

Attribute type: the attribute value is a list of references to unique identifiers.

See Also
getAttributeType
nameback to summary
protected String name

The local name of the Attribute

namespaceback to summary
protected transient Namespace namespace

The Namespace of the Attribute

NMTOKEN_TYPEback to summary
public static final int NMTOKEN_TYPE

Attribute type: the attribute value is a name token.

According to SAX 2.0 specification, attributes of enumerated types should be reported as "NMTOKEN" by SAX parsers. But the major parsers (Xerces and Crimson) provide specific values that permit to recognize them as ENUMERATED_TYPE.

See Also
getAttributeType
NMTOKENS_TYPEback to summary
public static final int NMTOKENS_TYPE

Attribute type: the attribute value is a list of name tokens.

See Also
getAttributeType
NOTATION_TYPEback to summary
public static final int NOTATION_TYPE

Attribute type: the attribute value is the name of a notation.

See Also
getAttributeType
parentback to summary
protected Element parent

Parent element, or null if none

typeback to summary
protected int type

The type of the Attribute

UNDECLARED_TYPEback to summary
public static final int UNDECLARED_TYPE

Attribute type: the attribute has not been declared or type is unknown.

See Also
getAttributeType
valueback to summary
protected String value

The value of the Attribute

Constructor Detail

Attributeback to summary
protected Attribute()

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

Attributeback to summary
public Attribute(final String name, final String value, final Namespace namespace)

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

Parameters
name:String

String name of Attribute.

value:String

String value for new attribute.

namespace:Namespace

Namespace namespace for new attribute.

Exceptions
IllegalNameException:
if the given name is illegal as an attribute name or if if the new namespace is the default namespace. Attributes cannot be in a default namespace.
IllegalDataException:
if the given attribute value is illegal character data (as determined by org.jdom.Verifier#checkCharacterData).
Attributeback to summary
public Attribute(final String name, final String value, final int type, final Namespace namespace)

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

Parameters
name:String

String name of Attribute.

value:String

String value for new attribute.

type:int

int type for new attribute.

namespace:Namespace

Namespace namespace for new attribute.

Exceptions
IllegalNameException:
if the given name is illegal as an attribute name or if if the new namespace is the default namespace. Attributes cannot be in a default namespace.
IllegalDataException:
if the given attribute value is illegal character data (as determined by org.jdom.Verifier#checkCharacterData) or if the given attribute type is not one of the supported types.
Attributeback to summary
public Attribute(final String name, final 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

String name of Attribute.

value:String

String value for new attribute.

Exceptions
IllegalNameException:
if the given name is illegal as an attribute name.
IllegalDataException:
if the given attribute value is illegal character data (as determined by org.jdom.Verifier#checkCharacterData).
Attributeback to summary
public Attribute(final String name, final String value, final 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.

Note

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

Parameters
name:String

String name of Attribute.

value:String

String value for new attribute.

type:int

int type for new attribute.

Exceptions
IllegalNameException:
if the given name is illegal as an attribute name.
IllegalDataException:
if the given attribute value is illegal character data (as determined by org.jdom.Verifier#checkCharacterData) or if the given attribute type is not one of the supported types.

Method Detail

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

This will return a clone of this Attribute.

Returns:Object

Object - clone of this Attribute.

detachback to summary
public Attribute detach()

This detaches the Attribute from its parent, or does nothing if the Attribute has no parent.

Returns:Attribute

Attribute - this Attribute modified.

equalsback to summary
public final boolean equals(final Object ob)

Overrides java.lang.Object.equals.

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

Parameters
ob:Object

Object to compare to.

Returns:boolean

boolean - whether the Attribute is equal to the supplied Object.

getAttributeTypeback to summary
public int getAttributeType()

This will return the actual declared type of this Attribute.

Returns:int

int - type for this attribute.

getBooleanValueback to summary
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

boolean value of attribute.

Exceptions
DataConversionException:
when conversion fails.
getDocumentback to summary
public Document getDocument()

This retrieves the owning Document for this Attribute, or null if not a currently a member of a Document.

Returns:Document

Document owning this Attribute, or null.

getDoubleValueback to summary
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

double value of attribute.

Exceptions
DataConversionException:
when conversion fails.
getFloatValueback to summary
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

float value of attribute.

Exceptions
DataConversionException:
when conversion fails.
getIntValueback to summary
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

int value of attribute.

Exceptions
DataConversionException:
when conversion fails.
getLongValueback to summary
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

long value of attribute.

Exceptions
DataConversionException:
when conversion fails.
getNameback to summary
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

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

getNamespaceback to summary
public Namespace getNamespace()

This will return this Attribute's Namespace.

Returns:Namespace

Namespace - Namespace object for this Attribute

getNamespacePrefixback to summary
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

String - namespace prefix of this attribute.

getNamespaceURIback to summary
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

String - namespace URI for this Attribute.

getParentback to summary
public Element getParent()

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

Returns:Element

parent of this Attribute

getQualifiedNameback to summary
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

String - full name for this element.

getValueback to summary
public String getValue()

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

Returns:String

String - value for this attribute.

hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

This returns the hash code for this Attribute.

Returns:int

int - hash code.

readObjectback to summary
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException
setAttributeTypeback to summary
public Attribute setAttributeType(final int type)

This will set the type of the Attribute.

Parameters
type:int

int type for the attribute.

Returns:Attribute

Attribute - this Attribute modified.

Exceptions
IllegalDataException:
if the given attribute type is not one of the supported types.
setNameback to summary
public Attribute setName(final String name)

This sets the local name of the Attribute.

Parameters
name:String

the new local name to set

Returns:Attribute

Attribute - the attribute modified.

Exceptions
IllegalNameException:
if the given name is illegal as an attribute name.
setNamespaceback to summary
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:Namespace

the new namespace

Returns:Attribute

Element - the element modified.

Exceptions
IllegalNameException:
if the new namespace is the default namespace. Attributes cannot be in a default namespace.
setParentback to summary
protected Attribute setParent(final Element parent)

This will set the parent of this Attribute.

Parameters
parent:Element

Element to be new parent.

Returns:Attribute

this Attribute modified.

setValueback to summary
public Attribute setValue(final String value)

This will set the value of the Attribute.

Parameters
value:String

String value for the attribute.

Returns:Attribute

Attribute - this Attribute modified.

Exceptions
IllegalDataException:
if the given attribute value is illegal character data (as determined by org.jdom.Verifier#checkCharacterData).
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

This returns a String representation of the Attribute, suitable for debugging.

Returns:String

String - information about the Attribute

writeObjectback to summary
private void writeObject(final ObjectOutputStream out) throws IOException