Class ParseExpr

Direct Known Subclasses:
Arr, Clause, FTExpr, GFLWOR, IndexDb, Path, Simple, Single, 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-21, BSD License, Christian Gruen
  • Field Details

    • exprType

      public final ExprType exprType
      Expression type.
    • info

      public InputInfo info
      Input information.
  • Constructor Details

    • ParseExpr

      protected ParseExpr(InputInfo info, SeqType seqType)
      Constructor.
      Parameters:
      info - input info (can be null
      seqType - sequence type
  • Method Details

    • iter

      public Iter iter(QueryContext qc) throws QueryException
      Description copied from class: Expr
      Evaluates the expression and returns an iterator on the resulting items. The implementation of this method is optional.
      Specified by:
      iter in class Expr
      Parameters:
      qc - query context
      Returns:
      iterator
      Throws:
      QueryException - query exception
    • value

      public Value value(QueryContext qc) throws QueryException
      Description copied from class: Expr
      Evaluates the expression and returns the resulting value. If this method is not implemented, Expr.item(QueryContext, InputInfo) must be implemented instead.
      Specified by:
      value in class Expr
      Parameters:
      qc - query context
      Returns:
      value
      Throws:
      QueryException - query exception
    • item

      public Item item(QueryContext qc, InputInfo ii) throws QueryException
      Description copied from class: Expr
      Evaluates the expression and returns the resulting item, or Empty.VALUE if the expression yields an empty sequence. If this method is not implemented, Expr.value(QueryContext) must be implemented instead.
      Specified by:
      item in class Expr
      Parameters:
      qc - query context
      ii - input info (only required by Seq instances, which have no input info)
      Returns:
      item or Empty.VALUE
      Throws:
      QueryException - query exception
    • atomValue

      public final Value atomValue(QueryContext qc, InputInfo ii) throws QueryException
      Description copied from class: Expr
      Evaluates the expression and returns the atomized items.
      Specified by:
      atomValue in class Expr
      Parameters:
      qc - query context
      ii - input info (only required by Seq instances, which have no input info)
      Returns:
      atomized item
      Throws:
      QueryException - query exception
    • ebv

      public final Item ebv(QueryContext qc, InputInfo ii) throws QueryException
      Description copied from class: Expr

      Checks if the effective boolean value can be computed for this expression:

      • If it yields an empty sequence, Bln.FALSE will be returned.
      • If it yields a single item, this item will be returned.
      • If it yields nodes, the first node will be returned.
      • Otherwise, an error will be raised.

      A single numeric item may later be evaluated as positional predicate.

      Specified by:
      ebv in class Expr
      Parameters:
      qc - query context
      ii - input info (required for Seq instances, which have no input info)
      Returns:
      item
      Throws:
      QueryException - query exception
    • test

      public final Item test(QueryContext qc, InputInfo ii) throws QueryException
      Description copied from class: Expr
      Performs a predicate test and returns the item if the test was successful. The returned item is required for full-text scoring.
      Specified by:
      test in class Expr
      Parameters:
      qc - query context
      ii - input info (required for Seq instances, which have no input info)
      Returns:
      item or null
      Throws:
      QueryException - query exception
    • seqType

      public final SeqType seqType()
      Description copied from class: Expr
      Returns the static type of the resulting value.
      Specified by:
      seqType in class Expr
      Returns:
      result of check
    • size

      public final long size()
      Description copied from class: Expr
      Returns the result size, or -1 if the size is unknown.
      Specified by:
      size in class Expr
      Returns:
      result of check
    • refineType

      public final void refineType(Expr expr)
      Description copied from class: Expr
      Refines the expression type.
      Specified by:
      refineType in class Expr
      Parameters:
      expr - original expression
    • copyType

      public final <T extends Expr> T copyType(T expr)
      Copies this expression's type to the specified expression.
      Type Parameters:
      T - expression type
      Parameters:
      expr - expression to be modified
      Returns:
      specified expression
    • adoptType

      public final ParseExpr adoptType(Expr expr)
      Assigns the type from the specified expression.
      Parameters:
      expr - expression
      Returns:
      self reference
    • checkUp

      protected final <T extends XQFunctionExpr> T checkUp(T expr, boolean updating, StaticContext sc) throws QueryException
      Ensures that the specified function expression is (not) updating. Otherwise, throws an exception.
      Type Parameters:
      T - expression type
      Parameters:
      expr - expression (may be null)
      updating - indicates if expression is expected to be updating
      sc - static context
      Returns:
      specified expression
      Throws:
      QueryException - query exception
    • checkNoUp

      protected final void checkNoUp(Expr expr) throws QueryException
      Ensures that the specified expression performs no updates. Otherwise, throws an exception.
      Parameters:
      expr - expression (may be null)
      Throws:
      QueryException - query exception
    • checkNoneUp

      protected final void checkNoneUp(Expr... exprs) throws QueryException
      Ensures that none of the specified expressions performs an update. Otherwise, throws an exception.
      Parameters:
      exprs - expressions (may be null)
      Throws:
      QueryException - query exception
    • checkAllUp

      protected final void checkAllUp(Expr... exprs) throws QueryException
      Ensures that all specified expressions are vacuous or either updating or non-updating. Otherwise, throws an exception.
      Parameters:
      exprs - expressions to be checked
      Throws:
      QueryException - query exception
    • ctxValue

      protected final Value ctxValue(QueryContext qc) throws QueryException
      Returns the current context value or throws an exception if the context value is not set.
      Parameters:
      qc - query context
      Returns:
      context value
      Throws:
      QueryException - query exception
    • toToken

      protected final byte[] toToken(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a string.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      token
      Throws:
      QueryException - query exception
    • toZeroToken

      protected final byte[] toZeroToken(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a string or an empty sequence.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      token (zero-length if result is an empty sequence)
      Throws:
      QueryException - query exception
    • toTokenOrNull

      protected final byte[] toTokenOrNull(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a string or an empty sequence.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      token, or null if result is an empty sequence
      Throws:
      QueryException - query exception
    • toToken

      protected final byte[] toToken(Item item) throws QueryException
      Checks if the specified non-empty item is a string.
      Parameters:
      item - item to be checked
      Returns:
      token
      Throws:
      QueryException - query exception
    • toBoolean

      protected final boolean toBoolean(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a boolean.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      boolean
      Throws:
      QueryException - query exception
    • toBoolean

      protected final boolean toBoolean(Item item) throws QueryException
      Checks if the specified item is a boolean.
      Parameters:
      item - item be checked
      Returns:
      boolean
      Throws:
      QueryException - query exception
    • toDouble

      protected final double toDouble(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a double.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      double
      Throws:
      QueryException - query exception
    • toDouble

      protected final double toDouble(Item item) throws QueryException
      Checks if the specified item is a double.
      Parameters:
      item - item
      Returns:
      double
      Throws:
      QueryException - query exception
    • toNumberOrNull

      protected final ANum toNumberOrNull(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a number or null.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      double or null
      Throws:
      QueryException - query exception
    • toNumber

      protected final ANum toNumber(Item item) throws QueryException
      Checks if the specified, non-empty item is a double.
      Parameters:
      item - item to be checked
      Returns:
      number
      Throws:
      QueryException - query exception
    • toFloat

      protected final float toFloat(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a float.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      float
      Throws:
      QueryException - query exception
    • toLong

      protected final long toLong(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields an integer.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      integer value
      Throws:
      QueryException - query exception
    • toLong

      protected final long toLong(Item item) throws QueryException
      Checks if the specified item is an integer.
      Parameters:
      item - item to be checked
      Returns:
      number
      Throws:
      QueryException - query exception
    • toNode

      protected final ANode toNode(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a node.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      node
      Throws:
      QueryException - query exception
    • toNodeOrNull

      protected final ANode toNodeOrNull(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a node or null.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      node or null
      Throws:
      QueryException - query exception
    • toNode

      protected final ANode toNode(Item item) throws QueryException
      Checks if the specified non-empty item is a node.
      Parameters:
      item - item to be checked
      Returns:
      node
      Throws:
      QueryException - query exception
    • toItem

      protected final Item toItem(Expr expr, QueryContext qc) throws QueryException
      Checks if the evaluated expression yields a non-empty item.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      item
      Throws:
      QueryException - query exception
    • toItem

      protected final Item toItem(Expr expr, QueryContext qc, Type type) throws QueryException
      Checks if the specified expression yields a non-empty item.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      type - expected type
      Returns:
      item
      Throws:
      QueryException - query exception
    • toAtomItem

      protected final Item toAtomItem(Expr expr, QueryContext qc) throws QueryException
      Checks if the evaluated expression yields a non-empty item.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      atomized item
      Throws:
      QueryException - query exception
    • toElem

      protected final ANode toElem(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields an element.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      element
      Throws:
      QueryException - query exception
    • toBin

      protected final Bin toBin(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a binary item.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      binary item
      Throws:
      QueryException - query exception
    • toBin

      protected final Bin toBin(Item item) throws QueryException
      Checks if the specified item is a binary item.
      Parameters:
      item - item to be checked
      Returns:
      binary item
      Throws:
      QueryException - query exception
    • toBytes

      protected final byte[] toBytes(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a string or binary item.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      byte array
      Throws:
      QueryException - query exception
    • toB64

      protected final B64 toB64(Expr expr, QueryContext qc, boolean empty) throws QueryException
      Checks if the specified expression yields a Base64 item.
      Parameters:
      empty - allow empty result
      expr - expression to be evaluated
      qc - query context
      Returns:
      Base64 item
      Throws:
      QueryException - query exception
    • toB64

      protected final B64 toB64(Item item, boolean empty) throws QueryException
      Checks if the specified item is a Base64 item.
      Parameters:
      empty - allow empty result
      item - item
      Returns:
      Base64 item, or null if the argument is an empty sequence and if empty is true
      Throws:
      QueryException - query exception
    • toBytes

      protected final byte[] toBytes(Item item) throws QueryException
      Checks if the specified item is a string or binary item.
      Parameters:
      item - item to be checked
      Returns:
      byte array
      Throws:
      QueryException - query exception
    • toQNm

      protected final QNm toQNm(Expr expr, QueryContext qc, boolean empty) throws QueryException
      Checks if the specified expression yields a QName.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      empty - allow empty result
      Returns:
      QName
      Throws:
      QueryException - query exception
    • toQNm

      protected final QNm toQNm(Item item, boolean empty) throws QueryException
      Checks if the specified item is a QName.
      Parameters:
      item - item
      empty - allow empty result
      Returns:
      QName, or null if the item is null and empty is true
      Throws:
      QueryException - query exception
    • toFunc

      protected final FItem toFunc(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a function.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      Returns:
      function item
      Throws:
      QueryException - query exception
    • toMap

      protected final XQMap toMap(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields a map.
      Parameters:
      expr - expression
      qc - query context
      Returns:
      map
      Throws:
      QueryException - query exception
    • toMap

      protected final XQMap toMap(Item item) throws QueryException
      Checks if the specified item is a map.
      Parameters:
      item - item to check
      Returns:
      map
      Throws:
      QueryException - if the item is not a map
    • toArray

      protected final XQArray toArray(Expr expr, QueryContext qc) throws QueryException
      Checks if the specified expression yields an array.
      Parameters:
      expr - expression
      qc - query context
      Returns:
      array
      Throws:
      QueryException - query exception
    • toArray

      protected final XQArray toArray(Item item) throws QueryException
      Assures that the specified item item is an array.
      Parameters:
      item - item to check
      Returns:
      the array
      Throws:
      QueryException - if the item is not an array
    • checkType

      protected final Item checkType(Expr expr, QueryContext qc, AtomType type) throws QueryException
      Checks if the specified expression yields an item of the specified atomic type.
      Parameters:
      expr - expression to be evaluated
      qc - query context
      type - type to be checked
      Returns:
      item
      Throws:
      QueryException - query exception
    • checkType

      protected final Item checkType(Item item, Type type) throws QueryException
      Checks if the specified expression is an empty sequence; if yes, throws an exception.
      Parameters:
      item - item to be checked
      type - type to be checked
      Returns:
      specified item
      Throws:
      QueryException - query exception
    • checkNoEmpty

      protected final Item checkNoEmpty(Item item) throws QueryException
      Checks if the specified item is no empty sequence.
      Parameters:
      item - item to be checked
      Returns:
      specified item
      Throws:
      QueryException - query exception
    • checkNoEmpty

      protected final Item checkNoEmpty(Item item, Type type) throws QueryException
      Checks if the specified item is no empty sequence.
      Parameters:
      item - item to be checked
      type - expected type
      Returns:
      specified item
      Throws:
      QueryException - query exception