EspressReport
v 5.5

quadbase.common.util.internal
Class XMLDefaultTreeNode

java.lang.Object
  |
  +--quadbase.common.util.internal.XMLDefaultTreeNode
All Implemented Interfaces:
java.lang.Cloneable, XMLConditionType
Direct Known Subclasses:
XMLConditionNode, XMLOperatorNode

public class XMLDefaultTreeNode
extends java.lang.Object
implements XMLConditionType, java.lang.Cloneable


Field Summary
protected  boolean allowsChildren
           
protected  java.util.Vector children
          array of children, may be null if this node has no children
static java.util.Enumeration EMPTY_ENUMERATION
          An enumeration that is always empty.
protected  XMLDefaultTreeNode parent
          this node's parent, or null if this node has no parent
protected  java.lang.Object userObject
          optional user object
 
Fields inherited from interface quadbase.common.util.internal.XMLConditionType
BETWEEN, EQUAL, GREATERTHAN, GREATERTHANOREQUAL, IN, LESSTHAN, LESSTHANOREQUAL, NOTEQUAL
 
Constructor Summary
XMLDefaultTreeNode()
          Creates a tree node that has no parent and no children, but which allows children.
XMLDefaultTreeNode(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.
XMLDefaultTreeNode(java.lang.Object userObject, boolean allowsChildren)
          Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.
 
Method Summary
 void add(XMLDefaultTreeNode 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()
           
 boolean execute()
           
 boolean getAllowsChildren()
          Returns true if this node is allowed to have children.
 XMLDefaultTreeNode 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.
 XMLFieldInfo getField(java.lang.String paramName)
           
 XMLDefaultTreeNode getFirstChild()
          Returns this node's first child.
 int getIndex(XMLDefaultTreeNode aChild)
          Returns the index of the specified child in this node's child array.
 XMLDefaultTreeNode getLastChild()
          Returns this node's last child.
 java.lang.String getName()
          Returns this node's user object.
 XMLDefaultTreeNode getParent()
          Returns this node's parent or null if this node has no parent.
 java.lang.Object getUserObject()
           
 void insert(XMLDefaultTreeNode newChild, int childIndex)
           
 boolean isExecutable()
           
 boolean isLeaf()
          Returns true if this node has no children.
 boolean isNodeChild(XMLDefaultTreeNode aNode)
          Returns true if aNode is a child of this node.
 boolean isRoot()
          Returns true if this node is the root of the tree.
 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(XMLDefaultTreeNode aChild)
          Removes aChild from this node's child array, giving it a null parent.
 void removeAllChildren()
          Removes all of this node's children, setting their parents to null.
 void removeFromParent()
          Removes the subtree rooted at this node from the tree, giving this node a null parent.
 void setName(java.lang.String userObject)
          Sets the user object for this node to userObject.
 void setParent(XMLDefaultTreeNode newParent)
          Sets this node's parent to newParent but does not change the parent's child array.
 void setUserObject(java.lang.Object userObj)
           
 java.lang.String toString()
          Returns the result of sending toString() to this node's user object, or null if this node has no user object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

protected XMLDefaultTreeNode parent
this node's parent, or null if this node has no parent

children

protected java.util.Vector children
array of children, may be null if this node has no children

allowsChildren

protected boolean allowsChildren

userObject

protected java.lang.Object userObject
optional user object

EMPTY_ENUMERATION

public static final java.util.Enumeration EMPTY_ENUMERATION
An enumeration that is always empty. This is used when an enumeration of a leaf node's children is requested.
Constructor Detail

XMLDefaultTreeNode

public XMLDefaultTreeNode()
Creates a tree node that has no parent and no children, but which allows children.

XMLDefaultTreeNode

public XMLDefaultTreeNode(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.
Parameters:
userObject - an Object provided by the user that constitutes the node's data

XMLDefaultTreeNode

public XMLDefaultTreeNode(java.lang.Object userObject,
                          boolean allowsChildren)
Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.
Parameters:
userObject - an Object provided by the user that constitutes the node's data
Method Detail

execute

public boolean execute()

isExecutable

public boolean isExecutable()
                     throws java.lang.Exception

insert

public void insert(XMLDefaultTreeNode newChild,
                   int childIndex)

remove

public void remove(int childIndex)
Removes the child at the specified index from this node's children and sets that node's parent to null. The child node to remove must be a MutableTreeNode.
Parameters:
childIndex - the index in this node's child array of the child to remove
Throws:
java.lang.ArrayIndexOutOfBoundsException - if childIndex is out of bounds

setParent

public void setParent(XMLDefaultTreeNode newParent)
Sets this node's parent to 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.
Parameters:
newParent - this node's new parent

getParent

public XMLDefaultTreeNode getParent()
Returns this node's parent or null if this node has no parent.
Returns:
this node's parent TreeNode, or null if this node has no parent

getChildAt

public XMLDefaultTreeNode getChildAt(int index)
Returns the child at the specified index in this node's child array.
Parameters:
index - an index into this node's child array
Returns:
the TreeNode in this node's child array at the specified index
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is out of bounds

getChildCount

public int getChildCount()
Returns the number of children of this node.
Returns:
an int giving the number of children of this node

getIndex

public int getIndex(XMLDefaultTreeNode aChild)
Returns the index of the specified child in this node's child array. If the specified node is not a child of this node, returns -1. This method performs a linear search and is O(n) where n is the number of children.
Parameters:
aChild - the TreeNode to search for among this node's children
Returns:
an int giving the index of the node in this node's child array, or -1 if the specified node is a not a child of this node
Throws:
java.lang.IllegalArgumentException - if aChild is null

isNodeChild

public boolean isNodeChild(XMLDefaultTreeNode aNode)
Returns true if aNode is a child of this node. If aNode is null, this method returns false.
Returns:
true if aNode is a child of this node; false if aNode is null

children

public java.util.Enumeration children()
Creates and returns a forward-order enumeration of this node's children. Modifying this node's child array invalidates any child enumerations created before the modification.
Returns:
an Enumeration of this node's children

getAllowsChildren

public boolean getAllowsChildren()
Returns true if this node is allowed to have children.
Returns:
true if this node allows children, else false

setName

public void setName(java.lang.String userObject)
Sets the user object for this node to userObject.
Parameters:
userObject - the Object that constitutes this node's user-specified data
See Also:
getName(), toString()

getName

public java.lang.String getName()
Returns this node's user object.
Returns:
the Object stored at this node by the user
See Also:
setUserObject(java.lang.Object), toString()

removeFromParent

public void removeFromParent()
Removes the subtree rooted at this node from the tree, giving this node a null parent. Does nothing if this node is the root of its tree.

remove

public void remove(XMLDefaultTreeNode aChild)
Removes aChild from this node's child array, giving it a null parent.
Parameters:
aChild - a child of this node to remove
Throws:
java.lang.IllegalArgumentException - if aChild is null or is not a child of this node

removeAllChildren

public void removeAllChildren()
Removes all of this node's children, setting their parents to null. If this node has no children, this method does nothing.

add

public void add(XMLDefaultTreeNode 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.
Parameters:
newChild - node to add as a child of this node
Throws:
java.lang.IllegalArgumentException - if newChild is null
java.lang.IllegalStateException - if this node does not allow children
See Also:
insert(quadbase.common.util.internal.XMLDefaultTreeNode, int)

isRoot

public boolean isRoot()
Returns true if this node is the root of the tree. The root is the only node in the tree with a null parent; every tree has exactly one root.
Returns:
true if this node is the root of its tree

getFirstChild

public XMLDefaultTreeNode getFirstChild()
Returns this node's first child. If this node has no children, throws NoSuchElementException.
Returns:
the first child of this node
Throws:
java.util.NoSuchElementException - if this node has no children

getLastChild

public XMLDefaultTreeNode getLastChild()
Returns this node's last child. If this node has no children, throws NoSuchElementException.
Returns:
the last child of this node
Throws:
java.util.NoSuchElementException - if this node has no children

isLeaf

public boolean isLeaf()
Returns true if this node has no children. To distinguish between nodes that have no children and nodes that cannot have children (e.g. to distinguish files from empty directories), use this method in conjunction with getAllowsChildren
Returns:
true if this node has no children
See Also:
getAllowsChildren()

toString

public java.lang.String toString()
Returns the result of sending toString() to this node's user object, or null if this node has no user object.
Overrides:
toString in class java.lang.Object
See Also:
getUserObject()

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

getUserObject

public java.lang.Object getUserObject()

setUserObject

public void setUserObject(java.lang.Object userObj)

getField

public XMLFieldInfo getField(java.lang.String paramName)

EspressReport
v 5.5