|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.saxon.expr.Expression
public abstract class Expression
Interface supported by an XPath expression. This includes both compile-time and run-time methods.
Field Summary | |
---|---|
static int |
EVALUATE_METHOD
|
static int |
ITERATE_METHOD
|
static int |
PROCESS_METHOD
|
Constructor Summary | |
---|---|
Expression()
|
Method Summary | |
---|---|
PathMap.PathMapNodeSet |
addToPathMap(PathMap pathMap,
PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap. |
void |
adoptChildExpression(Expression child)
Set up a parent-child relationship between this expression and a given child expression. |
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. |
int |
computeDependencies()
Compute the dependencies of an expression, as the union of the dependencies of its subexpressions. |
void |
computeStaticProperties()
Compute the static properties. |
abstract Expression |
copy()
Copy an expression. |
void |
display(int level,
PrintStream out,
Configuration config)
Deprecated. since 9.0 - use the explain method |
Expression |
doPromotion(Expression subexpression,
PromotionOffer offer)
Promote a subexpression if possible, and if the expression was changed, carry out housekeeping to reset the static properties and correct the parent pointers in the tree |
boolean |
effectiveBooleanValue(XPathContext context)
Get the effective boolean value of the expression. |
CharSequence |
evaluateAsString(XPathContext context)
Evaluate an expression as a String. |
Item |
evaluateItem(XPathContext context)
Evaluate an expression as a single item. |
abstract void |
explain(ExpressionPresenter out)
Diagnostic print of expression structure. |
void |
explain(OutputStream out)
Diagnostic print of expression structure. |
Expression |
findParentOf(Expression leaf)
Within the subtree rooted at this node, find the expression that is the parent of a given leaf node. |
int |
getCardinality()
Determine the static cardinality of the expression. |
int |
getColumnNumber()
Get the column number of the expression |
Container |
getContainer()
Get the container in which this expression is located. |
int |
getDependencies()
Determine which aspects of the context the expression depends on. |
Executable |
getExecutable()
Get the executable containing this expression |
int |
getHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container |
int |
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). |
InstructionInfo |
getInstructionInfo()
Get InstructionInfo for this expression |
int |
getIntrinsicDependencies()
Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions. |
abstract ItemType |
getItemType(TypeHierarchy th)
Determine the data type of the expression, if possible. |
int |
getLineNumber()
Get the line number of the expression |
int |
getLocationId()
Get the location ID of the expression |
LocationProvider |
getLocationProvider()
Get the LocationProvider allowing location identifiers to be resolved. |
String |
getPublicId()
Get the publicId of the module containing the expression (to satisfy the SourceLocator interface) |
int[] |
getSlotsUsed()
Get the local variables (identified by their slot numbers) on which this expression depends. |
int |
getSpecialProperties()
Get the static properties of this expression (other than its type). |
String |
getSystemId()
Get the systemId of the module containing the expression |
boolean |
hasLoopingSubexpression(Expression child)
Given an expression that is an immediate child of this expression, test whether the evaluation of the parent expression causes the child expression to be evaluated repeatedly |
boolean |
implementsStaticTypeCheck()
Determine whether this expression implements its own method for static type checking |
SequenceIterator |
iterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence. |
EventIterator |
iterateEvents(XPathContext context)
Deliver the result of the expression as a sequence of events. |
Iterator |
iterateSubExpressions()
Get the immediate sub-expressions of this expression. |
int |
markTailFunctionCalls(StructuredQName qName,
int arity)
Mark tail-recursive calls on stylesheet functions. |
Expression |
optimize(ExpressionVisitor visitor,
ItemType contextItemType)
Perform optimisation of an expression and its subexpressions. |
void |
process(XPathContext context)
Process the instruction, without returning any tail calls |
Expression |
promote(PromotionOffer offer)
Offer promotion for this subexpression. |
boolean |
replaceSubExpression(Expression original,
Expression replacement)
Replace one subexpression by a replacement subexpression |
void |
setContainer(Container container)
Mark an expression as being in a given Container. |
void |
setFiltered(boolean filtered)
Mark an expression as filtered: that is, it appears as the base expression in a filter expression. |
void |
setFlattened(boolean flattened)
Mark an expression as being "flattened". |
void |
setLocationId(int id)
Set the location ID on an expression. |
Expression |
simplify(ExpressionVisitor visitor)
Simplify an expression. |
Expression |
staticTypeCheck(SequenceType req,
boolean backwardsCompatible,
RoleLocator role,
ExpressionVisitor visitor)
Static type checking of some expressions is delegated to the expression itself, by calling this method. |
void |
suppressValidation(int validationMode)
Suppress validation on contained element constructors, on the grounds that the parent element is already performing validation. |
String |
toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath. |
Expression |
typeCheck(ExpressionVisitor visitor,
ItemType contextItemType)
Perform type checking of an expression and its subexpressions. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int EVALUATE_METHOD
public static final int ITERATE_METHOD
public static final int PROCESS_METHOD
Constructor Detail |
---|
public Expression()
Method Detail |
---|
public int getImplementationMethod()
ITERATE_METHOD
or EVALUATE_METHOD
or
PROCESS_METHOD
public boolean implementsStaticTypeCheck()
public Expression simplify(ExpressionVisitor visitor) throws XPathException
visitor
- an expression visitor
XPathException
- if an error is discovered during expression
rewritingpublic Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException
This checks statically that the operands of the expression have the correct type; if necessary it generates code to do run-time type checking or type conversion. A static type error is reported only if execution cannot possibly succeed, that is, if a run-time type error is inevitable. The call may return a modified form of the expression.
This method is called after all references to functions and variables have been resolved to the declaration of the function or variable. However, the types of such functions and variables may not be accurately known if they have not been explicitly declared.
If the implementation returns a value other than "this", then it is required to ensure that the parent pointer and location information in the returned expression have been set up correctly. It should not rely on the caller to do this, although for historical reasons many callers do so.
visitor
- an expression visitorcontextItemType
- the static type of "." at the point where this expression is invoked.
The parameter is set to null if it is known statically that the context item will be undefined.
If the type of the context item is not known statically, the argument is set to
Type.ITEM_TYPE
XPathException
- if an error is discovered during this phase
(typically a type error)public Expression staticTypeCheck(SequenceType req, boolean backwardsCompatible, RoleLocator role, ExpressionVisitor visitor) throws XPathException
req
- the required typebackwardsCompatible
- true if backwards compatibility mode appliesrole
- the role of the expression in relation to the required typevisitor
- an expression visitor
XPathException
- if failures occur, for example if the static type of one branch of the conditional
is incompatible with the required typepublic Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException
This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.
visitor
- an expression visitorcontextItemType
- the static type of "." at the point where this expression is invoked.
The parameter is set to null if it is known statically that the context item will be undefined.
If the type of the context item is not known statically, the argument is set to
Type.ITEM_TYPE
XPathException
- if an error is discovered during this phase
(typically a type error)public Expression promote(PromotionOffer offer) throws XPathException
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
XPathException
- if any error is detectedpublic final int getSpecialProperties()
public int getCardinality()
public abstract ItemType getItemType(TypeHierarchy th)
This method should always return a result, though it may be the best approximation that is available at the time.
th
- the type hierarchy cache
public int getDependencies()
public Iterator iterateSubExpressions()
public boolean hasLoopingSubexpression(Expression child)
child
- the immediate subexpression
public Expression findParentOf(Expression leaf)
leaf
- the expression whose parent is required
public void setFlattened(boolean flattened)
flattened
- set to true if the result of the expression is atomized or otherwise turned into
an atomic valuepublic void setFiltered(boolean filtered)
filtered
- if true, marks this expression as the base of a filter expressionpublic Item evaluateItem(XPathContext context) throws XPathException
evaluateItem
in interface EvaluableItem
context
- The context in which the expression is to be evaluated
XPathException
- if any dynamic error occurs evaluating the
expressionpublic SequenceIterator iterate(XPathContext context) throws XPathException
iterate
in interface SequenceIterable
context
- supplies the context for evaluation
XPathException
- if any dynamic error occurs evaluating the
expressionpublic EventIterator iterateEvents(XPathContext context) throws XPathException
The events (of class PullEvent
) are either complete
items, or one of startElement, endElement, startDocument, or endDocument, known
as semi-nodes. The stream of events may also include a nested EventIterator.
If a start-end pair exists in the sequence, then the events between
this pair represent the content of the document or element. The content sequence will
have been processed to the extent that any attribute and namespace nodes in the
content sequence will have been merged into the startElement event. Namespace fixup
will have been performed: that is, unique prefixes will have been allocated to element
and attribute nodes, and all namespaces will be declared by means of a namespace node
in the startElement event or in an outer startElement forming part of the sequence.
However, duplicate namespaces may appear in the sequence.
The content of an element or document may include adjacent or zero-length text nodes, atomic values, and nodes represented as nodes rather than broken down into events.
context
- The dynamic evaluation context
XPathException
- if a dynamic error occurs during expression evaluationpublic boolean effectiveBooleanValue(XPathContext context) throws XPathException
context
- The context in which the expression is to be evaluated
XPathException
- if any dynamic error occurs evaluating the
expressionpublic CharSequence evaluateAsString(XPathContext context) throws XPathException
context
- The context in which the expression is to be evaluated
XPathException
- if any dynamic error occurs evaluating the
expression
ClassCastException
- if the result type of the
expression is not xs:string?public void process(XPathContext context) throws XPathException
context
- The dynamic context, giving access to the current node,
the current variables, etc.
XPathException
public String toString()
toString
in class Object
public void display(int level, PrintStream out, Configuration config)
level
- this argument is ignoredout
- the expression presenter used to display the structureconfig
- the Saxon configurationpublic abstract void explain(ExpressionPresenter out)
out
- the expression presenter used to display the structurepublic final void explain(OutputStream out)
out
- the expression presenter used to display the structurepublic void checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole) throws XPathException
parentType
- the "given complex type": the method is checking that the nodes returned by this
expression are acceptable members of the content model of this typeenv
- the static contextwhole
- if true, we want to check that the value of this expression satisfies the content model
as a whole; if false we want to check that the value of the expression is acceptable as one part
of the content
XPathException
- if the value delivered by this expression cannot be part of the content model
of the given typepublic void setContainer(Container container)
This affects the expression and all its subexpressions. Any subexpressions that are not in the same container are marked with the new container, and this proceeds recursively. However, any subexpression that is already in the correct container is not modified.
container
- The container of this expression.public Container getContainer()
public void adoptChildExpression(Expression child)
Note: many calls on this method are now redundant, but are kept in place for "belt-and-braces" reasons. The rule is that an implementation of simplify(), typeCheck(), or optimize() that returns a value other than "this" is required to set the location information and parent pointer in the new child expression. However, in the past this was often left to the caller, which did it by calling this method, either unconditionally on return from one of these methods, or after testing that the returned object was not the same as the original.
child
- the child expressionpublic void setLocationId(int id)
id
- the location idpublic final int getLocationId()
public int getLineNumber()
getLineNumber
in interface SourceLocator
public int getColumnNumber()
getColumnNumber
in interface SourceLocator
public String getSystemId()
getSystemId
in interface SourceLocator
public final String getPublicId()
getPublicId
in interface SourceLocator
public Executable getExecutable()
public LocationProvider getLocationProvider()
public final Expression doPromotion(Expression subexpression, PromotionOffer offer) throws XPathException
subexpression
- the subexpression that is a candidate for promotionoffer
- details of the promotion being considered
XPathException
public final void computeStaticProperties()
public int computeDependencies()
public int getIntrinsicDependencies()
public abstract Expression copy()
public boolean replaceSubExpression(Expression original, Expression replacement)
original
- the original subexpressionreplacement
- the replacement subexpression
public void suppressValidation(int validationMode)
validationMode
- the kind of validation being performed on the parent expressionpublic int markTailFunctionCalls(StructuredQName qName, int arity)
qName
- the name of the functionarity
- the arity (number of parameters) of the function
public int[] getSlotsUsed()
public InstructionInfo getInstructionInfo()
getInstructionInfo
in interface InstructionInfoProvider
public int getHostLanguage()
Configuration.XSLT
or Configuration.XQUERY
public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
The default implementation of this method assumes that an expression does no navigation other than the navigation done by evaluating its subexpressions, and that the subexpressions are evaluated in the same context as the containing expression. The method must be overridden for any expression where these assumptions do not hold. For example, implementations exist for AxisExpression, ParentExpression, and RootExpression (because they perform navigation), and for the doc(), document(), and collection() functions because they create a new navigation root. Implementations also exist for PathExpression and FilterExpression because they have subexpressions that are evaluated in a different context from the calling expression.
pathMap
- the PathMap to which the expression should be addedpathMapNodeSet
- the PathMapNodeSet to which the paths embodied in this expression should be added
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |