com.flexive.shared.search.query
Class QueryNode

java.lang.Object
  extended by com.flexive.shared.search.query.QueryNode
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
QueryOperatorNode, QueryValueNode

public abstract class QueryNode
extends java.lang.Object
implements java.io.Serializable

A node in a search query expression.

Author:
Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
See Also:
Serialized Form

Field Summary
protected  java.util.List<QueryNode> children
           
protected  int id
           
protected  QueryNode parent
           
 
Constructor Summary
protected QueryNode()
          Default constructor
protected QueryNode(int id)
          Protected constructor.
 
Method Summary
 void addChild(QueryNode child)
          Add a new child node after the last child.
 void addChild(QueryNode parentNode, QueryNode child)
          Add a new child to the given parent node.
 void addChildAfter(QueryNode afterNode, QueryNode child)
          Add a child after the given node.
protected abstract  void buildSqlQuery(SqlQueryBuilder builder)
          Build the query represented by this node and its children.
 boolean equals(java.lang.Object anotherNode)
          
 QueryNode findChild(int childId)
          Return the child node with the given ID.
 QueryNode getChild(int index)
          Return the child node at the given index.
 java.util.List<QueryNode> getChildren()
           
 int getId()
           
 FxString getLabel()
          Return the label to be displayed for this query node.
 int getLevel()
          Return the nesting level of the given node in the query tree, i.e.
protected  java.lang.String getNodeName()
          Return the informal representation of a node to be used in toString.
 QueryNode getParent()
           
 java.lang.String getPath()
          Returns the complete node path of the current node, i.e.
 int hashCode()
          
 boolean isHidden()
          Returns true if the node and its children should not be displayed in a query editor or report.
abstract  boolean isValid()
          Return true if the node's value is valid, or false if it is not.
 boolean isValueNode()
          Return true if this node is a "value" node, i.e.
 boolean isWideInput()
          Returns true if the node needs a wide input field, e.g.
 QueryNode removeChild(QueryNode child)
          Remove a child node.
 void setChildren(java.util.List<QueryNode> children)
           
 void setId(int id)
           
 void setParent(QueryNode parent)
          Set the parent of this node.
 java.lang.String toString()
          
abstract  void visit(QueryNodeVisitor visitor)
          Visit this node.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

id

protected int id

parent

protected QueryNode parent

children

protected java.util.List<QueryNode> children
Constructor Detail

QueryNode

protected QueryNode()
Default constructor


QueryNode

protected QueryNode(int id)
Protected constructor.

Parameters:
id - the node ID
Method Detail

isValid

public abstract boolean isValid()
Return true if the node's value is valid, or false if it is not.

Returns:
true if the node's value is valid, or false if it is not.

buildSqlQuery

protected abstract void buildSqlQuery(SqlQueryBuilder builder)
Build the query represented by this node and its children.

Parameters:
builder - an sql query builder

visit

public abstract void visit(QueryNodeVisitor visitor)
Visit this node.

Parameters:
visitor - the visitor

getId

public int getId()

setId

public void setId(int id)

getParent

public QueryNode getParent()

getLevel

public int getLevel()
Return the nesting level of the given node in the query tree, i.e. the number of parent links one has to traverse to reach the root node. A node attached to the root node has a level of 1.

Returns:
the node level

setParent

public void setParent(QueryNode parent)
Set the parent of this node. If the node is not included in the parent's children list, it is added automatically.

Parameters:
parent - the parent to be sed

getChildren

public java.util.List<QueryNode> getChildren()

setChildren

public void setChildren(java.util.List<QueryNode> children)

addChild

public void addChild(QueryNode child)
Add a new child node after the last child.

Parameters:
child - The child node to be added

addChild

public void addChild(QueryNode parentNode,
                     QueryNode child)
Add a new child to the given parent node. The parent node may be the current node, or any of its immediate or transitive child nodes.

Parameters:
parentNode - The parent node where the child should be inserted
child - The child node to be added

addChildAfter

public void addChildAfter(QueryNode afterNode,
                          QueryNode child)
Add a child after the given node. The after node may be an immediate or transitive child of the current node.

Parameters:
afterNode - node after which the child should be inserted
child - child node to be added

removeChild

public QueryNode removeChild(QueryNode child)
Remove a child node. Also searches all subtrees if the node is node an immediate child.

Parameters:
child - the child to be deleted
Returns:
the parent node of the deleted child, or null if the child does not exist

getChild

public QueryNode getChild(int index)
Return the child node at the given index.

Parameters:
index - the child index in this parent's children list
Returns:
the child node at the given index.

findChild

public QueryNode findChild(int childId)
Return the child node with the given ID.

Parameters:
childId - the requested child node ID
Returns:
the child node with the given ID

equals

public boolean equals(java.lang.Object anotherNode)

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

getNodeName

protected java.lang.String getNodeName()
Return the informal representation of a node to be used in toString.

Returns:
the informal representation of a node to be used in toString.

getLabel

public FxString getLabel()
Return the label to be displayed for this query node.

Returns:
the label to be displayed for this query node.

isValueNode

public boolean isValueNode()
Return true if this node is a "value" node, i.e. is used to represent a scalar value in the query. Used for JSTL node handling.

Returns:
true for scalar value nodes

isHidden

public boolean isHidden()
Returns true if the node and its children should not be displayed in a query editor or report.

Returns:
true if the node and its children should not be displayed

isWideInput

public boolean isWideInput()
Returns true if the node needs a wide input field, e.g. a datepicker or file download field.

Returns:
true if the node needs a wide input field

getPath

public java.lang.String getPath()
Returns the complete node path of the current node, i.e. the node ids traversed to the root node separated by dashes ("-"). e.g. 1.path --> 1 |- 2.path --> 1-2 |- 3.path --> 1-2-3

Returns:
the complete node path of the current node