javolution37.javolution.xml
Class XmlElement
- java.lang.Object
-
- javolution37.javolution.xml.XmlElement
-
public final class XmlElement extends java.lang.ObjectThis class represents a XML element. Instances of this class are made available only during the XML serialization/deserialization process.
During serialization,
XmlFormat.format(XmlElement)is used to represent the Java objects into XML.During deserialization,
XmlFormat.parse(XmlElement)is used to restore the objects from their XML representations.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description voidadd(java.lang.Object obj)Adds the specified object as an anonymous nested element of unknown type.voidadd(java.lang.Object obj, java.lang.String qName)Adds the specified object as a named nested element of unknown type (nullobjects are ignored).voidadd(java.lang.Object obj, java.lang.String qName, java.lang.Class clazz)Adds the specified object as a named nested element of known type (nullobjects are ignored).voidadd(java.lang.Object obj, java.lang.String qName, XmlFormat xmlFormat)Deprecated.Replaced byadd(Object, String, Class)ContentHandlerformatter()Returns the content handler used during serialization (typically aWriterHandler).<T> Tget(java.lang.String qName)Returns the object corresponding to the next nested element only if it has the specified qualified name.<T> Tget(java.lang.String qName, java.lang.Class clazz)Returns the object corresponding to the next nested element only if it has the specified qualified name; the object type is identified by the specified class parameter.<T> Tget(java.lang.String qName, XmlFormat xmlFormat)Deprecated.Replaced byget(String, Class)java.lang.CharSequencegetAttribute(java.lang.String name)Searches for the attribute having the specified name.booleangetAttribute(java.lang.String name, boolean defaultValue)Returns the specifiedbooleanattribute.java.lang.BooleangetAttribute(java.lang.String name, java.lang.Boolean defaultValue)Searches for the specifiedBooleanattribute.java.lang.BytegetAttribute(java.lang.String name, java.lang.Byte defaultValue)Searches for the specifiedByteattribute.java.lang.CharSequencegetAttribute(java.lang.String name, java.lang.CharSequence defaultValue)Returns the specifiedCharSequenceattribute.doublegetAttribute(java.lang.String name, double defaultValue)Returns the specifieddoubleattribute.java.lang.DoublegetAttribute(java.lang.String name, java.lang.Double defaultValue)Searches for the specifiedDoubleattribute.floatgetAttribute(java.lang.String name, float defaultValue)Returns the specifiedfloatattribute.java.lang.FloatgetAttribute(java.lang.String name, java.lang.Float defaultValue)Searches for the specifiedFloatattribute.intgetAttribute(java.lang.String name, int defaultValue)Returns the specifiedintattribute.java.lang.IntegergetAttribute(java.lang.String name, java.lang.Integer defaultValue)Searches for the specifiedIntegerattribute.longgetAttribute(java.lang.String name, long defaultValue)Returns the specifiedlongattribute.java.lang.LonggetAttribute(java.lang.String name, java.lang.Long defaultValue)Searches for the specifiedLongattribute.java.lang.ShortgetAttribute(java.lang.String name, java.lang.Short defaultValue)Searches for the specifiedShortattribute.java.lang.StringgetAttribute(java.lang.String name, java.lang.String defaultValue)Returns the specifiedStringattribute.AttributesgetAttributes()Returns the attributes for this xml element (parsing or formatting).FastListgetContent()Deprecated.Formats should usegetNext()andhasNext()to parse anonymous content andadd(Object)to serialize anonymous content.<T> TgetNext()Returns the object corresponding to the next nested element.booleanhasNext()Indicates if more nested elements can be read.booleanisAttribute(java.lang.String name)Indicates if the specified attribute is present.TextBuildernewAttribute(java.lang.String name)Creates a new attribute for this xml element.<T> Tobject()Returns the object corresponding to this xml element; this is the object which has beenallocatedby the xml format or using the public no-arg constructor ofobjectClass().java.lang.ClassobjectClass()Returns the Java(tm) class corresponding to this XML element; the class is identified by the tag name of this xml element or the"j:class" attribute when present.XmlPullParserparser()Returns the pull parser used during deserialization.voidremoveAttribute(java.lang.String name)Removes the specified attribute.voidsetAttribute(java.lang.String name, boolean value)Sets the specifiedbooleanattribute.voidsetAttribute(java.lang.String name, java.lang.Boolean value)Sets the specifiedBooleanattribute.voidsetAttribute(java.lang.String name, java.lang.Byte value)Sets the specifiedByteattribute.voidsetAttribute(java.lang.String name, java.lang.CharSequence value)Sets the specifiedCharSequenceattribute (nullvalues are ignored).voidsetAttribute(java.lang.String name, double value)Sets the specifieddoubleattribute.voidsetAttribute(java.lang.String name, java.lang.Double value)Sets the specifiedDoubleattribute.voidsetAttribute(java.lang.String name, float value)Sets the specifiedfloatattribute.voidsetAttribute(java.lang.String name, java.lang.Float value)Sets the specifiedFloatattribute.voidsetAttribute(java.lang.String name, int value)Sets the specifiedintattribute.voidsetAttribute(java.lang.String name, java.lang.Integer value)Sets the specifiedIntegerattribute.voidsetAttribute(java.lang.String name, long value)Sets the specifiedlongattribute.voidsetAttribute(java.lang.String name, java.lang.Long value)Sets the specifiedLongattribute.voidsetAttribute(java.lang.String name, java.lang.Short value)Sets the specifiedShortattribute.voidsetAttribute(java.lang.String name, java.lang.String value)Sets the specifiedStringattribute (nullvalues are ignored).
-
-
-
Method Detail
-
object
public <T> T object() throws XmlExceptionReturns the object corresponding to this xml element; this is the object which has beenallocatedby the xml format or using the public no-arg constructor ofobjectClass().- Returns:
- the (uninitialized) object corresponding to this xml element.
- Throws:
XmlException
-
objectClass
public java.lang.Class objectClass()
Returns the Java(tm) class corresponding to this XML element; the class is identified by the tag name of this xml element or the"j:class" attribute when present.- Returns:
- this XML element's corresponding class.
-
formatter
public ContentHandler formatter()
Returns the content handler used during serialization (typically aWriterHandler).- Returns:
- the content handler receiving the SAX-2 events.
-
add
public void add(java.lang.Object obj)
Adds the specified object as an anonymous nested element of unknown type.- Parameters:
obj- the object added as nested element ornull.
-
add
public void add(java.lang.Object obj, java.lang.String qName)Adds the specified object as a named nested element of unknown type (nullobjects are ignored). The nested xml element will contain a "j:class" attribute identifying the object type.- Parameters:
obj- the object added as nested element ornull.qName- the qualified name of the nested element.
-
add
public void add(java.lang.Object obj, java.lang.String qName, java.lang.Class clazz)Adds the specified object as a named nested element of known type (nullobjects are ignored).- Parameters:
obj- the object added as nested element ornull.qName- the qualified name of the nested element.clazz- the class identifying the xml format to use.
-
newAttribute
public TextBuilder newAttribute(java.lang.String name)
Creates a new attribute for this xml element. This method allows for custom attribute formatting. For example:// Formats the color RGB value in hexadecimal. xml.newAttribute("color").append(_color.getRGB(), 16); // Formats the error using 4 digits. xml.newAttribute("error").append(error, 4, false, false);- Parameters:
name- the attribute name.- Returns:
- the text builder to hold the attribute value.
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.CharSequence value)Sets the specifiedCharSequenceattribute (nullvalues are ignored).- Parameters:
name- the attribute name.value- the attribute value ornull.
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.String value)Sets the specifiedStringattribute (nullvalues are ignored).- Parameters:
name- the attribute name.value- the attribute value.
-
setAttribute
public void setAttribute(java.lang.String name, boolean value)Sets the specifiedbooleanattribute.- Parameters:
name- the attribute name.value- thebooleanvalue for the specified attribute.- See Also:
getAttribute(String, boolean)
-
setAttribute
public void setAttribute(java.lang.String name, int value)Sets the specifiedintattribute.- Parameters:
name- the attribute name.value- theintvalue for the specified attribute.- See Also:
getAttribute(String, int)
-
setAttribute
public void setAttribute(java.lang.String name, long value)Sets the specifiedlongattribute.- Parameters:
name- the attribute name.value- thelongvalue for the specified attribute.- See Also:
getAttribute(String, long)
-
setAttribute
public void setAttribute(java.lang.String name, float value)Sets the specifiedfloatattribute.- Parameters:
name- the attribute name.value- thefloatvalue for the specified attribute.- See Also:
/
-
setAttribute
public void setAttribute(java.lang.String name, double value)Sets the specifieddoubleattribute.- Parameters:
name- the attribute name.value- thedoublevalue for the specified attribute.- See Also:
/
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Boolean value)Sets the specifiedBooleanattribute.- Parameters:
name- the name of the attribute.value- theBooleanvalue for the specified attribute ornullin which case the attribute is not set.- See Also:
getAttribute(String, Boolean)
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Byte value)Sets the specifiedByteattribute.- Parameters:
name- the name of the attribute.value- theBytevalue for the specified attribute ornullin which case the attribute is not set.- See Also:
getAttribute(String, Byte)
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Short value)Sets the specifiedShortattribute.- Parameters:
name- the name of the attribute.value- theShortvalue for the specified attribute ornullin which case the attribute is not set.- See Also:
getAttribute(String, Short)
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Integer value)Sets the specifiedIntegerattribute.- Parameters:
name- the name of the attribute.value- theIntegervalue for the specified attribute ornullin which case the attribute is not set.- See Also:
getAttribute(String, Integer)
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Long value)Sets the specifiedLongattribute.- Parameters:
name- the name of the attribute.value- theLongvalue for the specified attribute ornullin which case the attribute is not set.- See Also:
getAttribute(String, Long)
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Float value)Sets the specifiedFloatattribute.- Parameters:
name- the name of the attribute.value- theFloatvalue for the specified attribute ornullin which case the attribute is not set.- See Also:
/
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Double value)Sets the specifiedDoubleattribute.- Parameters:
name- the name of the attribute.value- theDoublevalue for the specified attribute ornullin which case the attribute is not set.- See Also:
/
-
removeAttribute
public void removeAttribute(java.lang.String name)
Removes the specified attribute.- Parameters:
name- the name of the attribute to remove.
-
parser
public XmlPullParser parser()
Returns the pull parser used during deserialization.- Returns:
- the pull parser.
-
hasNext
public boolean hasNext()
Indicates if more nested elements can be read.- Returns:
trueif more nested elements can be read;falseotherwise.
-
getNext
public <T> T getNext()
Returns the object corresponding to the next nested element.- Returns:
- the next nested object.
- Throws:
java.util.NoSuchElementException- ifthis.hasNext() == false
-
get
public <T> T get(java.lang.String qName)
Returns the object corresponding to the next nested element only if it has the specified qualified name.- Parameters:
qName- the nested element qualified name required.- Returns:
- the next content object or
nullif the qName does not match. - Throws:
XmlException- if the specified object has no "j:class" attribute identifying the object type.
-
get
public <T> T get(java.lang.String qName, java.lang.Class clazz)Returns the object corresponding to the next nested element only if it has the specified qualified name; the object type is identified by the specified class parameter.- Parameters:
qName- the nested element qualified name required.clazz- the class identifying the object to return.- Returns:
- the next content object or
nullif the qName does not match.
-
getAttributes
public Attributes getAttributes()
Returns the attributes for this xml element (parsing or formatting).- Returns:
- the attributes mapping.
-
getAttribute
public java.lang.CharSequence getAttribute(java.lang.String name)
Searches for the attribute having the specified name.- Parameters:
name- the qualified name of the attribute (qName).- Returns:
- the value for the specified attribute or
nullif the attribute is not found.
-
isAttribute
public boolean isAttribute(java.lang.String name)
Indicates if the specified attribute is present.- Parameters:
name- the qualified name of the attribute (qName).- Returns:
trueif this xml element contains the specified attribute;falseotherwise.
-
getAttribute
public java.lang.CharSequence getAttribute(java.lang.String name, java.lang.CharSequence defaultValue)Returns the specifiedCharSequenceattribute.- Parameters:
name- the name of the attribute.defaultValue- a default value.- Returns:
- the value for the specified attribute or
the
defaultValueif the attribute is not found.
-
getAttribute
public java.lang.String getAttribute(java.lang.String name, java.lang.String defaultValue)Returns the specifiedStringattribute.- Parameters:
name- the name of the attribute.defaultValue- a default value.- Returns:
- the value for the specified attribute or
the
defaultValueif the attribute is not found.
-
getAttribute
public boolean getAttribute(java.lang.String name, boolean defaultValue)Returns the specifiedbooleanattribute.- Parameters:
name- the name of the attribute searched for.defaultValue- the value returned if the attribute is not found.- Returns:
- the
booleanvalue for the specified attribute or the default value if the attribute is not found.
-
getAttribute
public int getAttribute(java.lang.String name, int defaultValue)Returns the specifiedintattribute. This method handles string formats that are used to represent octal and hexadecimal numbers.- Parameters:
name- the name of the attribute searched for.defaultValue- the value returned if the attribute is not found.- Returns:
- the
intvalue for the specified attribute or the default value if the attribute is not found.
-
getAttribute
public long getAttribute(java.lang.String name, long defaultValue)Returns the specifiedlongattribute. This method handles string formats that are used to represent octal and hexadecimal numbers.- Parameters:
name- the name of the attribute searched for.defaultValue- the value returned if the attribute is not found.- Returns:
- the
longvalue for the specified attribute or the default value if the attribute is not found.
-
getAttribute
public float getAttribute(java.lang.String name, float defaultValue)Returns the specifiedfloatattribute.- Parameters:
name- the name of the attribute searched for.defaultValue- the value returned if the attribute is not found.- Returns:
- the
floatvalue for the specified attribute or the default value if the attribute is not found. /
-
getAttribute
public double getAttribute(java.lang.String name, double defaultValue)Returns the specifieddoubleattribute.- Parameters:
name- the name of the attribute searched for.defaultValue- the value returned if the attribute is not found.- Returns:
- the
doublevalue for the specified attribute or the default value if the attribute is not found. /
-
getAttribute
public java.lang.Boolean getAttribute(java.lang.String name, java.lang.Boolean defaultValue)Searches for the specifiedBooleanattribute.- Parameters:
name- the name of the attribute.defaultValue- the value returned if the attribute is not found.- Returns:
- the
Booleanvalue for the specified attribute or the default value if the attribute is not found.
-
getAttribute
public java.lang.Byte getAttribute(java.lang.String name, java.lang.Byte defaultValue)Searches for the specifiedByteattribute.- Parameters:
name- the name of the attribute.defaultValue- the value returned if the attribute is not found.- Returns:
- the
Bytevalue for the specified attribute or the default value if the attribute is not found.
-
getAttribute
public java.lang.Short getAttribute(java.lang.String name, java.lang.Short defaultValue)Searches for the specifiedShortattribute.- Parameters:
name- the name of the attribute.defaultValue- the value returned if the attribute is not found.- Returns:
- the
Shortvalue for the specified attribute or the default value if the attribute is not found.
-
getAttribute
public java.lang.Integer getAttribute(java.lang.String name, java.lang.Integer defaultValue)Searches for the specifiedIntegerattribute.- Parameters:
name- the name of the attribute.defaultValue- the value returned if the attribute is not found.- Returns:
- the
Integervalue for the specified attribute or the default value if the attribute is not found.
-
getAttribute
public java.lang.Long getAttribute(java.lang.String name, java.lang.Long defaultValue)Searches for the specifiedLongattribute.- Parameters:
name- the name of the attribute.defaultValue- the value returned if the attribute is not found.- Returns:
- the
Longvalue for the specified attribute or the default value if the attribute is not found.
-
getAttribute
public java.lang.Float getAttribute(java.lang.String name, java.lang.Float defaultValue)Searches for the specifiedFloatattribute.- Parameters:
name- the name of the attribute.defaultValue- the value returned if the attribute is not found.- Returns:
- the
Floatvalue for the specified attribute or the default value if the attribute is not found. /
-
getAttribute
public java.lang.Double getAttribute(java.lang.String name, java.lang.Double defaultValue)Searches for the specifiedDoubleattribute.- Parameters:
name- the name of the attribute.defaultValue- the value returned if the attribute is not found.- Returns:
- the
Doublevalue for the specified attribute or the default value if the attribute is not found. /
-
getContent
public FastList getContent()
Deprecated. Formats should usegetNext()andhasNext()to parse anonymous content andadd(Object)to serialize anonymous content.
-
add
public void add(java.lang.Object obj, java.lang.String qName, XmlFormat xmlFormat)Deprecated. Replaced byadd(Object, String, Class)
-
get
public <T> T get(java.lang.String qName, XmlFormat xmlFormat)Deprecated. Replaced byget(String, Class)
-
-
DMelt 3.0 © DataMelt by jWork.ORG