|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jboss.mq.xml.XElement
XElement provides an interface to an XML element. An XElement represents an
XML element which contains:
It is important to understand the diffrence between an "field" XElement and
a non "field" XElement. If an XElement does not contain any sub elements, it
is considered a "field" XElement. The getField(String)
and
getValue()
functions will throw an XElementException if they
are used on non "attribute" objects. This give you a little bit type
checking (You'll get an exception if you try to access the character data of
an element that has sub elements).
If XElement is not an field, then it contains other XElements and optionaly
some text. The text data can be accessed with the getText()
method and the sub elements with the iterator()
or with
getElementXXX()
fuctions. Since XML and thus XElements provide a tree
type data structure, traversing the tree to access leaf data can be
cumbersom if you have a 'deep' tree. For example, you may have to do:
element.getElement("tree").getElement("branch").getElement("leaf")
access a XElement 3 levels deep in the tree. To access deep elements easier,
XElements lets you use 'reletive' names to access deep elements. Using
reletive names, you could access the same element in previous example doing:
element.getElement("tree/branch/leaf")
When using relative
names, keep in mind that "." will get the current XElement, and ".." will
get parent XElement. Very similar to how URLs work.
Constructor Summary | |
XElement(String objectName)
Constructs an empty object. |
|
XElement(String objectName,
Attributes atts)
Constructs an XElement with it's parent and metatags set. |
Method Summary | |
void |
add(String data)
Adds and appends string data to the objects text. |
void |
addElement(XElement subObject)
Adds an XElement to the set of XElements that are contained by this object. |
void |
addField(String key,
String value)
Adds an XElement to the set of XElements that are contained by this object. |
boolean |
containsElement(String objectName)
Tests to see if this object contains the specified object. |
boolean |
containsField(String objectName)
Tests to see if this object contains the specified attribute object. |
static XElement |
createFrom(InputStream is)
Constructs an empty object. |
static XElement |
createFrom(URL url)
Constructs an empty object. |
Enumeration |
elements()
|
String |
getAttribute(String key)
Returns the value of a meta data value. |
XElement |
getElement(String relativeName)
Returns the first object contained in this object named relativeName. |
Enumeration |
getElementsNamed(String relativeName)
Returns all the contained objects with the specified name. |
String |
getField(String objectName)
Gets the value of a contained attribute object. |
String |
getName()
Returns the element name (tag name) of this XElement |
String |
getOptionalField(String field)
|
XElement |
getParent()
Get the parent of this object, or the object the contains this one. |
String |
getText()
Gets the TRIMMED character data that was within this object. |
String |
getValue()
Gets the character data that was within this object. |
boolean |
isField()
Returns true if the object is an attribute object. |
void |
removeFromParent()
Removes this XElement from the parent. |
void |
setAttribute(String key,
String value)
Sets/Adds a metatag value Only metatags whose value is not empty will display when the toString() methods is called. |
void |
setField(String key,
String value)
Sets/Adds a attribute |
void |
setName(String newName)
Sets the object name |
void |
setOptionalField(String field,
String value)
|
void |
setValue(String value)
Gets the character data that was within this object. |
String |
toString()
Serializes this object into a string. |
String |
toString(int nestingLevel,
boolean indent)
Serializes this object into a string. |
String |
toXML(boolean indent)
Serializes this object into a XML document String. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public XElement(String objectName)
objectName
- the tag or element name that this object represents.public XElement(String objectName, Attributes atts)
objectName
- the tag or element name that this object represents.atts
- Description of ParameterMethod Detail |
public void setAttribute(String key, String value)
toString()
methods is called.
key
- the name of the metatagvalue
- the value to set the metatag to.public void setName(String newName)
newName
- public void setValue(String value) throws XElementException
value
- The new Value value
XElementException
- if the object was not an attribute objectpublic void setField(String key, String value) throws XElementException
key
- the name of the attribute elementvalue
- the value to set the attribute to.
XElementException
- Description of Exceptionpublic String getAttribute(String key)
key
- Description of Parameter
public String getName()
public XElement getParent()
public String getText()
public String getValue() throws XElementException
XElementException
- if the object was not an attribute objectpublic XElement getElement(String relativeName) throws XElementException
relativeName
- The name of the object to find
XElementException
- if the object could not be found.public String getField(String objectName) throws XElementException
objectName
- The name of the attribute object.
XElementException
- if the object does not exist or if its not an
attribute object.public boolean isField()
public Enumeration getElementsNamed(String relativeName)
relativeName
- The name of the objects
public void add(String data)
data
- Description of Parameterpublic String toString()
public void addElement(XElement subObject)
subObject
- public void addField(String key, String value)
key
- The feature to be added to the Field attributevalue
- The feature to be added to the Field attributepublic boolean containsElement(String objectName)
objectName
- The name of the object.
public boolean containsField(String objectName)
objectName
- The name of the attribute object.
public String toString(int nestingLevel, boolean indent)
nestingLevel
- how many tabs to prepend to outputindent
- Description of Parameter
public String toXML(boolean indent)
indent
- Description of Parameter
public void removeFromParent() throws XElementException
XElementException
- if the object did not have a parentpublic Enumeration elements()
public static XElement createFrom(InputStream is) throws XElementException, IOException
is
- Description of Parameter
XElementException
- Description of Exception
IOException
- Description of Exceptionpublic static XElement createFrom(URL url) throws XElementException, IOException
url
- Description of Parameter
XElementException
- Description of Exception
IOException
- Description of Exceptionpublic String getOptionalField(String field) throws XElementException
XElementException
public void setOptionalField(String field, String value) throws XElementException
XElementException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |