|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection
java.util.AbstractList
com.dautelle.xml.XmlElement
This class represents a XML element. Instances of this class are made available only during the XML serialization/deserialization process.
During serialization, XML elements are used to define the XML mapping of
Java objects (ref. Representable
interface).
During deserialization, XML elements are restored and are converted
to Java objects using the factory method:
where the static Object elementName.valueOf(XmlElement xml)
xml
parameter contains the attributes
(CharSequence
) as well as all the inners objects
(Representable
) recursively created from the XML document.
ObjectWriter
,
Constructor
Field Summary |
Fields inherited from class java.util.AbstractList |
modCount |
Method Summary | |
void |
add(int index,
java.lang.Object object)
Inserts the specified object at the specified position in this XML element. |
void |
add(Representable element)
Appends the specified nested element to this XmlElement . |
boolean |
addAll(Representable[] elements)
Appends the specified nested elements to this XmlElement . |
java.util.Iterator |
attributeNames()
Returns an iterator over the names of all the attributes being set for this XML element. |
java.lang.Object |
get(int index)
Returns the object contained by this XML element at the specified position. |
java.lang.CharSequence |
getAttribute(java.lang.CharSequence name)
Searches for the specified attribute (generic). |
boolean |
getAttribute(java.lang.String name,
boolean defaultValue)
Returns the specified boolean attribute. |
double |
getAttribute(java.lang.String name,
double defaultValue)
Returns the specified double attribute. |
Enum |
getAttribute(java.lang.String name,
Enum defaultValue)
Searches for the specified Enum attribute. |
float |
getAttribute(java.lang.String name,
float defaultValue)
Returns the specified float attribute. |
int |
getAttribute(java.lang.String name,
int defaultValue)
Returns the specified int attribute. |
long |
getAttribute(java.lang.String name,
long defaultValue)
Returns the specified long attribute. |
java.lang.String |
getAttribute(java.lang.String name,
java.lang.String defaultValue)
Searches for the specified String attribute. |
java.lang.Class |
getFactoryClass()
Sets the factory class for this XML element. |
XmlElement |
getParent()
Returns the parent of this XML element (container element). |
boolean |
isAttribute(java.lang.CharSequence name)
Indicates if the specified attribute is present. |
boolean |
isEmpty()
Indicates if this XML element is empty. |
java.lang.StringBuffer |
newAttribute(java.lang.CharSequence name)
Creates a new attribute for this XmlElement and returns the
StringBuffer holding the attribute's value. |
java.lang.Object |
newInstance()
Convenience method equivalent to getFactoryClass().newInstance() . |
java.lang.Object |
remove(int index)
Removes the object at the specified position in this list XML element. |
java.lang.Object |
set(int index,
java.lang.Object object)
Replaces the specified object at the specified position in this XML element. |
void |
setAttribute(java.lang.CharSequence name,
java.lang.CharSequence value)
Sets the specified attribute (generic). |
void |
setAttribute(java.lang.String name,
boolean value)
Sets the specified boolean attribute. |
void |
setAttribute(java.lang.String name,
double value)
Sets the specified double attribute. |
void |
setAttribute(java.lang.String name,
Enum value)
Sets the specified Enum attribute. |
void |
setAttribute(java.lang.String name,
float value)
Sets the specified float attribute. |
void |
setAttribute(java.lang.String name,
int value)
Sets the specified int attribute. |
void |
setAttribute(java.lang.String name,
long value)
Sets the specified long attribute. |
void |
setFactoryClass(java.lang.Class factoryClass)
Sets the factory class to use for deserialization (identified by the XML element tag name). |
int |
size()
Returns the number of nested element contained in this XML element. |
Methods inherited from class java.util.AbstractList |
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList |
Methods inherited from class java.util.AbstractCollection |
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray |
Method Detail |
public java.lang.StringBuffer newAttribute(java.lang.CharSequence name)
XmlElement
and returns the
StringBuffer
holding the attribute's value.
Note: This method allows for custom formatting of attribute's values
without allocating temporary String
objects.
For example:
// Formats an attribute in hexadecimal. TypeFormat.format(intValue, 16, xml.newAttribute(name));
name
- the attributes' name.
StringBuffer
to hold the attribute's value.public void setAttribute(java.lang.CharSequence name, java.lang.CharSequence value)
name
- the attributes' name.value
- the attributes' value.public void setAttribute(java.lang.String name, Enum value)
Enum
attribute.
name
- the name of the attribute.value
- the Enum
for the specified attribute.getAttribute(String, Enum)
public void setAttribute(java.lang.String name, boolean value)
boolean
attribute.
name
- the name of the attribute.value
- the boolean
value for the specified attribute.getAttribute(String, boolean)
public void setAttribute(java.lang.String name, int value)
int
attribute.
name
- the name of the attribute.value
- the int
value for the specified attribute.getAttribute(String, int)
public void setAttribute(java.lang.String name, long value)
long
attribute.
name
- the name of the attribute.value
- the long
value for the specified attribute.getAttribute(String, long)
public void setAttribute(java.lang.String name, float value)
float
attribute.
name
- the name of the attribute.value
- the float
value for the specified attribute.getAttribute(String, float)
public void setAttribute(java.lang.String name, double value)
double
attribute.
name
- the name of the attribute.value
- the double
value for the specified attribute.getAttribute(String, double)
public void setFactoryClass(java.lang.Class factoryClass)
factoryClass
- the class to use for deserialization.public XmlElement getParent()
null
if this element
is a root element.public java.util.Iterator attributeNames()
CharSequence
objects).public boolean isAttribute(java.lang.CharSequence name)
name
- the name of the attribute.
true
if this xml element contains the specified
attribute; false
otherwise.public java.lang.CharSequence getAttribute(java.lang.CharSequence name)
name
- the name of the attribute.
null
if not found.setAttribute(CharSequence, CharSequence)
public java.lang.String getAttribute(java.lang.String name, java.lang.String defaultValue)
String
attribute.
name
- the name of the attribute.defaultValue
- a default value.
String
value for the specified attribute or
the defaultValue
if the attribute is not found.public Enum getAttribute(java.lang.String name, Enum defaultValue)
Enum
attribute.
name
- the name of the attribute.defaultValue
- a default value which also identifies the
enumeration.
Enum
for the specified attribute or
the defaultValue
if the attribute is not found.public boolean getAttribute(java.lang.String name, boolean defaultValue)
boolean
attribute.
name
- the name of the attribute searched for.defaultValue
- the value returned if the attribute is not found.
boolean
value for the specified attribute or
the default value if the attribute is not found.public int getAttribute(java.lang.String name, int defaultValue)
int
attribute. This method handles
string formats that are used to represent octal and hexadecimal numbers.
name
- the name of the attribute searched for.defaultValue
- the value returned if the attribute is not found.
int
value for the specified attribute or
the default value if the attribute is not found.public long getAttribute(java.lang.String name, long defaultValue)
long
attribute. This method handles
string formats that are used to represent octal and hexadecimal numbers.
name
- the name of the attribute searched for.defaultValue
- the value returned if the attribute is not found.
long
value for the specified attribute or
the default value if the attribute is not found.public float getAttribute(java.lang.String name, float defaultValue)
float
attribute.
name
- the name of the attribute searched for.defaultValue
- the value returned if the attribute is not found.
float
value for the specified attribute or
the default value if the attribute is not found.public double getAttribute(java.lang.String name, double defaultValue)
double
attribute.
name
- the name of the attribute searched for.defaultValue
- the value returned if the attribute is not found.
double
value for the specified attribute or
the default value if the attribute is not found.public java.lang.Class getFactoryClass()
setFactoryClass(java.lang.Class)
public java.lang.Object newInstance() throws ConstructorException
getFactoryClass().newInstance()
.
Typically, this method is used to provide a default XML factory method
inherited by sub-classes. For example:
abstract class TopClass { public static TopClass valueOf(XmlElement xml) { TopClass instance = (TopClass) xml.newInstance(); ... // Initializes instance from xml. return instance; } }
ConstructorException
- if the instance cannot be created.public void add(Representable element)
XmlElement
.
element
- the nested element to be inserted.public boolean addAll(Representable[] elements)
XmlElement
.
elements
- the nested elements being appended.
true
if this XmlElement
changed as a result
of this call; false
otherwise.public java.lang.Object get(int index)
Note: Typically the object returned is a Representable
,
but it does not have to be if the class is deserializable
only (XML document created externally).
index
- the index of the object to return.
java.lang.IndexOutOfBoundsException
- if the given index is out of range
(index < 0 || index >= size()
).public java.lang.Object set(int index, java.lang.Object object)
index
- index of the object to replace.object
- the object to be stored at the specified position.
java.lang.ClassCastException
- if this specified object is not a
Representable
.
java.lang.IndexOutOfBoundsException
- if the specified index is out of
range (index < 0 || index >= size()
).public void add(int index, java.lang.Object object)
index
- index at which the specified object is to be inserted.object
- the object to be inserted.
java.lang.ClassCastException
- if this specified object is not a
Representable
.
java.lang.IndexOutOfBoundsException
- if the specified index is out of
range (index < 0 || index > size()
).public java.lang.Object remove(int index)
index
- the index of the object to remove.
java.lang.IndexOutOfBoundsException
- if the specified index is out of
range (index < 0 || index >= size()
).public int size()
public boolean isEmpty()
<className .../>
true
if this element has no content;
false
otherwise.
|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |