net.sf.saxon.expr

Class IfExpression

public class IfExpression extends ComputedExpression implements TailCallReturner

An IfExpression returns the value of either the "then" part or the "else" part, depending on the value of the condition
Constructor Summary
IfExpression(Expression condition, Expression thenExp, Expression elseExp)
Constructor
Method Summary
voidcheckPermittedContents(SchemaType parentType, StaticContext env, boolean whole)
Check that any elements and attributes constructed or returned by this expression are acceptable in the content model of a given complex type.
intcomputeCardinality()
Determine the static cardinality of the result
intcomputeSpecialProperties()
Get the static properties of this expression (other than its type).
voiddisplay(int level, NamePool pool, PrintStream out)
Diagnostic print of expression structure
ItemevaluateItem(XPathContext context)
Evaluate the conditional expression in a given context
ExpressiongetCondition()
ExpressiongetElseExpression()
ItemTypegetItemType(TypeHierarchy th)
Get data type of items in sequence returned by expression
ExpressiongetThenExpression()
SequenceIteratoriterate(XPathContext context)
Iterate the path-expression in a given context
IteratoriterateSubExpressions()
Get the immediate subexpressions of this expression
booleanmarkTailFunctionCalls()
Mark tail calls on used-defined functions.
Expressionoptimize(Optimizer opt, StaticContext env, ItemType contextItemType)
voidprocess(XPathContext context)
Process this expression as an instruction, writing results to the current receiver
TailCallprocessLeavingTail(XPathContext context)
ProcessLeavingTail: called to do the real work of this instruction.
Expressionpromote(PromotionOffer offer)
Promote this expression if possible
voidsetCondition(Expression exp)
voidsetThenExpression(Expression exp)
Expressionsimplify(StaticContext env)
Simplify an expression
voidsuppressValidation(int validationMode)
Suppress validation on contained element constructors, on the grounds that the parent element is already performing validation.
ExpressiontypeCheck(StaticContext env, ItemType contextItemType)
Type-check the expression

Constructor Detail

IfExpression

public IfExpression(Expression condition, Expression thenExp, Expression elseExp)
Constructor

Method Detail

checkPermittedContents

public void checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole)
Check that any elements and attributes constructed or returned by this expression are acceptable in the content model of a given complex type. It's always OK to say yes, since the check will be repeated at run-time. The process of checking element and attribute constructors against the content model of a complex type also registers the type of content expected of those constructors, so the static validation can continue recursively.

computeCardinality

public int computeCardinality()
Determine the static cardinality of the result

computeSpecialProperties

public int computeSpecialProperties()
Get the static properties of this expression (other than its type). The result is bit-signficant. These properties are used for optimizations. In general, if property bit is set, it is true, but if it is unset, the value is unknown.

display

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

evaluateItem

public Item evaluateItem(XPathContext context)
Evaluate the conditional expression in a given context

Parameters: context the evaluation context

getCondition

public Expression getCondition()

getElseExpression

public Expression getElseExpression()

getItemType

public ItemType getItemType(TypeHierarchy th)
Get data type of items in sequence returned by expression

Parameters: th

getThenExpression

public Expression getThenExpression()

iterate

public SequenceIterator iterate(XPathContext context)
Iterate the path-expression in a given context

Parameters: context the evaluation context

iterateSubExpressions

public Iterator iterateSubExpressions()
Get the immediate subexpressions of this expression

markTailFunctionCalls

public boolean markTailFunctionCalls()
Mark tail calls on used-defined functions. For most expressions, this does nothing.

optimize

public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType)

process

public void process(XPathContext context)
Process this expression as an instruction, writing results to the current receiver

processLeavingTail

public TailCall processLeavingTail(XPathContext context)
ProcessLeavingTail: called to do the real work of this instruction. This method must be implemented in each subclass. The results of the instruction are written to the current Receiver, which can be obtained via the Controller.

Parameters: context The dynamic context of the transformation, giving access to the current node, the current variables, etc.

Returns: null if the instruction has completed execution; or a TailCall indicating a function call or template call that is delegated to the caller, to be made after the stack has been unwound so as to save stack space.

promote

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

setCondition

public void setCondition(Expression exp)

setThenExpression

public void setThenExpression(Expression exp)

simplify

public Expression simplify(StaticContext env)
Simplify an expression

suppressValidation

public void suppressValidation(int validationMode)
Suppress validation on contained element constructors, on the grounds that the parent element is already performing validation. The default implementation does nothing.

typeCheck

public Expression typeCheck(StaticContext env, ItemType contextItemType)
Type-check the expression