edu.wpi.cs.dsrg.xmldb.xat.common.treestructure
Class XATTreeImp

java.lang.Object
  |
  +--edu.wpi.cs.dsrg.xmldb.xat.common.operator.XATPropertiesImp
        |
        +--edu.wpi.cs.dsrg.xmldb.xat.common.operator.XATQueryObjectImp
              |
              +--edu.wpi.cs.dsrg.xmldb.xat.common.treestructure.XATTreeImp

public class XATTreeImp
extends XATQueryObjectImp
implements XATTree

This class implemented the XATTree.

Since:
1.0
See Also:
Serialized Form

Field Summary
protected  BindingTable bindingTable
          The binding table of XATTree.
protected  java.util.ArrayList root
          The array containing all the roots of XATTree.
 
Fields inherited from class edu.wpi.cs.dsrg.xmldb.xat.common.operator.XATQueryObjectImp
stats, statsPresent
 
Constructor Summary
XATTreeImp()
          The default XATTreeImp constructor.
 
Method Summary
 void addNode(XATNode newNode, XATNode parentNode)
          Add a new parent node for a given DOMPatternNode node.
 void addXATTree(XATTree subtree)
          For all the leaves, add the subtree to it.
protected  void appendChildLeaves(java.util.Vector v, XATNode node)
          Append all the decendent nodes of given XAT Node into a vector.
protected  void appendNodes(java.util.Vector v, XATNode node)
          Append all the distinct decendent nodes of given XAT Node into a vector.
 void appendXATNode(XATNode leaf)
          Append a node to all the leaves of the current XATTree.
protected  java.lang.String childrenString(XATNode node, java.lang.String indent)
          Convert all the children of the given XATNode into a string with indent format.
 java.lang.Object clone()
          Clone the XATTree.
 XATNode[] convertToArray()
          Converts this tree into an array, similar to getLeaves()
 void copy(XATTreeImp tree)
          Copy the specified tree as current tree.
 void deleteNode(XATNode node)
          Delete node.
 java.util.Vector getAllLeafNodes(XATNode root)
          Get all the leaf node of given XATTree, which is rooted at given root node.
 BindingTable getBindingTable()
          Get the binding table of this Tree.
 XATNode[] getLeaves()
          Get all the leaves of this XATTree.
 XATLeaf[] getLeavesWithDepth()
          Get all the leaves of this XATTree along with their depth.
 XATNode getRoot()
          Get the root node of this XATTree.
 java.util.Iterator getRoots()
          Assuming the XATTree is a forest sometime, this method get all the roots of XAT.
 void insertRoot(XATNode newroot)
          Insert a new node as the root of this tree.
 boolean isDebug()
          Get the value of the propertity "DEBUG_XATTreeImp".
 void moveNode(XATNode child, XATNode newParent)
          Move node.
 void moveNode(XATNode child, XATNode new_parent, int position)
          Move node.
 void replaceNode(XATNode oldNode, XATNode newNode)
          Replace oldNode in Tree with newNode.
 void setBindingTable(BindingTable bind)
          Set the binding table of this Tree.
protected  void setDefaultProperties()
          Called by the constructor.
protected  void setDefaultStatistics()
          Called by the constructor.
 XATNode setRoot(XATNode newRoot)
          Set root node.
 int size()
          Give number of nodes in this tree.
 java.lang.String toString()
           
 boolean validate()
          This going to validate the parent-child relationship.
 
Methods inherited from class edu.wpi.cs.dsrg.xmldb.xat.common.operator.XATQueryObjectImp
addStatistic, compareTo, getStatistics, isValidStatistic
 
Methods inherited from class edu.wpi.cs.dsrg.xmldb.xat.common.operator.XATPropertiesImp
addProperty, getProperties, getProperty, isValidPropertyName, setNewPropertyValue, setProperty
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

root

protected java.util.ArrayList root
The array containing all the roots of XATTree.
Since:
1.0

bindingTable

protected BindingTable bindingTable
The binding table of XATTree.
Since:
1.0
Constructor Detail

