org.basex.query.expr
Class ParseExpr

java.lang.Object
  extended by org.basex.data.ExprInfo
      extended by org.basex.query.expr.Expr
          extended by org.basex.query.expr.ParseExpr
Direct Known Subclasses:
Arr, FTContains, FTExpr, GFLWOR, GFLWOR.Clause, Path, Preds, Simple, Single, StaticVarRef, Switch, TypeSwitch, VarRef

public abstract class ParseExpr
extends Expr

Abstract parse expression. All non-value expressions are derived from this class.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Nested Class Summary
 
Nested classes/interfaces inherited from class org.basex.query.expr.Expr
Expr.Flag
 
Field Summary
 InputInfo info
          Input information.
 long size
          Cardinality of result; unknown if set to -1.
 SeqType type
          Static type.
 
Constructor Summary
protected ParseExpr(InputInfo ii)
          Constructor.
 
Method Summary
 void checkAdmin(QueryContext ctx)
          Checks if the current user has create permissions.
 void checkAllUp(Expr... expr)
          Ensures that all specified expressions are either updating or vacuous.
 Bin checkBinary(Expr e, QueryContext ctx)
          Checks if the specified expression yields a binary item.
 boolean checkBln(Expr e, QueryContext ctx)
          Checks if the specified expression yields a boolean.
 Collation checkColl(Expr e, QueryContext ctx)
          Checks if the specified collation is supported.
 void checkCreate(QueryContext ctx)
          Checks if the current user has create permissions.
 Value checkCtx(QueryContext ctx)
          Throws an exception if the context value is not set.
 double checkDbl(Expr e, QueryContext ctx)
          Checks if the specified expression yields a double.
 DBNode checkDBNode(Item it)
          Checks if the specified expression is a database node.
 byte[] checkEStr(Expr e, QueryContext ctx)
          Checks if the specified expression yields a string or empty sequence.
 byte[] checkEStr(Item it)
          Checks if the specified item is a string or an empty sequence.
 FItem checkFunc(Expr e, QueryContext ctx)
          Checks if the specified expression yields a string or binary item.
 Item checkItem(Expr e, QueryContext ctx)
          Checks if the specified expression yields a non-empty item.
 long checkItr(Expr e, QueryContext ctx)
          Checks if the specified expression is an integer.
 long checkItr(Item it)
          Checks if the specified item is a number.
 Map checkMap(Item it)
          Assures that the given (non-null) item is a map.
 ANode checkNode(Expr e, QueryContext ctx)
          Checks if the specified expression yields a node.
 ANode checkNode(Item it)
          Checks if the specified item is a node.
 ANode checkNode(QueryContext ctx)
          Throws an exception if the context value is not a node.
 Item checkNoEmpty(Item it)
          Checks if the specified item is no empty sequence.
 void checkNoneUp(Expr... expr)
          Ensures that none of the specified expressions performs an update.
 void checkNoUp(Expr e)
          Ensures that the specified expression performs no updates.
 QNm checkQNm(Expr e, QueryContext ctx)
          Checks if the specified expression has the specified type; if no, throws an exception.
 byte[] checkStr(Expr e, QueryContext ctx)
          Checks if the specified expression yields a string.
 byte[] checkStr(Item it)
          Checks if the specified item is a string.
 byte[] checkStrBin(Item it)
          Checks if the specified expression yields a string or binary item.
 Item checkType(Item it, Type t)
          Checks if the specified expression is an empty sequence; if yes, throws an exception.
 Data checkWrite(Data data, QueryContext ctx)
          Checks if the current user has write permissions for the specified database.
static Expr compBln(Expr e, InputInfo ii)
          Returns a boolean equivalent for the specified expression.
protected
<T extends ParseExpr>
T
copyType(T e)
          Copies this expression's return type and size to the given expression.
 Item ebv(QueryContext ctx, InputInfo ii)
          Checks if the iterator can be dissolved into an effective boolean value.
 Item item(QueryContext ctx, InputInfo ii)
          Evaluates the expression and returns the resulting item or a null reference, if the expression yields an empty sequence.
 Iter iter(QueryContext ctx)
          Evaluates the expression and returns an iterator on the resulting items.
protected  Expr optPre(Expr opt, QueryContext ctx)
          Adds an optimization info for pre-evaluating the specified expression.
 Expr preEval(QueryContext ctx)
          Pre-evaluates the specified expression.
 long size()
          Returns the sequence size or 1.
 Item test(QueryContext ctx, InputInfo ii)
          Performs a predicate test and returns the item if test was successful.
 SeqType type()
          Returns the static type of the evaluated value.
 Value value(QueryContext ctx)
          Evaluates the expression and returns the resulting value.
 
Methods inherited from class org.basex.query.expr.Expr
accept, addText, checkUp, compEbv, compile, copy, copy, count, exprSize, has, hasFreeVars, indexAccessible, indexEquivalent, inline, inlineAll, isEmpty, isFunction, isItem, isVacuous, isValue, iterable, markTailCalls, optimize, removable, sameAs, uses, visitAll
 
Methods inherited from class org.basex.data.ExprInfo
addPlan, addPlan, description, info, plan, planAttr, planElem, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

info

public InputInfo info
Input information.


size

public long size
Cardinality of result; unknown if set to -1.


type

public SeqType type
Static type.

Constructor Detail

ParseExpr

protected ParseExpr(InputInfo ii)
Constructor.

Parameters:
ii - input info
Method Detail

iter

public Iter iter(QueryContext ctx)
          throws QueryException
Description copied from class: Expr
Evaluates the expression and returns an iterator on the resulting items. If this method is not overwritten, Expr.item(org.basex.query.QueryContext, org.basex.util.InputInfo) must be implemented by an expression, as it may be called by this method.

Specified by:
iter in class Expr
Parameters:
ctx - query context
Returns:
resulting item
Throws:
QueryException - query exception

item

public Item item(QueryContext ctx,
                 InputInfo ii)
          throws QueryException
Description copied from class: Expr
Evaluates the expression and returns the resulting item or a null reference, if the expression yields an empty sequence. If this method is not overwritten, Expr.iter(org.basex.query.QueryContext) must be implemented by an expression, as it may be called by this method.

Specified by:
item in class Expr
Parameters:
ctx - query context
ii - input info
Returns:
iterator
Throws:
QueryException - query exception

value

public Value value(QueryContext ctx)
            throws QueryException
Description copied from class: Expr
Evaluates the expression and returns the resulting value.

Specified by:
value in class Expr
Parameters:
ctx - query context
Returns:
iterator
Throws:
QueryException - query exception

copyType

protected final <T extends ParseExpr> T copyType(T e)
Copies this expression's return type and size to the given expression.

Type Parameters:
T - expression type
Parameters:
e - expression
Returns:
the expression for convenience

ebv

public final Item ebv(QueryContext ctx,
                      InputInfo ii)
               throws QueryException
Description copied from class: Expr
Checks if the iterator can be dissolved into an effective boolean value. If not, returns an error. If yes, returns the first value - which can be also be e.g. an integer, which is later evaluated as numeric predicate.

Specified by:
ebv in class Expr
Parameters:
ctx - query context
ii - input info
Returns:
item
Throws:
QueryException - query exception

test

public final Item test(QueryContext ctx,
                       InputInfo ii)
                throws QueryException
Description copied from class: Expr
Performs a predicate test and returns the item if test was successful.

Specified by:
test in class Expr
Parameters:
ctx - query context
ii - input info
Returns:
item
Throws:
QueryException - query exception

type

public SeqType type()
Description copied from class: Expr
Returns the static type of the evaluated value. For simplicity, some types have been merged to super types. As an example, many numeric types are treated as integers.

Specified by:
type in class Expr
Returns:
result of check

size

public final long size()
Description copied from class: Expr
Returns the sequence size or 1.

Specified by:
size in class Expr
Returns:
result of check

preEval

public final Expr preEval(QueryContext ctx)
                   throws QueryException
Pre-evaluates the specified expression.

Parameters:
ctx - query context
Returns:
optimized expression
Throws:
QueryException - query exception

optPre

protected final Expr optPre(Expr opt,
                            QueryContext ctx)
Adds an optimization info for pre-evaluating the specified expression.

Parameters:
opt - optimized expression
ctx - query context
Returns:
optimized expression

compBln

public static final Expr compBln(Expr e,
                                 InputInfo ii)
Returns a boolean equivalent for the specified expression. If the specified expression yields a boolean value anyway, it will be returned as is. Otherwise, it will be wrapped into a boolean function.

Parameters:
e - expression to be rewritten
ii - input info
Returns:
expression

checkNoUp

public void checkNoUp(Expr e)
               throws QueryException
Ensures that the specified expression performs no updates. Otherwise, throws an exception.

Parameters:
e - expression (may be null)
Throws:
QueryException - query exception

checkNoneUp

public final void checkNoneUp(Expr... expr)
                       throws QueryException
Ensures that none of the specified expressions performs an update. Otherwise, throws an exception.

Parameters:
expr - expressions (may contain null references)
Throws:
QueryException - query exception

checkAllUp

public void checkAllUp(Expr... expr)
                throws QueryException
Ensures that all specified expressions are either updating or vacuous. Otherwise, throws an exception.

Parameters:
expr - expressions to be checked
Throws:
QueryException - query exception

checkBln

public final boolean checkBln(Expr e,
                              QueryContext ctx)
                       throws QueryException
Checks if the specified expression yields a boolean. Returns the boolean or throws an exception.

Parameters:
e - expression to be checked
ctx - query context
Returns:
boolean
Throws:
QueryException - query exception

checkDbl

public final double checkDbl(Expr e,
                             QueryContext ctx)
                      throws QueryException
Checks if the specified expression yields a double. Returns the double or throws an exception.

Parameters:
e - expression to be checked
ctx - query context
Returns:
double
Throws:
QueryException - query exception

checkItr

public final long checkItr(Expr e,
                           QueryContext ctx)
                    throws QueryException
Checks if the specified expression is an integer. Returns a token representation or an exception.

Parameters:
e - expression to be checked
ctx - query context
Returns:
integer value
Throws:
QueryException - query exception

checkItr

public final long checkItr(Item it)
                    throws QueryException
Checks if the specified item is a number. Returns a token representation or an exception.

Parameters:
it - item to be checked
Returns:
item
Throws:
QueryException - query exception

checkNode

public final ANode checkNode(Expr e,
                             QueryContext ctx)
                      throws QueryException
Checks if the specified expression yields a node. Returns the boolean or throws an exception.

Parameters:
e - expression to be checked
ctx - query context
Returns:
boolean
Throws:
QueryException - query exception

checkNode

public final ANode checkNode(Item it)
                      throws QueryException
Checks if the specified item is a node. Returns the node or an exception.

Parameters:
it - item to be checked
Returns:
item
Throws:
QueryException - query exception

checkDBNode

public final DBNode checkDBNode(Item it)
                         throws QueryException
Checks if the specified expression is a database node. Returns the node or an exception.

Parameters:
it - item to be checked
Returns:
item
Throws:
QueryException - query exception

checkColl

public final Collation checkColl(Expr e,
                                 QueryContext ctx)
                          throws QueryException
Checks if the specified collation is supported.

Parameters:
e - expression to be checked
ctx - query context
Returns:
collator, or null (default collation)
Throws:
QueryException - query exception

checkStr

public final byte[] checkStr(Expr e,
                             QueryContext ctx)
                      throws QueryException
Checks if the specified expression yields a string. Returns a token representation or an exception.

Parameters:
e - expression to be evaluated
ctx - query context
Returns:
string representation
Throws:
QueryException - query exception

checkStr

public final byte[] checkStr(Item it)
                      throws QueryException
Checks if the specified item is a string. Returns a token representation or an exception.

Parameters:
it - item to be checked
Returns:
string representation
Throws:
QueryException - query exception

checkEStr

public final byte[] checkEStr(Item it)
                       throws QueryException
Checks if the specified item is a string or an empty sequence. Returns a token representation or an exception.

Parameters:
it - item to be checked
Returns:
string representation
Throws:
QueryException - query exception

checkCtx

public final Value checkCtx(QueryContext ctx)
                     throws QueryException
Throws an exception if the context value is not set.

Parameters:
ctx - query context
Returns:
context
Throws:
QueryException - query exception

checkNode

public final ANode checkNode(QueryContext ctx)
                      throws QueryException
Throws an exception if the context value is not a node.

Parameters:
ctx - query context
Returns:
context
Throws:
QueryException - query exception

checkItem

public final Item checkItem(Expr e,
                            QueryContext ctx)
                     throws QueryException
Checks if the specified expression yields a non-empty item.

Parameters:
e - expression to be evaluated
ctx - query context
Returns:
item
Throws:
QueryException - query exception

checkBinary

public final Bin checkBinary(Expr e,
                             QueryContext ctx)
                      throws QueryException
Checks if the specified expression yields a binary item.

Parameters:
e - expression to be evaluated
ctx - query context
Returns:
binary item
Throws:
QueryException - query exception

checkStrBin

public final byte[] checkStrBin(Item it)
                         throws QueryException
Checks if the specified expression yields a string or binary item.

Parameters:
it - item to be checked
Returns:
byte representation
Throws:
QueryException - query exception

checkQNm

public final QNm checkQNm(Expr e,
                          QueryContext ctx)
                   throws QueryException
Checks if the specified expression has the specified type; if no, throws an exception.

Parameters:
e - expression to be checked
ctx - query context
Returns:
specified item
Throws:
QueryException - query exception

checkFunc

public FItem checkFunc(Expr e,
                       QueryContext ctx)
                throws QueryException
Checks if the specified expression yields a string or binary item. Checks the type of the given function item.

Parameters:
e - expression to be evaluated
ctx - query context
Returns:
function item
Throws:
QueryException - query exception

checkType

public final Item checkType(Item it,
                            Type t)
                     throws QueryException
Checks if the specified expression is an empty sequence; if yes, throws an exception.

Parameters:
it - item to be checked
t - type to be checked
Returns:
specified item
Throws:
QueryException - query exception

checkNoEmpty

public final Item checkNoEmpty(Item it)
                        throws QueryException
Checks if the specified item is no empty sequence.

Parameters:
it - item to be checked
Returns:
specified item
Throws:
QueryException - query exception

checkEStr

public final byte[] checkEStr(Expr e,
                              QueryContext ctx)
                       throws QueryException
Checks if the specified expression yields a string or empty sequence. Returns a token representation or an exception.

Parameters:
e - expression to be evaluated
ctx - query context
Returns:
item
Throws:
QueryException - query exception

checkAdmin

public final void checkAdmin(QueryContext ctx)
                      throws QueryException
Checks if the current user has create permissions. If negative, an exception is thrown.

Parameters:
ctx - query context
Throws:
QueryException - query exception

checkCreate

public final void checkCreate(QueryContext ctx)
                       throws QueryException
Checks if the current user has create permissions. If negative, an exception is thrown.

Parameters:
ctx - query context
Throws:
QueryException - query exception

checkWrite

public final Data checkWrite(Data data,
                             QueryContext ctx)
                      throws QueryException
Checks if the current user has write permissions for the specified database. If negative, an exception is thrown.

Parameters:
data - data reference
ctx - query context
Returns:
data reference
Throws:
QueryException - query exception

checkMap

public Map checkMap(Item it)
             throws QueryException
Assures that the given (non-null) item is a map.

Parameters:
it - item to check
Returns:
the map
Throws:
QueryException - if the item is not a map