edu.wpi.cs.dsrg.xmldb.xat.component.xattreegeneration
Class ParserTraverse

java.lang.Object
  |
  +--edu.wpi.cs.dsrg.xmldb.xat.common.visitorpattern.InheritableVisitor
        |
        +--edu.wpi.cs.dsrg.xmldb.xat.component.xattreegeneration.ParserTraverse

public class ParserTraverse
extends InheritableVisitor

This class visits the objects of the Kweelt parser and puts the query in the correct algebra node.

To understand this code, one should know how the Kweelt parser works and what our algebra is. It would also be helpful to know what a visitor pattern is because that is what we use to traverse through the query.

There are different types of the return value from the visit() function. For visit(QuiltQuery) returns a Vector of XATTrees. For visit(*Op*) returns a Vector of Expression + XATTree. For visit(LocationStep) returns a Vector of Step + XATTree. For visit(Value*) returns a Primitive Type (*). For visit(*) returns a XATTree.

Since:
1.0
See Also:
xacute.quilt, edu.wpi.cs.dsrg.xmldb.xat.common.visitorpattern

Field Summary
protected  OperatorBuilder builder
          Used to create operators.
 
Constructor Summary
ParserTraverse()
          Class Default Constructor
ParserTraverse(boolean debugMain)
          Class constructor specifying debug mode
 
Method Summary
 java.lang.Object dispatch()
          To visit a null object.
 java.lang.Object dispatch(java.lang.Object obj)
          To visit any object.
 java.lang.Object dispatch(java.lang.Object ob1, java.lang.Object ob2)
           
 XATTree expressionVectorToXAT(java.util.Vector expVector)
          Convert an Expression Vector into an XAT Tree.
 XATTree getTree()
          Returns the xat.
 XATTree getTree(java.lang.String functionName)
          Returned the XAT for the user defined functions.
 XATTree handleWhereClause(xacute.quilt.FLWRExpression flwr, XATTree returnClause, java.lang.String returnCol)
          Generate the XAT Tree for Where Clause
 boolean isDebug()
          Get the value of the propertity 'DEBUG_ParserTraverse'.
protected  XATTree mergeTreeWithSources(XATTree top, XATTree bottom)
          Merge two trees together and aware of source operators.
 void setDebug(boolean debug)
          Set to show debugging message.
 java.lang.Object visit(xacute.quilt.BinOpAND andOp)
          Create XAT Tree for Binary AND Expression.
 java.lang.Object visit(xacute.quilt.BinOpArith arith)
          Create XAT Tree for Binary Arithmatic Expression.
 java.lang.Object visit(xacute.quilt.BinOpCOMP comp)
          This method is visited when WHERE is encountered in a query It will creates a select node.
 java.lang.Object visit(xacute.quilt.BinOpOR orOp)
          Create XAT Tree for Binary OR Expression.
 java.lang.Object visit(xacute.quilt.BinOpUnion union)
          For the union, two operators will be created.
 java.lang.Object visit(xacute.quilt.CurrentNode curN)
          Create XAT Tree for Current Node.
 java.lang.Object visit(xacute.quilt.DeleteUpdate del)
          Create XAT Tree for Delete Update Operator.
 java.lang.Object visit(xacute.quilt.ElementConstruct ec)
          Visited when a RETURN clause is encountered
 java.lang.Object visit(xacute.quilt.FilterExpression filterExpr)
          Process the Filter Expression.
 java.lang.Object visit(xacute.quilt.FLWRExpression flwr)
          Called if a FLWR (For-Let-Where-Return) expression is encountered (OR when a FOR is found in the query)
 java.lang.Object visit(xacute.quilt.FLWUExpression flwu)
          Difference from the FLWR, it doesn't have the Aggregate Operator.
 java.lang.Object visit(xacute.quilt.ForBinding b)
          Order of generated forbinding: NavUnnest->(Distinct)->Subtree Contains the data for the FOR bindings
 java.lang.Object visit(xacute.quilt.FunCall funPrim)
          The superclass of all the function calls
 java.lang.Object visit(xacute.quilt.FunDef fundef)
          Visit defined functions using visit(FunCall)
 java.lang.Object visit(xacute.quilt.FunUserDefined funUD)
          Visit user defined functions
 java.lang.Object visit(xacute.quilt.IfThenElse ite)
          Create XAT Tree for IF THEN ELSE structure.
 java.lang.Object visit(xacute.quilt.InsertUpdate ins)
          Called when an Insert Update is encountered
 java.lang.Object visit(xacute.quilt.LetBinding let)
          The let binding will add a rename operator to show the binding.
 java.lang.Object visit(xacute.quilt.LocationStep lstep)
          Determines the type of XPath (child, descendant-or-self) Contains an axis variable Calls the NodeTest object The result is either a NameTest or NodeType object visit call
 java.lang.Object visit(xacute.quilt.Nav nav)
          A new Navigate node is created.
 java.lang.Object visit(xacute.quilt.QuiltQuery q)
          This is the first pattern that is visited The QuiltQuery object contains the entire query The visitor pattern visits the body of the QuiltQuery object, which is the entire Quilt query For each function definitions it will create a new XAT tree.
 java.lang.Object visit(xacute.quilt.RenameUpdate re)
          Called when a Rename Update is encountered
 java.lang.Object visit(xacute.quilt.ReplaceUpdate rep)
          Called when a Replace Update is encountered
 java.lang.Object visit(xacute.quilt.SequenceExpression seq)
          Visit sequence expression will just link all the expressions together.
 java.lang.Object visit(xacute.quilt.SortClause sort)
          Called when a sortyby command is called in a query
 java.lang.Object visit(xacute.quilt.TagNameable tag)
          The tag name data is found in the TagNameable object A tag node is created for the taggerTree (Tag node data structure)
 java.lang.Object visit(xacute.quilt.UnOpMinus minusOp)
          It will return a Vector of 1) expression and 2) subtree of required operators.
 java.lang.Object visit(xacute.quilt.UnOpNot notOp)
          It will return a Vector of 1) expression and 2) subtree of required operators.
 java.lang.Object visit(xacute.quilt.ValueBool valBool)
          Visit a Boolean value
 java.lang.Object visit(xacute.quilt.ValueNum valNum)
          Visit a Boolean value
 java.lang.Object visit(xacute.quilt.ValueString val)
          Returns the ValueString object as a string Used for source nodes and select nodes.
 java.lang.Object visit(xacute.quilt.Var var)
          Visits a binding variable Contains the entry point for a navigation node
 
Methods inherited from class edu.wpi.cs.dsrg.xmldb.xat.common.visitorpattern.InheritableVisitor
getAncestors, getMethod, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

builder

protected OperatorBuilder builder
Used to create operators.
Since:
1.0
Constructor Detail

ParserTraverse

public ParserTraverse()
Class Default Constructor
Since:
1.0

ParserTraverse

public ParserTraverse(boolean debugMain)
Class constructor specifying debug mode
Since:
1.0
Method Detail

dispatch

public java.lang.Object dispatch()
Description copied from class: InheritableVisitor
To visit a null object.
Overrides:
dispatch in class InheritableVisitor

dispatch

public java.lang.Object dispatch(java.lang.Object obj)
Description copied from class: InheritableVisitor
To visit any object.
Overrides:
dispatch in class InheritableVisitor

dispatch

public java.lang.Object dispatch(java.lang.Object ob1,
                                 java.lang.Object ob2)

expressionVectorToXAT

public XATTree expressionVectorToXAT(java.util.Vector expVector)
Convert an Expression Vector into an XAT Tree.
Parameters:
expVector - Vector to be converted.
Returns:
edu.wpi.cs.dsrg.xmldb.xat.common.treestructure.XATTree
Since:
1.0

getTree

public XATTree getTree()
Returns the xat. It is used by other components / classes to retrieve the tree.
Returns:
XAT Tree
Since:
1.0

getTree

public XATTree getTree(java.lang.String functionName)
Returned the XAT for the user defined functions.
Parameters:
functionName - function to get the XAT tree.
Returns:
XAT Tree
Since:
1.0

handleWhereClause

public XATTree handleWhereClause(xacute.quilt.FLWRExpression flwr,
                                 XATTree returnClause,
                                 java.lang.String returnCol)
Generate the XAT Tree for Where Clause
Parameters:
flwr - XQurey's FLWR Expression
returnClause - XAT Tree already generated for Return Clause
returnCol - Returned column name
Returns:
XAT Tree
Since:
1.0

isDebug

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

mergeTreeWithSources

protected XATTree mergeTreeWithSources(XATTree top,
                                       XATTree bottom)
Merge two trees together and aware of source operators.

If there is a source operator, then the lower part are copied many times with product operator.

Parameters:
top - edu.wpi.cs.dsrg.xmldb.xat.common.treestructure.XATTree
bottom - edu.wpi.cs.dsrg.xmldb.xat.common.treestructure.XATTree
Returns:
edu.wpi.cs.dsrg.xmldb.xat.common.treestructure.XATTree
Since:
1.0

setDebug

public void setDebug(boolean debug)
Set to show debugging message.
Parameters:
debug - boolean
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.BinOpAND andOp)
Create XAT Tree for Binary AND Expression. It will return a Vector of 1) expression and 2) subtree of required operators.
Parameters:
andOp - xacute.quilt.BinOpAND
Returns:
Vector of BinANDExpression and subXATTree.
Since:
1.0
See Also:
BinOpAND

visit

public java.lang.Object visit(xacute.quilt.BinOpArith arith)
Create XAT Tree for Binary Arithmatic Expression. This method is visited an arithmatic expression encountered in a query
Parameters:
arith - xacute.quilt.BinOpArith
Returns:
Vector of BinArithExpression + XATTRee
Since:
1.0
See Also:
BinOpArith

visit

public java.lang.Object visit(xacute.quilt.BinOpCOMP comp)
This method is visited when WHERE is encountered in a query It will creates a select node.
Parameters:
comp - xacute.quilt.BinOpCOMP
Returns:
Vector of BinCOMPExpression + XATTRee
Since:
1.0
See Also:
BinOpCOMP

visit

public java.lang.Object visit(xacute.quilt.BinOpOR orOp)
Create XAT Tree for Binary OR Expression. This method is visited an OR expression encountered in a query
Parameters:
orOp - xacute.quilt.BinOpOR
Returns:
Vector of BinORExpression + XATTree
Since:
1.0
See Also:
BinOpOR

visit

public java.lang.Object visit(xacute.quilt.BinOpUnion union)
For the union, two operators will be created. First, is the merge operator. Second, is the xml union operaotr. The xml union operator will take the two subtrees's output columns, and then, generate a new output column. The merge operator will make two input tables as one table. Also, according to Kweelt's specification, it only take two sources.
Parameters:
union - xacute.quilt.BinOpUnion
Returns:
XATTree
Since:
1.0
See Also:
BinOpUnion

visit

public java.lang.Object visit(xacute.quilt.CurrentNode curN)
Create XAT Tree for Current Node.
Parameters:
curN - xacute.quilt.CurrentNode
Returns:
VarStepImp.
Since:
1.0
See Also:
VarStepImp

visit

public java.lang.Object visit(xacute.quilt.DeleteUpdate del)
Create XAT Tree for Delete Update Operator. Called when a Delete Update is encountered.
Parameters:
del - DeleteUpdate
Returns:
XATTree of deleteNode.
Since:
1.0
See Also:
DeleteUpdate

visit

public java.lang.Object visit(xacute.quilt.ElementConstruct ec)
Visited when a RETURN clause is encountered
Parameters:
ec - the element construct expression to be visited.
Returns:
XATTree of Tagger.
Since:
1.0
See Also:
ElementConstruct

visit

public java.lang.Object visit(xacute.quilt.FilterExpression filterExpr)
Process the Filter Expression.
Parameters:
filterExpr - xacute.quilt.FilterExpression
Returns:
XATTree
Since:
1.0
See Also:
FilterExpression

visit

public java.lang.Object visit(xacute.quilt.FLWRExpression flwr)
Called if a FLWR (For-Let-Where-Return) expression is encountered (OR when a FOR is found in the query)

The tree should be like: Aggregate -> (Sort) -> For bindings -> (Where) -> Return Clause -> (Let bindings) | result | | returnClause |

Parameters:
flwr - FLWR expression.
Returns:
XATTree
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.FLWUExpression flwu)
Difference from the FLWR, it doesn't have the Aggregate Operator. Called when a FLWU(Update) Expression in encountered
Parameters:
flwu - FLWU expression.
Returns:
XATTree.
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.ForBinding b)
Order of generated forbinding: NavUnnest->(Distinct)->Subtree Contains the data for the FOR bindings
Parameters:
b - ForBinding
Returns:
XATTree.
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.FunCall funPrim)
The superclass of all the function calls
Parameters:
funPrim - xacute.quilt.FunCall
Returns:
XATTree
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.FunDef fundef)
Visit defined functions using visit(FunCall)
Parameters:
fundef - xacute.quilt.FunDef
Returns:
java.lang.Object
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.FunUserDefined funUD)
Visit user defined functions
Parameters:
param - xacute.quilt.FunUserDefined
Returns:
java.lang.Object
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.IfThenElse ite)
Create XAT Tree for IF THEN ELSE structure. IfThenElse will have a condition, e.g., like the where clause, Then, it has two branches. Left for the then, and Right for the else.
Parameters:
ite - xacute.quilt.IfThenElse
Returns:
java.lang.XATTree
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.InsertUpdate ins)
Called when an Insert Update is encountered
Parameters:
InsertUpdate - ins
Returns:
XATTree
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.LetBinding let)
The let binding will add a rename operator to show the binding.
Parameters:
let - xacute.quilt.LetBinding
Returns:
XATTree.
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.LocationStep lstep)
Determines the type of XPath (child, descendant-or-self) Contains an axis variable Calls the NodeTest object The result is either a NameTest or NodeType object visit call

The LocationStep will be converted into one Navigate operator with optional multiple select operators.

The axies have: AXISSPECIFIERS = {"ancestor", "ancestor-or-self", "attribute", "child", "descendant", "descendant-or-self", "following", "following-sibling", "namespace", "parent", "preceding", "preceding-sibling", "self"};

Parameters:
lstep - LocationStep
Returns:
A Vector of multiple elements: 1) Step, 2-x) XATTrees for predicates.
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.Nav nav)
A new Navigate node is created. NavigationStep objects are assigned to the Navigate node

NavCollection Operator is created instead of NavigationImp.

In the ForBinding, we will add a NavigateImp (unnesting) to iterate the answers.

If the LocationStep has a filter, then a rename (dummy) is created at the root, so that, we know which column is the focus.

For the locationstep, it will return a vector. Also, for the E, it returns a XATTree or a String for the Var.

Parameters:
nav - Nav
Returns:
XATTree
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.QuiltQuery q)
                       throws FactoryException
This is the first pattern that is visited The QuiltQuery object contains the entire query The visitor pattern visits the body of the QuiltQuery object, which is the entire Quilt query For each function definitions it will create a new XAT tree. Hence, QuiltQuery will return a vector of XAT trees. Where the first one is the root Tree and rest of them are functions.
Parameters:
q - QuiltQuery
Returns:
Hashtable of XATTrees. Hashed by function name and "main".
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.RenameUpdate re)
Called when a Rename Update is encountered
Parameters:
RenameUpdate - re
Returns:
XATTree
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.ReplaceUpdate rep)
Called when a Replace Update is encountered
Parameters:
ReplaceUpdate - rep
Returns:
XATTree
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.SequenceExpression seq)
Visit sequence expression will just link all the expressions together.
Parameters:
seq - xacute.quilt.SequenceExpression
Returns:
XATTree
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.SortClause sort)
Called when a sortyby command is called in a query
Parameters:
sort - SortClause
Returns:
XATTree.
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.TagNameable tag)
The tag name data is found in the TagNameable object A tag node is created for the taggerTree (Tag node data structure)
Parameters:
tag - TagNameable
Returns:
String.
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.UnOpMinus minusOp)
It will return a Vector of 1) expression and 2) subtree of required operators.
Parameters:
andOp - xacute.quilt.UniOpMinus
Returns:
Vector of UniMinusExpression and subXATTree.
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.UnOpNot notOp)
It will return a Vector of 1) expression and 2) subtree of required operators.
Parameters:
andOp - xacute.quilt.UniOpNot
Returns:
Vector of UniNotExpression and subXATTree.
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.ValueBool valBool)
Visit a Boolean value
Parameters:
valBool - xacute.quilt.ValueBool
Returns:
Boolean
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.ValueNum valNum)
Visit a Boolean value
Parameters:
valNum - xacute.quilt.ValueNum
Returns:
Double
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.ValueString val)
Returns the ValueString object as a string Used for source nodes and select nodes. Also sets the source node in the appropriate tree.
Parameters:
val - xacute.quilt.ValueString
Returns:
String.
Since:
1.0

visit

public java.lang.Object visit(xacute.quilt.Var var)
Visits a binding variable Contains the entry point for a navigation node
Parameters:
var - Var
Returns:
VarStep.
Since:
1.0