XATTreeImp

public XATTreeImp()
The default XATTreeImp constructor.
Since:
1.0
Method Detail

addNode

public void addNode(XATNode newNode,
                    XATNode parentNode)
Add a new parent node for a given DOMPatternNode node. The parent node is updated to have a link to the child node. The child node is updates to have a link to the parent node.
Specified by:
addNode in interface XATTree
Parameters:
parent - The parent node it attached to.
child - The child node attached.
Returns:
void
Since:
1.0

addXATTree

public void addXATTree(XATTree subtree)
For all the leaves, add the subtree to it. Note: We clone the subtree, and then added it to the tree. Hence, further modifications will not by automatically updated. Make sure create the subtree first, then added to the tree.
Specified by:
addXATTree in interface XATTree
Parameters:
childTree - The XATTree attached.
Returns:
void
Since:
1.0

appendChildLeaves

protected void appendChildLeaves(java.util.Vector v,
                                 XATNode node)
Append all the decendent nodes of given XAT Node into a vector.
Parameters:
v - The vector contains all decendent nodes.
node - The node searching for.
Returns:
void
Since:
1.0

appendNodes

protected void appendNodes(java.util.Vector v,
                           XATNode node)
Append all the distinct decendent nodes of given XAT Node into a vector.
Parameters:
v - The vector contains all decendent nodes.
node - The node searching for.
Returns:
void
Since:
1.0

appendXATNode

public void appendXATNode(XATNode leaf)
Append a node to all the leaves of the current XATTree. Remember further updates to this leaf will not be updated automatically!
Specified by:
appendXATNode in interface XATTree
Parameters:
leaf - The node searching for.
Returns:
void
Since:
1.0

childrenString

protected java.lang.String childrenString(XATNode node,
                                          java.lang.String indent)
Convert all the children of the given XATNode into a string with indent format.
Parameters:
node - The XATNode searching for.
indent - The indent format.
Returns:
String The converted String.
Since:
1.0

clone

public java.lang.Object clone()
Clone the XATTree.
Specified by:
clone in interface XATTree
Overrides:
clone in class java.lang.Object
Returns:
Object The result
Since:
1.0

convertToArray

public XATNode[] convertToArray()
Converts this tree into an array, similar to getLeaves()
Specified by:
convertToArray in interface XATTree
Returns:
XATNode[] An array of XATNodes
Since:
1.0

copy

public void copy(XATTreeImp tree)
Copy the specified tree as current tree.
Parameters:
tree - The new XATTree.
Returns:
void
Since:
1.0

deleteNode

public void deleteNode(XATNode node)
                throws XATTreeNodeHasNoParentException
Delete node. It will affect number of nodes. All the children nodes of the to-be-deleted node will be the children of the parent node of the to-be-delete node. If the to-be-deleted node is the root node of the XATTree, the exception XATTreeNodeHasNoParentException will the throwed. Instead, the root node should be changed by setRoot() method.
Specified by:
deleteNode in interface XATTree
Parameters:
node - the to-be-deleted child node.
Returns:
void
Since:
1.0

getAllLeafNodes

public java.util.Vector getAllLeafNodes(XATNode root)
Get all the leaf node of given XATTree, which is rooted at given root node.
 This method is used to find all of the Source operators in an XATTree
 Looks at all of the root's children and adds them to the vector
 if that nodes' operator is an XML source .  The function is then
 recurvsively called on each of root's children until there are no more nodes 
 to look at.  
 
Specified by:
getAllLeafNodes in interface XATTree
Parameters:
root - The root of a tree to iterate over
Returns:
Vector of all the leaf nodes including the subtree of FOR and GB.
Since:
1.0
See Also:

getBindingTable

public BindingTable getBindingTable()
Get the binding table of this Tree.
Specified by:
getBindingTable in interface XATTree
Returns:
BindingTable The binding table of current tree.
Since:
1.0

getLeaves

public XATNode[] getLeaves()
Get all the leaves of this XATTree.
Specified by:
getLeaves in interface XATTree
Returns:
XATNode[] An array of XATNodes those are the leaf nodes.
Since:
1.0

