org.jdom
Class Attribute

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

public class Attribute
extends java.lang.Object

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

Field Summary
protected  java.lang.String name
          The local name of the Attribute
protected  java.lang.String prefix
          The namespace prefix 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 name and value.
  Attribute(java.lang.String prefix, java.lang.String name, java.lang.String value)
           This will create a new Attribute with the specified name and value.
 
Method Summary
 boolean getBooleanValue()
           This gets the value of the attribute, in boolean form, and if no conversion can occur, throws a DataConversionException
 boolean getBooleanValue(boolean defaultValue)
           This gets the value of the attribute, in boolean form, and if no conversion can occur, returns the supplied default value.
 byte getByteValue()
           This gets the value of the attribute, in byte form, and if no conversion can occur, throws a DataConversionException
 byte getByteValue(byte defaultValue)
           This gets the value of the attribute, in byte form, and if no conversion can occur, returns the supplied default value.
 char getCharValue()
           This gets the value of the attribute, in char form, and if no conversion can occur, throws a DataConversionException
 char getCharValue(char defaultValue)
           This gets the value of the attribute, in char form, and if no conversion can occur, returns the supplied default value.
 double getDoubleValue()
           This gets the value of the attribute, in double form, and if no conversion can occur, throws a DataConversionException
 double getDoubleValue(double defaultValue)
           This gets the value of the attribute, in double form, and if no conversion can occur, returns the supplied default value.
 float getFloatValue()
           This gets the value of the attribute, in float form, and if no conversion can occur, throws a DataConversionException
 float getFloatValue(float defaultValue)
           This gets the value of the attribute, in float form, and if no conversion can occur, returns the supplied default value.
 java.lang.String getFullName()
           This will retrieve the full name of the Attrbute.
 int getIntValue()
           This gets the value of the attribute, in int form, and if no conversion can occur, throws a DataConversionException
 int getIntValue(int defaultValue)
           This gets the value of the attribute, in int form, and if no conversion can occur, returns the supplied default value.
 long getLongValue()
           This gets the value of the attribute, in long form, and if no conversion can occur, throws a DataConversionException
 long getLongValue(long defaultValue)
           This gets the value of the attribute, in long form, and if no conversion can occur, returns the supplied default value.
 java.lang.String getName()
           This will retrieve the local name of the Attribute.
 java.lang.String getNamespacePrefix()
           This will retrieve the namespace prefix of the Attribute.
 java.lang.String getValue()
           This will return the actual textual value of this Attribute.
 java.lang.String getValue(java.lang.String defaultValue)
           This will return the actual textual value of this Attribute.
 void setValue(java.lang.String value)
           This will set the value of the Attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

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

prefix

protected java.lang.String prefix
The namespace prefix 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 prefix,
                 java.lang.String name,
                 java.lang.String value)

This will create a new Attribute with the specified name and value.

Parameters:
prefix - String prefix for Attribute.
name - String local name of Attribute.
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 name and value.

Parameters:
fullName - 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 prefix (and is in the default 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.

getFullName

public java.lang.String getFullName()

This will retrieve the full name of the Attrbute. For any XML attribute whose name is [namespacePrefix]:[elementName], the full name of the attribute would be everything (both namespace prefix and element name). When the attribute has no namespace prefix (and is in the default namespace), the full 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 prefix (and is in the default namespace), an empty String is returned.

Returns:
String - namespace prefix of 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 void setValue(java.lang.String value)

This will set the value of the Attribute.

Parameters:
value - String value for the attribute.

getValue

public java.lang.String getValue(java.lang.String defaultValue)

This will return the actual textual value of this Attribute. This will include all text within the quotation marks. If no value exists, the supplied default value will be returned.

Parameters:
defaultValue - String default value.
Returns:
String - value for this attribute.

getIntValue

public int getIntValue(int defaultValue)

This gets the value of the attribute, in int form, and if no conversion can occur, returns the supplied default value.

Parameters:
defaultValue - int default.
Returns:
int value of attribute.

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(long defaultValue)

This gets the value of the attribute, in long form, and if no conversion can occur, returns the supplied default value.

Parameters:
defaultValue - long default.
Returns:
long value of attribute.

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(float defaultValue)

This gets the value of the attribute, in float form, and if no conversion can occur, returns the supplied default value.

Parameters:
defaultValue - float default.
Returns:
float value of attribute.

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(double defaultValue)

This gets the value of the attribute, in double form, and if no conversion can occur, returns the supplied default value.

Parameters:
defaultValue - double default.
Returns:
double value of attribute.

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(boolean defaultValue)

This gets the value of the attribute, in boolean form, and if no conversion can occur, returns the supplied default value.

Parameters:
defaultValue - boolean default.
Returns:
boolean value of attribute.

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.

getCharValue

public char getCharValue(char defaultValue)

This gets the value of the attribute, in char form, and if no conversion can occur, returns the supplied default value.

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

getCharValue

public char getCharValue()
                  throws DataConversionException

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

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

getByteValue

public byte getByteValue(byte defaultValue)

This gets the value of the attribute, in byte form, and if no conversion can occur, returns the supplied default value.

Parameters:
defaultValue - byte default.
Returns:
byte value of attribute.

getByteValue

public byte getByteValue()
                  throws DataConversionException

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

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


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