|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.cbse.jeasy.JENode
public class JENode
JENode implements a XML structure as a TreeNode.
A JENode may be created by the SAX parser JESaxParser.parse2tree(...) or may be created by initialization.
A JENode contains of JEElements as userObjects.
These JEElements contain the tag name, the attributes and the value of the XML tag.
See a demonstration in the program JEasyExample tab "TreeNode".
| Field Summary | |
|---|---|
protected boolean |
allowsChildren
true if the node is able to have children |
static int |
CDATA
|
protected java.util.Vector |
children
array of children, may be null if this node has no children |
static int |
COMMENT
|
static java.util.Enumeration |
EMPTY_ENUMERATION
An enumeration that is always empty. |
static java.lang.String |
nextline
nextline Line separator xmlversion XML version |
protected JENode |
parent
this node's parent, or null if this node has no parent |
protected java.lang.Object |
userObject
optional user object |
static java.lang.String |
xmlversion
|
| Constructor Summary | |
|---|---|
JENode()
Creates a tree node that has no parent and no children, but which allows children. |
|
JENode(java.lang.Object userObject)
Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object. |
|
JENode(java.lang.Object userObject,
boolean allowsChildren)
Creates a tree node with no parent, no children, initialized with the specified user object, and that allows children only if specified. |
|
JENode(java.lang.String tagname)
Creates a tree node that has an XML tag |
|
JENode(java.lang.String tagname,
java.util.HashMap hm)
Creates a tree node that has an XML tag and attributes |
|
JENode(java.lang.String tagname,
java.lang.String data)
Creates a tree node that has an XML tag and data |
|
JENode(java.lang.String tagname,
java.lang.String data,
java.util.HashMap hm)
Creates a tree node that has an XML tag with attributes and data |
|
JENode(java.lang.String tagname,
java.lang.String data,
int typ)
Creates a tree node that has an XML tag and data as CDATA or COMMENT |
|
JENode(java.lang.String tagname,
java.lang.String data,
int typ,
java.util.HashMap hm)
Creates a tree node that has an XML tag with attributes and data |
|
| Method Summary | |
|---|---|
void |
add(JENode newChild)
Removes newChild from its parent and makes it a child of
this node by adding it to the end of this node's child array. |
java.util.Enumeration |
children()
Creates and returns a forward-order enumeration of this node's children. |
java.lang.Object |
clone()
Creates a new JENode out of an existing JENode. |
java.util.Vector |
getAllNodes(java.lang.String tagName)
Gets a Vector of all JENodes with the given tagName |
java.util.Vector |
getAllNodesWithAttribute(java.lang.String attributeName,
java.lang.String attributeValue)
Gets a Vector of all JENodes with the given Attribute |
boolean |
getAllowsChildren()
|
javax.swing.tree.TreeNode |
getChildAt(int index)
Returns the child at the specified index in this node's child array. |
int |
getChildCount()
Returns the number of children of this node. |
JEElement |
getElement()
Returns this node's user object JEElement. |
JEElement |
getElement(java.lang.String tagName)
Gets the JEElement with the given tagName inside the given JENode. |
java.lang.String |
getElementData(java.lang.String tagName)
Gets the text of the JEElement with the given tagName inside the given JENode. |
java.util.Vector |
getElementVector(java.lang.String tagName)
Gets a Vector of all Sub-Element data with the given tagName |
int |
getIndex(javax.swing.tree.TreeNode aChild)
Returns the index of the specified child in this node's child array. |
JENode |
getNode(java.lang.String tagName)
Gets the JENode with the given tagName inside the given JENode. |
JENode |
getNode(java.lang.String child,
java.lang.String subChild)
Looks for a childnode with the name child and there for the child equals subChild |
JENode |
getNodeByTag(java.lang.String element,
java.lang.String subelement,
java.lang.String subelementText)
Gets a node with name equals element and its subelement and its value is subelementText |
java.lang.String |
getNodeName()
Gets the name of the JENoden, which is the name of the JEElement |
java.util.Vector |
getNodes(java.lang.String tagName)
Gets a Vector of all children JENodes with the given tagName |
javax.swing.tree.TreeNode |
getParent()
Returns this node's parent or null if this node has no parent. |
java.lang.Object |
getUserObject()
Returns this node's user object. |
void |
insert(JENode newChild,
int childIndex)
Removes newChild from its present parent (if it has a
parent), sets the child's parent to this node, and then adds the child to
this node's child array at index childIndex. |
boolean |
isLeaf()
Returns true if this node has no children. |
boolean |
isNodeAncestor(javax.swing.tree.TreeNode anotherNode)
Returns true if anotherNode is an ancestor of this node --
if it is this node, this node's parent, or an ancestor of this node's
parent. |
boolean |
isNodeChild(javax.swing.tree.TreeNode aNode)
Returns true if aNode is a child of this node. |
static void |
main(java.lang.String[] args)
|
protected void |
recToString(java.lang.StringBuffer sb,
JENode jen,
int depth)
|
void |
remove(int childIndex)
Removes the child at the specified index from this node's children and sets that node's parent to null. |
void |
remove(JENode aChild)
Removes aChild from this node's child array, giving it a
null parent. |
void |
setElement(JEElement userObject)
Sets the user object for this node to userObject. |
void |
setParent(JENode newParent)
Sets this node's parent to newParent but does not change the parent's child array. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int CDATA
public static final int COMMENT
public static final java.util.Enumeration EMPTY_ENUMERATION
public static final java.lang.String nextline
public static final java.lang.String xmlversion
protected boolean allowsChildren
protected java.util.Vector children
protected JENode parent
protected transient java.lang.Object userObject
| Constructor Detail |
|---|
public JENode()
public JENode(java.lang.Object userObject)
userObject - an Object provided by the user that constitutes the node's
data
public JENode(java.lang.Object userObject,
boolean allowsChildren)
userObject - an Object provided by the user that constitutes the node's
dataallowsChildren - if true, the node is allowed to have child nodes -- otherwise,
it is always a leaf nodepublic JENode(java.lang.String tagname)
public JENode(java.lang.String tagname,
java.util.HashMap hm)
public JENode(java.lang.String tagname,
java.lang.String data)
public JENode(java.lang.String tagname,
java.lang.String data,
java.util.HashMap hm)
public JENode(java.lang.String tagname,
java.lang.String data,
int typ)
public JENode(java.lang.String tagname,
java.lang.String data,
int typ,
java.util.HashMap hm)
| Method Detail |
|---|
public static void main(java.lang.String[] args)
public java.lang.Object clone()
clone in class java.lang.Objectjen -
public void add(JENode newChild)
newChild from its parent and makes it a child of
this node by adding it to the end of this node's child array.
newChild - node to add as a child of this node
java.lang.IllegalArgumentException - if newChild is null
java.lang.IllegalStateException - if this node does not allow childreninsert(de.cbse.jeasy.JENode, int)public java.util.Enumeration children()
children in interface javax.swing.tree.TreeNodepublic boolean getAllowsChildren()
getAllowsChildren in interface javax.swing.tree.TreeNodepublic javax.swing.tree.TreeNode getChildAt(int index)
getChildAt in interface javax.swing.tree.TreeNodeindex - an index into this node's child array
java.lang.ArrayIndexOutOfBoundsException - if index is out of boundspublic int getChildCount()
getChildCount in interface javax.swing.tree.TreeNodepublic JEElement getElement()
#setUserObject,
toString()public JEElement getElement(java.lang.String tagName)
jn - tagName -
public java.lang.String getElementData(java.lang.String tagName)
jn - tagName -
public java.util.Vector getElementVector(java.lang.String tagName)
tagName -
public int getIndex(javax.swing.tree.TreeNode aChild)
-1.
This method performs a linear search and is O(n) where n is the number of
children.
getIndex in interface javax.swing.tree.TreeNodeaChild - the TreeNode to search for among this node's children
-1 if the specified node is a not a child of
this node
java.lang.IllegalArgumentException - if aChild is nullpublic JENode getNode(java.lang.String tagName)
jn - tagName -
public JENode getNodeByTag(java.lang.String element,
java.lang.String subelement,
java.lang.String subelementText)
element - subelement - subelementText -
public JENode getNode(java.lang.String child,
java.lang.String subChild)
child - subChild -
public java.lang.String getNodeName()
public java.util.Vector getNodes(java.lang.String tagName)
tagName -
public java.util.Vector getAllNodes(java.lang.String tagName)
tagName -
public java.util.Vector getAllNodesWithAttribute(java.lang.String attributeName,
java.lang.String attributeValue)
v - attributeName - attributeValue -
public javax.swing.tree.TreeNode getParent()
getParent in interface javax.swing.tree.TreeNodepublic java.lang.Object getUserObject()
#setUserObject,
toString()
public void insert(JENode newChild,
int childIndex)
newChild from its present parent (if it has a
parent), sets the child's parent to this node, and then adds the child to
this node's child array at index childIndex.
newChild must not be null and must not be an ancestor of
this node.
newChild - the MutableTreeNode to insert under this nodechildIndex - the index in this node's child array where this node is to be
inserted
java.lang.ArrayIndexOutOfBoundsException - if childIndex is out of bounds
java.lang.IllegalArgumentException - if newChild is null or is an ancestor of
this node
java.lang.IllegalStateException - if this node does not allow children#isNodeDescendantpublic boolean isLeaf()
getAllowsChildren
isLeaf in interface javax.swing.tree.TreeNodegetAllowsChildren()public boolean isNodeAncestor(javax.swing.tree.TreeNode anotherNode)
anotherNode is an ancestor of this node --
if it is this node, this node's parent, or an ancestor of this node's
parent. (Note that a node is considered an ancestor of itself.) If
anotherNode is null, this method returns false. This
operation is at worst O(h) where h is the distance from the root to this
node.
anotherNode - node to test as an ancestor of this node
anotherNode#isNodeDescendant,
#getSharedAncestorpublic boolean isNodeChild(javax.swing.tree.TreeNode aNode)
aNode is a child of this node. If
aNode is null, this method returns false.
aNode is a child of this node; false if
aNode is nullpublic void remove(int childIndex)
MutableTreeNode.
childIndex - the index in this node's child array of the child to remove
java.lang.ArrayIndexOutOfBoundsException - if childIndex is out of boundspublic void remove(JENode aChild)
aChild from this node's child array, giving it a
null parent.
aChild - a child of this node to remove
java.lang.IllegalArgumentException - if aChild is null or is not a child of this
nodepublic void setElement(JEElement userObject)
userObject.
userObject - the JEElement that constitutes this node's user-specified datagetUserObject(),
toString()public void setParent(JENode newParent)
newParent but does not change the parent's child array. This method is called from insert() and remove() to reassign a child's parent, it should not be messaged from anywhere else.
newParent - this node's new parentpublic java.lang.String toString()
toString in class java.lang.Object
protected void recToString(java.lang.StringBuffer sb,
JENode jen,
int depth)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||