net.sf.saxon.instruct

Class GeneralVariable

public abstract class GeneralVariable extends Instruction implements Binding

This class defines common behaviour across xsl:variable, xsl:param, and xsl:with-param; also saxon:assign
Field Summary
protected intnameCode
protected intreferenceCount
SequenceTyperequiredType
Expressionselect
Constructor Summary
GeneralVariable()
Method Summary
voiddisplay(int level, NamePool pool, PrintStream out)
Diagnostic print of expression structure.
ItemevaluateItem(XPathContext context)
Evaluate an expression as a single item.
intgetCardinality()
Get the cardinality of the result of this instruction.
intgetInstructionNameCode()
ItemTypegetItemType(TypeHierarchy th)
Get the type of the result of this instruction.
intgetLocalSlotNumber()
If this is a local variable held on the local stack frame, return the corresponding slot number.
intgetNameCode()
SequenceTypegetRequiredType()
ExpressiongetSelectExpression()
ValueRepresentationgetSelectValue(XPathContext context)
Evaluate the variable.
intgetSlotNumber()
intgetVariableFingerprint()
Get the name of the variable (as a NamePool fingerprint)
StringgetVariableName()
voidinit(Expression select, int nameCode)
booleanisAssignable()
Test whether it is permitted to assign to the variable using the saxon:assign extension element.
booleanisGlobal()
booleanisRequiredParam()
booleanisTunnelParam()
SequenceIteratoriterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence.
IteratoriterateSubExpressions()
Get all the XPath expressions associated with this instruction (in XSLT terms, the expression present on attributes of the instruction, as distinct from the child instructions in a sequence construction)
Expressionoptimize(Optimizer opt, StaticContext env, ItemType contextItemType)
protected voidpromoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.
voidsetAssignable(boolean assignable)
voidsetNameCode(int nameCode)
voidsetReferenceCount(int refCount)
voidsetRequiredParam(boolean requiredParam)
voidsetRequiredType(SequenceType required)
voidsetSelectExpression(Expression select)
voidsetSlotNumber(int s)
voidsetTunnel(boolean tunnel)
voidsetVariableName(String s)
Expressionsimplify(StaticContext env)
ExpressiontypeCheck(StaticContext env, ItemType contextItemType)

Field Detail

nameCode

protected int nameCode

referenceCount

protected int referenceCount

requiredType

SequenceType requiredType

select

Expression select

Constructor Detail

GeneralVariable

public GeneralVariable()

Method Detail

display

public void display(int level, NamePool pool, PrintStream out)
Diagnostic print of expression structure. The expression is written to the System.err output stream

Parameters: level indentation level for this expression out

evaluateItem

public Item evaluateItem(XPathContext context)
Evaluate an expression as a single item. This always returns either a single Item or null (denoting the empty sequence). No conversion is done. This method should not be used unless the static type of the expression is a subtype of "item" or "item?": that is, it should not be called if the expression may return a sequence. There is no guarantee that this condition will be detected.

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

getCardinality

public int getCardinality()
Get the cardinality of the result of this instruction. An xsl:variable instruction returns nothing, so the type is empty.

Returns: the empty cardinality.

getInstructionNameCode

public int getInstructionNameCode()

getItemType

public ItemType getItemType(TypeHierarchy th)
Get the type of the result of this instruction. An xsl:variable instruction returns nothing, so the type is empty.

Parameters: th

Returns: the empty type.

getLocalSlotNumber

public int getLocalSlotNumber()
If this is a local variable held on the local stack frame, return the corresponding slot number. In other cases, return -1.

getNameCode

public int getNameCode()

getRequiredType

public SequenceType getRequiredType()

getSelectExpression

public Expression getSelectExpression()

getSelectValue

public ValueRepresentation getSelectValue(XPathContext context)
Evaluate the variable. That is, get the value of the select expression if present or the content of the element otherwise, either as a tree or as a sequence

getSlotNumber

public int getSlotNumber()

getVariableFingerprint

public int getVariableFingerprint()
Get the name of the variable (as a NamePool fingerprint)

Returns: the NamePool fingerprint of the variable's expanded name.

getVariableName

public String getVariableName()

init

public void init(Expression select, int nameCode)

isAssignable

public final boolean isAssignable()
Test whether it is permitted to assign to the variable using the saxon:assign extension element. This will only be true if the extra attribute saxon:assignable="yes" is present.

isGlobal

public boolean isGlobal()

isRequiredParam

public final boolean isRequiredParam()

isTunnelParam

public final boolean isTunnelParam()

iterate

public SequenceIterator iterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation relies on the process() method: it "pushes" the results of the instruction to a sequence in memory, and then iterates over this in-memory sequence. In principle instructions should implement a pipelined iterate() method that avoids the overhead of intermediate storage.

Parameters: context supplies the context for evaluation

Returns: a SequenceIterator that can be used to iterate over the result of the expression

Throws: XPathException if any dynamic error occurs evaluating the expression

iterateSubExpressions

public Iterator iterateSubExpressions()
Get all the XPath expressions associated with this instruction (in XSLT terms, the expression present on attributes of the instruction, as distinct from the child instructions in a sequence construction)

optimize

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

promoteInst

protected void promoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.

Parameters: offer The type of rewrite being offered

Throws: XPathException

setAssignable

public void setAssignable(boolean assignable)

setNameCode

public void setNameCode(int nameCode)

setReferenceCount

public void setReferenceCount(int refCount)

setRequiredParam

public void setRequiredParam(boolean requiredParam)

setRequiredType

public void setRequiredType(SequenceType required)

setSelectExpression

public void setSelectExpression(Expression select)

setSlotNumber

public void setSlotNumber(int s)

setTunnel

public void setTunnel(boolean tunnel)

setVariableName

public void setVariableName(String s)

simplify

public Expression simplify(StaticContext env)

typeCheck

public Expression typeCheck(StaticContext env, ItemType contextItemType)