net.sf.saxon.expr

Class CastableExpression

Implemented Interfaces:
EvaluableItem, InstructionInfoProvider, SequenceIterable, Serializable, SourceLocator

public final class CastableExpression
extends UnaryExpression

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

Field Summary

Fields inherited from class net.sf.saxon.expr.UnaryExpression

operand

Fields inherited from class net.sf.saxon.expr.Expression

EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD, locationId, staticProperties

Constructor Summary

CastableExpression(Expression source, AtomicType target, boolean allowEmpty)
Create a "castable" expression of the form "source castable as target"

Method Summary

boolean
allowsEmpty()
Determine whether the empty sequence is allowed
int
computeCardinality()
Compute the static cardinality of this expression
int
computeSpecialProperties()
Determine the special properties of this expression
Expression
copy()
Copy an expression.
boolean
effectiveBooleanValue(XPathContext context)
Get the effective boolean value of the expression.
boolean
equals(Object other)
Is this expression the same as another expression?
Item
evaluateItem(XPathContext context)
Evaluate the expression
void
explain(ExpressionPresenter out)
Diagnostic print of expression structure.
ItemType
getItemType(TypeHierarchy th)
Determine the data type of the result of the Castable expression
AtomicType
getTargetType()
Get the target type
static boolean
isCastable(AtomicValue value, AtomicType targetType, XPathContext context)
Determine whether a value is castable to a given type
Expression
optimize(ExpressionVisitor visitor, ItemType contextItemType)
Optimize the expression
Expression
simplify(ExpressionVisitor visitor)
Simplify the expression
Expression
typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Type-check the expression

Methods inherited from class net.sf.saxon.expr.UnaryExpression

computeCardinality, computeSpecialProperties, displayExpressionName, displayOperator, equals, explain, getBaseExpression, getItemType, hashCode, iterateSubExpressions, optimize, promote, replaceSubExpression, simplify, toString, typeCheck

Methods inherited from class net.sf.saxon.expr.Expression

addToPathMap, adoptChildExpression, checkPermittedContents, computeCardinality, computeDependencies, computeSpecialProperties, computeStaticProperties, copy, display, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, explain, explain, findParentOf, getCardinality, getColumnNumber, getConstructType, getContainer, getDependencies, getExecutable, getHostLanguage, getImplementationMethod, getInstructionInfo, getIntrinsicDependencies, getItemType, getLineNumber, getLocationId, getLocationProvider, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, iterate, iterateEvents, iterateSubExpressions, markTailFunctionCalls, optimize, process, promote, replaceSubExpression, resetLocalStaticProperties, setContainer, setFiltered, setFlattened, setLocationId, simplify, staticTypeCheck, suppressValidation, toString, typeCheck, typeError

Constructor Details

CastableExpression

public CastableExpression(Expression source,
                          AtomicType target,
                          boolean allowEmpty)
Create a "castable" expression of the form "source castable as target"
Parameters:
source - The source expression
target - The type being tested against
allowEmpty - true if an empty sequence is acceptable, that is if the expression was written as "source castable as target?"

Method Details

allowsEmpty

public boolean allowsEmpty()
Determine whether the empty sequence is allowed
Returns:
true if an empty sequence is allowed

computeCardinality

public int computeCardinality()
Compute the static cardinality of this expression
Overrides:
computeCardinality in interface UnaryExpression

computeSpecialProperties

public int computeSpecialProperties()
Determine the special properties of this expression
Overrides:
computeSpecialProperties in interface UnaryExpression

copy

public Expression copy()
Copy an expression. This makes a deep copy.
Overrides:
copy in interface Expression
Returns:
the copy of the original expression

effectiveBooleanValue

public boolean effectiveBooleanValue(XPathContext context)
            throws XPathException
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.
Overrides:
effectiveBooleanValue in interface Expression
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

equals

public boolean equals(Object other)
Is this expression the same as another expression?
Overrides:
equals in interface UnaryExpression

evaluateItem

public Item evaluateItem(XPathContext context)
            throws XPathException
Evaluate the expression
Specified by:
evaluateItem in interface EvaluableItem
Overrides:
evaluateItem in interface Expression

explain

public void explain(ExpressionPresenter out)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
Overrides:
explain in interface UnaryExpression

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the data type of the result of the Castable expression
Overrides:
getItemType in interface UnaryExpression
Parameters:
th - the type hierarchy cache

getTargetType

public AtomicType getTargetType()
Get the target type
Returns:
the target type

isCastable

public static boolean isCastable(AtomicValue value,
                                 AtomicType targetType,
                                 XPathContext context)
Determine whether a value is castable to a given type
Parameters:
value - the value to be tested
targetType - the type to be tested against
context - XPath dynamic context
Returns:
true if the value is castable to the required type

optimize

public Expression optimize(ExpressionVisitor visitor,
                           ItemType contextItemType)
            throws XPathException
Optimize the expression
Overrides:
optimize in interface UnaryExpression

simplify

public Expression simplify(ExpressionVisitor visitor)
            throws XPathException
Simplify the expression
Overrides:
simplify in interface UnaryExpression
Parameters:
visitor - an expression visitor
Returns:
the simplified expression

typeCheck

public Expression typeCheck(ExpressionVisitor visitor,
                            ItemType contextItemType)
            throws XPathException
Type-check the expression
Overrides:
typeCheck in interface UnaryExpression