org.cdlib.xtf.saxonExt
Class InstructionWithContent

Object
  extended by Expression
      extended by Instruction
          extended by InstructionWithContent
All Implemented Interfaces:
Serializable, SourceLocator, Container, EvaluableItem, SequenceIterable, TailCallReturner, InstructionInfoProvider
Direct Known Subclasses:
OutputElement.OutputInstruction, SendElement.SendInstruction

public abstract class InstructionWithContent
extends Instruction

Base class that automates much of the tedious Saxon housekeeping for an extension instruction that supports arbitrary content.

Author:
Martin Haye
See Also:
Serialized Form

Field Summary
protected  Map<String,Expression> attribs
           
protected  Expression content
           
protected  String name
           
private  int nameCode
           
 
Fields inherited from class Expression
EVALUATE_METHOD, ITERATE_METHOD, locationId, PROCESS_METHOD, staticProperties
 
Constructor Summary
InstructionWithContent(String name, Map<String,Expression> attribs, Expression content)
          Construct the content instruction.
 
Method Summary
 boolean createsNewNodes()
          Determine whether this instruction creates new nodes.
 void display(int level, PrintStream out, Configuration config)
          Diagnostic print of expression structure.
 int getCardinality()
           
 int getInstructionNameCode()
          Get the name of this instruction for diagnostic and tracing purposes
 ItemType getItemType(TypeHierarchy th)
           
 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)
 Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType)
           
abstract  TailCall processLeavingTail(XPathContext context)
          This is where the main work should be performed.
protected  void promoteInst(PromotionOffer offer)
          Handle promotion offers, that is, non-local tree rewrites.
 boolean replaceSubExpression(Expression original, Expression replacement)
          Replace one subexpression by a replacement subexpression
protected static String sequenceToString(Expression exp, XPathContext context)
          Utility function to convert an expression (which might be a sequence) to a string value.
 Expression simplify(StaticContext env)
          Simplify an expression.
 Expression typeCheck(StaticContext env, ItemType contextItemType)
           
 
Methods inherited from class Instruction
appendItem, assembleParams, assembleTunnelParams, computeCardinality, computeSpecialProperties, dynamicError, evaluateAsString, evaluateItem, getImplementationMethod, getInstructionInfo, getSourceLocator, isXSLT, iterate, process, promote
 
Methods inherited from class Expression
adoptChildExpression, checkPermittedContents, computeDependencies, computeStaticProperties, doPromotion, dynamicError, effectiveBooleanValue, getColumnNumber, getConstructType, getContainingProcedure, getDependencies, getExecutable, getHostLanguage, getIntrinsicDependencies, getLineNumber, getLocationId, getLocationProvider, getParentExpression, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasBadParentPointer, markTailFunctionCalls, resetStaticProperties, setLocationId, setParentExpression, setParentExpression, suppressValidation, typeError
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface SourceLocator
getColumnNumber, getLineNumber, getPublicId, getSystemId
 

Field Detail

name

protected final String name

nameCode

private int nameCode

attribs

protected Map<String,Expression> attribs

content

protected Expression content
Constructor Detail

InstructionWithContent

public InstructionWithContent(String name,
                              Map<String,Expression> attribs,
                              Expression content)
Construct the content instruction.

Method Detail

simplify

public Expression simplify(StaticContext env)
                    throws XPathException
Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression). The default implementation does nothing.

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

typeCheck

public Expression typeCheck(StaticContext env,
                            ItemType contextItemType)
                     throws XPathException
Overrides:
typeCheck in class Expression
Throws:
XPathException

optimize

public Expression optimize(Optimizer opt,
                           StaticContext env,
                           ItemType contextItemType)
                    throws XPathException
Overrides:
optimize in class Expression
Throws:
XPathException

getInstructionNameCode

public int getInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposes

Overrides:
getInstructionNameCode in class Instruction

getItemType

public ItemType getItemType(TypeHierarchy th)
Overrides:
getItemType in class Instruction

getCardinality

public int getCardinality()
Overrides:
getCardinality in class Expression

createsNewNodes

public final boolean createsNewNodes()
Determine whether this instruction creates new nodes. This implementation returns true.

Overrides:
createsNewNodes in class Instruction

promoteInst

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

Overrides:
promoteInst in class Instruction
Parameters:
offer - The type of rewrite being offered
Throws:
XPathException

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)

Overrides:
iterateSubExpressions in class Expression

replaceSubExpression

public boolean replaceSubExpression(Expression original,
                                    Expression replacement)
Replace one subexpression by a replacement subexpression

Specified by:
replaceSubExpression in interface Container
Overrides:
replaceSubExpression in class Expression
Parameters:
original - the original subexpression
replacement - the replacement subexpression
Returns:
true if the original subexpression is found

processLeavingTail

public abstract TailCall processLeavingTail(XPathContext context)
                                     throws XPathException
This is where the main work should be performed. Subclasses must implement this method.

Specified by:
processLeavingTail in interface TailCallReturner
Specified by:
processLeavingTail in class Instruction
Throws:
XPathException

sequenceToString

protected static String sequenceToString(Expression exp,
                                         XPathContext context)
                                  throws XPathException
Utility function to convert an expression (which might be a sequence) to a string value.

Throws:
XPathException

display

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

Specified by:
display in class Expression
Parameters:
level - indentation level for this expression
out -
config -