org.jafer.query
Class QueryBuilder

java.lang.Object
  |
  +--org.jafer.query.QueryBuilder
All Implemented Interfaces:
QueryBuilder

public class QueryBuilder
extends java.lang.Object
implements QueryBuilder

Class for building XML representations of queries.

All methods use a default search profile if one has been set in ZClient.

Some getNode() methods allow the default search profile to be altered for that query.

(The value of the term supplied to each method cannot be null or an empty String).

See also: org.jafer.zclient.ZClient setsearchProfile().


Field Summary
(package private)  int[] defaultAttributes
           
private  org.w3c.dom.Document document
           
(package private)  boolean dummyNodePresent
           
 
Constructor Summary
QueryBuilder()
           
QueryBuilder(java.lang.String searchProfile)
           
 
Method Summary
 org.w3c.dom.Node and(org.w3c.dom.Node leftNode, org.w3c.dom.Node rightNode)
          Produces an AND node from 2 nodes, which can be query nodes, or AND, OR or NOT nodes.
 org.w3c.dom.Node and(java.util.Vector useAttributes, java.util.Vector terms)
          Produces an AND node from a pair of attributes, or a tree of AND nodes if more than 2 attributes are given.
private  org.w3c.dom.Node buildConstraintModelNode(int[] attributes, java.lang.String term)
           
 org.w3c.dom.Node getNode(int[][] attTypesValues, java.lang.String term)
          Creates a basic query node incorporating the attributes and term supplied.
 org.w3c.dom.Node getNode(int[] attributes, java.lang.String term)
          Creates a basic query node incorporating the attributes and term supplied.
 org.w3c.dom.Node getNode(int useAttribute, java.lang.String term)
          Creates a basic query node incorporating the attribute and term supplied.
 org.w3c.dom.Node getNode(java.lang.String queryExp)
           
 org.w3c.dom.Node getNode(java.lang.String useAttribute, java.lang.String term)
          Creates a basic query node incorporating the attribute and term supplied.
 boolean isDummyNodePresent()
          Gets the value of the dummyNodePresent flag.
private  int lookUpUseAttribute(java.lang.String attributeString)
           
 org.w3c.dom.Node not(org.w3c.dom.Node inputNode)
          Produces a NOT node from the supplied node.
 org.w3c.dom.Node or(org.w3c.dom.Node leftNode, org.w3c.dom.Node rightNode)
          Produces an OR node from 2 nodes, which can be query nodes, or AND, OR or NOT nodes.
 org.w3c.dom.Node or(java.util.Vector useAttributes, java.util.Vector terms)
          Produces an OR node from a pair of attributes, or a tree of OR nodes if more than 2 attributes are given.
 org.w3c.dom.Node parse(org.w3c.dom.Node queryNode)
          Parses the query node before submission.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

document

private org.w3c.dom.Document document

defaultAttributes

int[] defaultAttributes

dummyNodePresent

boolean dummyNodePresent
Constructor Detail

QueryBuilder

public QueryBuilder()

QueryBuilder

public QueryBuilder(java.lang.String searchProfile)
Method Detail

getNode

public org.w3c.dom.Node getNode(java.lang.String useAttribute,
                                java.lang.String term)
                         throws QueryException
Creates a basic query node incorporating the attribute and term supplied.

Attribute supplied must be a Use attribute.

Attribute value is checked against lookup table in ???????org.jafer.util.Bib1Attributes.

Specified by:
getNode in interface QueryBuilder
Parameters:
useAttribute - represents the Use attribute to be used in the query, e.g. "title".
term - the term to be used in the query.
Returns:
a query node, returned via lookUpUseAttribute()??????
Throws:
org.jafer.zclient.QueryException - if useAttribute parameter is not found ?????.
QueryException

getNode

public org.w3c.dom.Node getNode(int useAttribute,
                                java.lang.String term)
                         throws QueryException
Creates a basic query node incorporating the attribute and term supplied.

Attribute supplied can only be a Use attribute.

useAttribute parameter is checked against lookup table in org.jafer.util.Bib1Attributes.java.

Specified by:
getNode in interface QueryBuilder
Parameters:
useAttribute - represents the Use attribute to be used in the query.
term - the term to be used in the query.
Returns:
a query node, -- returned via getNode(int[] attributes, String term)
Throws:
org.jafer.zclient.QueryException - if useAttribute parameter is not within the ranges in the look-up table??????????????.
QueryException

getNode

public org.w3c.dom.Node getNode(int[] attributes,
                                java.lang.String term)
                         throws QueryException
Creates a basic query node incorporating the attributes and term supplied.

The int[] parameter values are used in order for:

{Use, Relation, Position, Structure, Truncation, Completeness}

e.g. { 4, 3, 3, 2, 100, 1 }

A smaller sized array can be used, in which case the values given will be interpreted in order, following the pattern above.

If a default search profile has been set, it will be altered for this query: any values given in the parameter will replace corresponding default values.

(A parameter value of 0 will result in the corresponding attribute type to be excluded from the query.)

Specified by:
getNode in interface QueryBuilder
Parameters:
attributes - represents the attribute values to be used in the query.
term - the term to be used in the query.
Returns:
a query node, -- returned via private method buildConstraintModelNode(int[] attributes, String term)
Throws:
org.jafer.zclient.QueryException - if attributes array size is smaller than 1, or larger than 6. Also if the first attributes element is 0, or term is an empty String or null.
QueryException

getNode

public org.w3c.dom.Node getNode(int[][] attTypesValues,
                                java.lang.String term)
                         throws QueryException
Creates a basic query node incorporating the attributes and term supplied.

The int[][] parameter holds the attribute types and corresponding values.

e.g. {{1,1003}, {2,3}, {4,2}} would set:

Use = 1003, Relation = 3 and Structure = 2.

If a default search profile has been set, it will be altered for this query: any values given in the parameter will replace corresponding default values.

(A parameter value of 0 will result in the corresponding attribute type to be excluded from the query.)

Specified by:
getNode in interface QueryBuilder
Parameters:
attTypesValues - represents the attribute types and their corresponding values to be used in the query.
term - the term to be used in the query.
Returns:
a query node, -- returned via private method buildConstraintModelNode(int[] attributes, String term)
Throws:
org.jafer.zclient.QueryException - if attTypesValues array size is smaller than 1, or larger than 6. Also if the first attributes element is 0, or not supplied. Also if term is an empty String or null.
QueryException

buildConstraintModelNode

private org.w3c.dom.Node buildConstraintModelNode(int[] attributes,
                                                  java.lang.String term)
                                           throws QueryException
QueryException

and

public org.w3c.dom.Node and(org.w3c.dom.Node leftNode,
                            org.w3c.dom.Node rightNode)
                     throws QueryException
Produces an AND node from 2 nodes, which can be query nodes, or AND, OR or NOT nodes.

Specified by:
and in interface QueryBuilder
Parameters:
leftNode - a query, AND, OR or NOT node.
rightNode - a query, AND, OR or NOT node.
Returns:
an AND node.
QueryException

and

public org.w3c.dom.Node and(java.util.Vector useAttributes,
                            java.util.Vector terms)
                     throws QueryException
Produces an AND node from a pair of attributes, or a tree of AND nodes if more than 2 attributes are given.

Vector parameters: Minimum size is 2, and must contain only String objects.

Attributes supplied must be Use attributes.

Attribute values are checked against lookup table in org.jafer.util.Bib1Attributes??????????????.

Parameters:
useAttributes - the attribute values to be used in building the query.
terms - the corresponding terms to be used in building the query.
Returns:
an AND node or tree.
QueryException

or

public org.w3c.dom.Node or(org.w3c.dom.Node leftNode,
                           org.w3c.dom.Node rightNode)
                    throws QueryException
Produces an OR node from 2 nodes, which can be query nodes, or AND, OR or NOT nodes.

Specified by:
or in interface QueryBuilder
Parameters:
leftNode - a query, AND, OR or NOT node.
rightNode - a query, AND, OR or NOT node.
Returns:
an OR node.
QueryException

or

public org.w3c.dom.Node or(java.util.Vector useAttributes,
                           java.util.Vector terms)
                    throws QueryException
Produces an OR node from a pair of attributes, or a tree of OR nodes if more than 2 attributes are given.

Vector parameters: minimum size is 2, and must contain only String objects.

Attributes supplied must be Use attributes.

Attribute values are checked against lookup table in org.jafer.util.Bib1Attributes.

Parameters:
useAttributes - the attribute values to be used in building the query.
terms - the corresponding terms to be used in building the query.
Returns:
an OR node or tree.
QueryException

not

public org.w3c.dom.Node not(org.w3c.dom.Node inputNode)
                     throws QueryException
Produces a NOT node from the supplied node. (Supplied node can be a query node, an OR node, or an AND node.) i.e. produces a negated version of the supplied node.

Specified by:
not in interface QueryBuilder
Parameters:
inputNode - a query, AND or OR node.
Returns:
a NOT node.
QueryException

parse

public org.w3c.dom.Node parse(org.w3c.dom.Node queryNode)
                       throws QueryException
Parses the query node before submission.

This method is called from ZClient.

Parameters:
queryNode - the unparsed query node.
Returns:
the parsed query node.
QueryException

isDummyNodePresent

public boolean isDummyNodePresent()
Gets the value of the dummyNodePresent flag.

returns true if a dummy node was created in QueryParser.makeDummyNode().

Returns:
true or false.

getNode

public org.w3c.dom.Node getNode(java.lang.String queryExp)
                         throws QueryException
QueryException

lookUpUseAttribute

private int lookUpUseAttribute(java.lang.String attributeString)
                        throws QueryException
QueryException