getLeavesWithDepth

public XATLeaf[] getLeavesWithDepth()
Get all the leaves of this XATTree along with their depth.
Specified by:
getLeavesWithDepth in interface XATTree
Returns:
XATLeaf[] An array of XATNodes those are the leaf nodes.
Since:
1.0

getRoot

public XATNode getRoot()
Get the root node of this XATTree.
Specified by:
getRoot in interface XATTree
Returns:
XATNode The root of XATTree.
Since:
1.0

getRoots

public java.util.Iterator getRoots()
Assuming the XATTree is a forest sometime, this method get all the roots of XAT.
Specified by:
getRoots in interface XATTree
Returns:
java.util.Iterator All the roots of given XAT.
Since:
1.0

insertRoot

public void insertRoot(XATNode newroot)
Insert a new node as the root of this tree.
Specified by:
insertRoot in interface XATTree
Parameters:
root - The root will be inserted in.
Returns:
void
Since:
1.0

isDebug

public boolean isDebug()
Get the value of the propertity "DEBUG_XATTreeImp".
Returns:
boolean True: With debug information. False: No debug information.
Since:
1.0

moveNode

public void moveNode(XATNode child,
                     XATNode newParent)
Description copied from interface: XATTree
Move node. It will affect three nodes, the original parent node A, the child node B and the new parent node C. The A's children is updated, The B's parent is updated, and C's children is updated.

The child node will always move to the end of the children of the parent node.

Specified by:
moveNode in interface XATTree
Tags copied from interface: XATTree
Parameters:
child - The to-be-moved child node.
new_parent - The new parent node.
Returns:
void

moveNode

public void moveNode(XATNode child,
                     XATNode new_parent,
                     int position)
Move node. It will affect three nodes, the original parent node A, the child node B and the new parent node C. The A's children is updated, The B's parent is updated, and C's children is updated.

The child node will always move to the end of the children of the parent node.

Specified by:
moveNode in interface XATTree
Parameters:
child - The to-be-moved child node.
new_parent - The new parent node.
Returns:
void
Since:
1.0

replaceNode

public void replaceNode(XATNode oldNode,
                        XATNode newNode)
Replace oldNode in Tree with newNode.
Specified by:
replaceNode in interface XATTree
Parameters:
oldNode - The old XATNode will be replaced.
newNode - The new XATNode used to replace the old one.
Returns:
void
Since:
1.0

setBindingTable

public void setBindingTable(BindingTable bind)
Set the binding table of this Tree.
Specified by:
setBindingTable in interface XATTree
Parameters:
bind - The new binding table for this tree.
Returns:
void
Since:
1.0

setDefaultProperties

protected void setDefaultProperties()
Called by the constructor. this will set the default properties that the ALL query objects will support. Each subclass should override this method and add their own unique properties, but should also call super.setDefaultProperties() so that the common properties may be set.
Overrides:
setDefaultProperties in class XATQueryObjectImp
Returns:
void
Since:
1.0

setDefaultStatistics

protected void setDefaultStatistics()
Called by the constructor. this will set the default properties that the ALL query objects will support. Each subclass should override this method and add their own unique properties, but should also call super.setDefaultProperties() so that the common properties may be set.
Overrides:
setDefaultStatistics in class XATQueryObjectImp

setRoot

public XATNode setRoot(XATNode newRoot)
Set root node.
Specified by:
setRoot in interface XATTree
Parameters:
new_root - The new root node.
Returns:
XATNode The original root node.
Since:
1.0

size

public int size()
Give number of nodes in this tree.
Specified by:
size in interface XATTree
Returns:
int The computed size of the tree.
Since:
1.0

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

validate

public boolean validate()
This going to validate the parent-child relationship. It's a top down traversal. And, if it find a children't parent is not set properly in the tree, a warning message will be shown, and also the parent link will be fixed.
Specified by:
validate in interface XATTree
Returns:
boolean Tree: This is a valid XATTree. False: otherwise.
Since:
1.0