net.sf.saxon.expr
Class CastableExpression

java.lang.Object
  extended by net.sf.saxon.expr.ComputedExpression
      extended by net.sf.saxon.expr.CastableExpression
All Implemented Interfaces:
Serializable, Expression

public final class CastableExpression
extends ComputedExpression

Castable Expression: implements "Expr castable as atomic-type?". The implementation simply wraps a cast expression with a try/catch.

See Also:
Serialized Form

Field Summary
(package private)  boolean allowEmpty
           
(package private)  Expression source
           
(package private)  AtomicType targetType
           
 
Fields inherited from class net.sf.saxon.expr.ComputedExpression
lineNumber, NO_ARGUMENTS, staticProperties
 
Constructor Summary
CastableExpression(Expression source, AtomicType target, boolean allowEmpty)
           
 
Method Summary
 Expression analyze(StaticContext env)
          Type-check the expression
 int computeCardinality()
           
 void display(int level, NamePool pool)
          Diagnostic print of expression structure
 boolean effectiveBooleanValue(XPathContext context)
          Get the effective boolean value of the expression.
 Item evaluateItem(XPathContext context)
          Evaluate the expression
 ItemType getItemType()
          Determine the data type of the result of the Castable expression
 Expression[] getSubExpressions()
          Get the immediate subexpressions of this expression
 Expression promote(PromotionOffer offer)
          Promote this expression if possible
 Expression simplify()
          Simplify the expression
 
Methods inherited from class net.sf.saxon.expr.ComputedExpression
computeDependencies, computeSpecialProperties, computeStaticProperties, dynamicError, evaluateAsString, getCardinality, getDependencies, getIntrinsicDependencies, getLineNumber, getSpecialProperties, iterate, markTailFunctionCalls, setLineNumber, typeError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

source

Expression source

targetType

AtomicType targetType

allowEmpty

boolean allowEmpty
Constructor Detail

CastableExpression

public CastableExpression(Expression source,
                          AtomicType target,
                          boolean allowEmpty)
                   throws XPathException
Throws:
XPathException
Method Detail

simplify

public Expression simplify()
                    throws XPathException
Simplify the expression

Specified by:
simplify in interface Expression
Overrides:
simplify in class ComputedExpression
Returns:
the simplified expression
Throws:
XPathException - if an error is discovered during expression rewriting

analyze

public Expression analyze(StaticContext env)
                   throws XPathException
Type-check the expression

Parameters:
env - the static context of the expression
Returns:
the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
Throws:
XPathException - if an error is discovered during this phase (typically a type error)

promote

public Expression promote(PromotionOffer offer)
                   throws XPathException
Promote this expression if possible

Specified by:
promote in interface Expression
Overrides:
promote in class ComputedExpression
Parameters:
offer - details of the offer, for example the offer to move expressions that don't depend on the context to an outer level in the containing expression
Returns:
if the offer is not accepted, return this expression unchanged. Otherwise return the result of rewriting the expression to promote this subexpression
Throws:
XPathException - if any error is detected

getSubExpressions

public Expression[] getSubExpressions()
Get the immediate subexpressions of this expression

Specified by:
getSubExpressions in interface Expression
Overrides:
getSubExpressions in class ComputedExpression
Returns:
an array containing the sub-expressions of this expression

getItemType

public ItemType getItemType()
Determine the data type of the result of the Castable expression

Returns:
a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)

computeCardinality

public int computeCardinality()
Specified by:
computeCardinality in class ComputedExpression

evaluateItem

public Item evaluateItem(XPathContext context)
                  throws XPathException
Evaluate the expression

Specified by:
evaluateItem in interface Expression
Overrides:
evaluateItem in class ComputedExpression
Parameters:
context - The context in which the expression is to be evaluated
Returns:
the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
Throws:
XPathException - if any dynamic error occurs evaluating the expression

effectiveBooleanValue

public boolean effectiveBooleanValue(XPathContext context)
                              throws XPathException
Description copied from class: ComputedExpression
Get the effective boolean value of the expression. This returns false if the value is the empty sequence, a zero-length string, a number equal to zero, or the boolean false. Otherwise it returns true.

Specified by:
effectiveBooleanValue in interface Expression
Overrides:
effectiveBooleanValue in class ComputedExpression
Parameters:
context - The context in which the expression is to be evaluated
Returns:
the effective boolean value
Throws:
XPathException - if any dynamic error occurs evaluating the expression

display

public void display(int level,
                    NamePool pool)
Diagnostic print of expression structure

Parameters:
level - indentation level for this expression