net.sf.saxon.expr
Class CastExpression

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

public final class CastExpression
extends ComputedExpression

Cast Expression: implements "cast as data-type ( expression )". It also allows an internal cast, which has the same semantics as a user-requested cast, but maps an empty sequence to an empty sequence.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sf.saxon.expr.ComputedExpression
lineNumber, NO_ARGUMENTS, staticProperties
 
Constructor Summary
CastExpression(Expression source, AtomicType target)
           
CastExpression(Expression source, AtomicType target, boolean allowEmpty)
           
 
Method Summary
 Expression analyze(StaticContext env)
          Type-check the expression
 int computeCardinality()
          Get the static cardinality of the expression
 void display(int level, NamePool pool)
          Diagnostic print of expression structure
 Item evaluateItem(XPathContext context)
          Evaluate the expression
 ItemType getItemType()
          Get the static type of the 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, effectiveBooleanValue, 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
 

Constructor Detail

CastExpression

public CastExpression(Expression source,
                      AtomicType target)
               throws XPathException
Throws:
XPathException

CastExpression

public CastExpression(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

computeCardinality

public int computeCardinality()
Get the static cardinality of the expression

Specified by:
computeCardinality in class ComputedExpression

getItemType

public ItemType getItemType()
Get the static type of the expression

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

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

display

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

Parameters:
level - indentation level for this expression