|
DLESE Tools v1.6.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dlese.dpc.xml.XMLNode
public class XMLNode
Creates an object wrapper for JDOM XML elements and for accessing
their content. The primary purpose of this class is to provide
object mapping between the JDOM tree hierarchy and the HashMap maintained
by XMLRecord
. Child and parent relationships in the XML
element hierarchy are mirrored by the XMLNode
structure.
The path strings created and maintained by this class reflect the path
that would be traversed through the JDOM tree hierarchy to reach the
wrapped element. Path strings are extended as nodes are added, by
appending the element's name and its number of occurrence. The path
strings then serve as keys to the map maintained by XMLRecord
.
Here is an example path:
record:0.technical:0.requirements:1.type:0.langstring:0
This path identifies the type langstring element belonging to the 2nd technical requirement of the root element record. Here is the corresponding XML:
<record> ... <technical> ... <requirements> <type> <langstring /> </type> ... </requirements> <requirements> <type> <langstring>THIS IS THE ONE</langstring> </type> ... </requirements> ... <technical> ... <record>
By knowing the path structure, a calling method may ask XMLRecord
for any node anywhere in the hierarchy. The node then provides the caller
with convenient access methods to the element and its attributes.
Field Summary | |
---|---|
protected ArrayList |
children
List of child nodes. |
protected org.jdom.Element |
element
The JDOM XML element this node wraps. |
protected int |
occurs
Identifies the nth occurence of this node in the parent's children array. |
protected XMLNode |
parent
The parent node of this one. |
protected String |
path
Identifies the location in the JDOM hierarchy of the wrapped XML element. |
Constructor Summary | |
---|---|
XMLNode(org.jdom.Element element)
Constructor wraps a JDOM Element with a new node. |
|
XMLNode(org.jdom.Element element,
boolean setNormalize)
Constructor wraps a JDOM Element with a new node. |
Method Summary | |
---|---|
void |
addChild(XMLNode node)
Adds a child node to this one at the correct location, and sets the path. |
void |
addComment(String value)
Adds a comment to the element of this node. |
void |
clear()
|
protected int |
findPlace(XMLNode node)
Finds the place where a new node should be inserted. |
String |
getAttribute(String attName)
Retrieves a named attribute from the element of this node, if the attribute exists. |
XMLNode |
getChild(int index)
Gets the child node that lives at a specific index of this node's children array. |
List |
getChildren()
Gets the list of children belonging to this node. |
String |
getComment(String identifier)
Gets an identified comment from the element of this node, if it exists. |
List |
getComments()
Gets all the comments belonging to the element of this node. |
org.jdom.Element |
getElement()
Retrieves the element of this node. |
List |
getLikeChildren(String name)
|
String |
getName()
Retrieves the name of the element of this node. |
XMLNode |
getParent()
Retrieve the node's parent node, which is null if this node wraps the root element. |
String |
getPath()
Returns the path which maps this node's element location in the JDOM tree hierarchy. |
String |
getValue()
Retrieves the textual content of the element of this node. |
boolean |
isLeaf()
Tests whether this node wraps a leaf element, which is useful for knowing how to add content. |
boolean |
isRoot()
Tests whether this node wraps the JDOM document root element. |
int |
likeChildren(String nodeName)
Searches the children nodes for an element name and returns the number found. |
boolean |
removeComment(String identifier)
Removes the first identified comment from the element of this node, if one exists. |
void |
setAttribute(String attName,
String value)
Sets the value of an attribute for the element of this node. |
void |
setPath(String parentPath)
Appends this node's name and number of occurrence to a path. |
void |
setValue(String value)
Sets the textual content of the element of this node, if it is a leaf element. |
String |
toString()
Retrieves the name of the element of this node. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected String path
protected ArrayList children
protected int occurs
protected org.jdom.Element element
protected XMLNode parent
Constructor Detail |
---|
public XMLNode(org.jdom.Element element)
element
- JDOM element to be wrapped.public XMLNode(org.jdom.Element element, boolean setNormalize)
element
- JDOM element to be wrapped.Method Detail |
---|
public XMLNode getParent()
public void clear()
public void addChild(XMLNode node)
node
- The node to add.public XMLNode getChild(int index)
NOTE: no bounds checking is done in this implementation.
index
- An integer identifying the index of the node to return.
public List getChildren()
List
containing all the children of this node.public List getLikeChildren(String name)
public int likeChildren(String nodeName)
nodeName
- The name to search for.
protected int findPlace(XMLNode node)
node
- The XMLNode to find the placement for.
public String getPath()
public void setPath(String parentPath)
parentPath
- The path of the node which is or will be this node's
parent.public void addComment(String value)
value
- String comment to be added.public String getComment(String identifier)
identifier
- String to match as an identifier.
public List getComments()
public boolean removeComment(String identifier)
identifier
- String to match as an identifier.
public boolean isRoot()
public boolean isLeaf()
public String toString()
toString
in class Object
public String getName()
public org.jdom.Element getElement()
public String getValue()
NOTE: This implementation is built on JDOM 4, which provides weak access for reading and writing element content. JDOM 5 has deprecated this approach, and JDOM 6 is even more flexible and robust. Future implementations of this class should reflect the updates in JDOM.
public void setValue(String value)
NOTE: This implementation is built on JDOM 4, which provides weak access for reading and writing element content. JDOM 5 has deprecated this approach, and JDOM 6 is even more flexible and robust. Future implementations of this class should reflect the updates in JDOM.
value
- The text to set as content for the element of this node.public String getAttribute(String attName)
attName
- The name of the attribute to retrieve.
public void setAttribute(String attName, String value)
attName
- The name of the attribute to set.value
- The value to assign to the attribute.
|
DLESE Tools v1.6.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |