org.basex.query.func
Class StandardFunc

java.lang.Object
  extended by org.basex.data.ExprInfo
      extended by org.basex.query.expr.Expr
          extended by org.basex.query.expr.ParseExpr
              extended by org.basex.query.expr.Arr
                  extended by org.basex.query.func.StandardFunc
Direct Known Subclasses:
FNAcc, FNAdmin, FNAggr, FNArchive, FNClient, FNContext, FNConvert, FNCrypto, FNDate, FNDb, FNFetch, FNFile, FNFormat, FNFt, FNFunc, FNGen, FNHash, FNHof, FNHtml, FNHttp, FNId, FNIndex, FNInfo, FNInspect, FNJson, FNMap, FNMath, FNNode, FNNum, FNOut, FNPat, FNProc, FNProf, FNQName, FNRandom, FNRepo, FNSeq, FNSimple, FNSql, FNStr, FNStream, FNUnit, FNValidate, FNXQuery, FNXslt, FNZip

public abstract class StandardFunc
extends Arr

Standard (built-in) functions.

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
 
Fields inherited from class org.basex.query.expr.Arr
expr
 
Fields inherited from class org.basex.query.expr.ParseExpr
info, size, type
 
Constructor Summary
protected StandardFunc(InputInfo ii, Function s, Expr... args)
          Constructor.
 
Method Summary
static Item atom(Item it, InputInfo ii)
          Atomizes the specified item.
protected  java.util.HashMap<java.lang.String,Value> bindings(int i, QueryContext ctx)
          Returns all keys and values of the specified binding argument.
protected  void cache(Iter ir, ValueBuilder vb, QueryContext ctx)
          Caches and materializes all items of the specified iterator.
protected  Data checkData(QueryContext ctx)
          Returns a data instance for the first string argument of the function.
protected  java.io.File checkFile(int i, QueryContext ctx)
          Converts the specified argument to a file instance.
 Expr compile(QueryContext ctx, VarScope scp)
          Compiles and optimizes the expression, assigns data types and cardinalities.
 StandardFunc copy(QueryContext ctx, VarScope scp, IntObjMap<Var> vs)
          Copies an expression.
protected  boolean dataLock(ASTVisitor visitor)
          Checks if the specified database can be detected for locking, i.e., if the first argument of the tested function is a static string.
protected  long dateTimeToMs(Expr e, QueryContext ctx)
          Converts the specified dateTime to milliseconds.
 java.lang.String description()
          Returns a string description of the expression.
protected  java.lang.String encoding(int i, Err err, QueryContext ctx)
          Returns a normalized encoding representation.
 boolean has(Expr.Flag flag)
          Indicates if an expression has the specified compiler property.
 boolean isFunction(Function f)
          Checks if this expression is a certain function.
 boolean isVacuous()
          Tests if this is a vacuous expression (empty sequence or error function).
protected static boolean oneOf(Function sig, Function... sigs)
          Compares several signatures for equality.
protected  Expr opt(QueryContext ctx)
          Performs function specific optimizations.
 Expr optimize(QueryContext ctx, VarScope scp)
          Optimizes an already compiled expression without recompiling its sub-expressions.
 void plan(FElem plan)
          Creates an expression tree.
 java.lang.String toString()
           
 
Methods inherited from class org.basex.query.expr.Arr
accept, allAreValues, checkNoUp, checkUp, copyAll, count, exprSize, indexEquivalent, inline, removable, toString
 
Methods inherited from class org.basex.query.expr.ParseExpr
checkAdmin, checkAllUp, checkBinary, checkBln, checkColl, checkCreate, checkCtx, checkDbl, checkDBNode, checkEStr, checkEStr, checkFunc, checkItem, checkItr, checkItr, checkMap, checkNode, checkNode, checkNode, checkNoEmpty, checkNoneUp, checkNoUp, checkQNm, checkStr, checkStr, checkStrBin, checkType, checkWrite, compBln, copyType, ebv, item, iter, optPre, preEval, size, test, type, value
 
Methods inherited from class org.basex.query.expr.Expr
addText, compEbv, copy, hasFreeVars, indexAccessible, inlineAll, isEmpty, isItem, isValue, iterable, markTailCalls, sameAs, uses, visitAll
 
Methods inherited from class org.basex.data.ExprInfo
addPlan, addPlan, info, planAttr, planElem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StandardFunc

protected StandardFunc(InputInfo ii,
                       Function s,
                       Expr... args)
Constructor.

Parameters:
ii - input info
s - function definition
args - arguments
Method Detail

compile

public final Expr compile(QueryContext ctx,
                          VarScope scp)
                   throws QueryException
Description copied from class: Expr
Compiles and optimizes the expression, assigns data types and cardinalities.

Overrides:
compile in class Arr
Parameters:
ctx - query context
scp - variable scope
Returns:
optimized expression
Throws:
QueryException - query exception

optimize

public final Expr optimize(QueryContext ctx,
                           VarScope scp)
                    throws QueryException
Description copied from class: Expr
Optimizes an already compiled expression without recompiling its sub-expressions.

Overrides:
optimize in class Expr
Parameters:
ctx - query context
scp - variable scope
Returns:
optimized expression
Throws:
QueryException - query exception

opt

protected Expr opt(QueryContext ctx)
            throws QueryException
Performs function specific optimizations.

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

copy

public final StandardFunc copy(QueryContext ctx,
                               VarScope scp,
                               IntObjMap<Var> vs)
Description copied from class: Expr
Copies an expression. Will be useful for inlining functions, or for copying static queries.

Specified by:
copy in class Expr
Parameters:
ctx - query context
scp - variable scope for creating new variables
vs - mapping from old variable IDs to new variable copies
Returns:
copied expression

atom

public static final Item atom(Item it,
                              InputInfo ii)
                       throws QueryException
Atomizes the specified item.

Parameters:
it - input item
ii - input info
Returns:
atomized item
Throws:
QueryException - query exception

has

public boolean has(Expr.Flag flag)
Description copied from class: Expr
Indicates if an expression has the specified compiler property. This method is called by numerous Expr.compile(org.basex.query.QueryContext, org.basex.query.var.VarScope) methods to test properties of sub-expressions. It returns true if at least one test is successful.

Overrides:
has in class Arr
Parameters:
flag - flag to be found
Returns:
result of check

isFunction

public final boolean isFunction(Function f)
Description copied from class: Expr
Checks if this expression is a certain function.

Overrides:
isFunction in class Expr
Parameters:
f - function definition
Returns:
result of check

isVacuous

public final boolean isVacuous()
Description copied from class: Expr
Tests if this is a vacuous expression (empty sequence or error function). This check is needed for updating queries.

Overrides:
isVacuous in class Expr
Returns:
result of check

description

public final java.lang.String description()
Description copied from class: ExprInfo
Returns a string description of the expression. This method is only called by error messages. Contrary to the ExprInfo.toString() method, arguments are not included in the output.

Overrides:
description in class ExprInfo
Returns:
result of check

plan

public final void plan(FElem plan)
Description copied from class: ExprInfo
Creates an expression tree.

Overrides:
plan in class Arr
Parameters:
plan - root element

toString

public final java.lang.String toString()
Specified by:
toString in class ExprInfo

checkData

protected final Data checkData(QueryContext ctx)
                        throws QueryException
Returns a data instance for the first string argument of the function. This method assumes that the function has at least one argument.

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

checkFile

protected java.io.File checkFile(int i,
                                 QueryContext ctx)
                          throws QueryException
Converts the specified argument to a file instance.

Parameters:
i - argument index
ctx - query context
Returns:
file instance
Throws:
QueryException - query exception

dataLock

protected final boolean dataLock(ASTVisitor visitor)
Checks if the specified database can be detected for locking, i.e., if the first argument of the tested function is a static string. This method assumes that the function has at least one argument.

Parameters:
visitor - visitor
Returns:
result of check

encoding

protected final java.lang.String encoding(int i,
                                          Err err,
                                          QueryContext ctx)
                                   throws QueryException
Returns a normalized encoding representation.

Parameters:
i - index of encoding argument
err - error for invalid encoding
ctx - query context
Returns:
text entry
Throws:
QueryException - query exception

dateTimeToMs

protected final long dateTimeToMs(Expr e,
                                  QueryContext ctx)
                           throws QueryException
Converts the specified dateTime to milliseconds.

Parameters:
e - expression
ctx - query context
Returns:
resulting value
Throws:
QueryException - query exception

bindings

protected final java.util.HashMap<java.lang.String,Value> bindings(int i,
                                                                   QueryContext ctx)
                                                            throws QueryException
Returns all keys and values of the specified binding argument.

Parameters:
i - index of argument
ctx - query context
Returns:
resulting map
Throws:
QueryException - query exception

cache

protected final void cache(Iter ir,
                           ValueBuilder vb,
                           QueryContext ctx)
                    throws QueryException
Caches and materializes all items of the specified iterator.

Parameters:
ir - iterator
vb - value builder
ctx - query context
Throws:
QueryException - query exception

oneOf

protected static boolean oneOf(Function sig,
                               Function... sigs)
Compares several signatures for equality.

Parameters:
sig - signature to be found
sigs - signatures to be compared
Returns:
result of check