|
|||||||
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.
Two expressions are considered equal if they return the same result when evaluated in the same context.
Field Summary | |
---|---|
static int |
EVALUATE_METHOD
|
static int |
ITERATE_METHOD
|
protected int |
locationId
|
static int |
PROCESS_METHOD
|
protected int |
staticProperties
|
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 |
checkForUpdatingSubexpressions()
Check to ensure that this expression does not contain any inappropriate updating subexpressions. |
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. |
protected abstract int |
computeCardinality()
Compute the static cardinality of this expression |
int |
computeDependencies()
Compute the dependencies of an expression, as the union of the dependencies of its subexpressions. |
protected int |
computeSpecialProperties()
Compute the special properties of this expression. |
void |
computeStaticProperties()
Compute the static properties. |
abstract Expression |
copy()
Copy an expression. |
Expression |
doPromotion(Expression parentExpression,
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 |
protected void |
dynamicError(String message,
String code,
XPathContext context)
Method used in subclasses to signal a dynamic error |
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. |
void |
evaluatePendingUpdates(XPathContext context,
PendingUpdateList pul)
Evaluate an updating expression, adding the results to a Pending Update List. |
abstract void |
explain(ExpressionPresenter out)
Diagnostic print of expression structure. |
void |
explain(OutputStream out)
Diagnostic print of expression structure. |
int |
getCardinality()
Determine the static cardinality of the expression. |
int |
getColumnNumber()
Get the column number of the expression |
int |
getColumnNumber(long locationId)
Get the column number within the document, entity, or module containing a particular location |
int |
getConstructType()
Get the type of this expression for use in tracing and diagnostics |
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(). |
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 |
getLineNumber(long locationId)
Get the line number within the document or module containing a particular location |
int |
getLocationId()
Get the location ID of the expression |
LocationProvider |
getLocationProvider()
Get the LocationProvider allowing location identifiers to be resolved. |
StructuredQName |
getObjectName()
Get a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc. |
Iterator |
getProperties()
Get an iterator over all the properties available. |
Object |
getProperty(String name)
Get the value of a particular property of the instruction. |
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 |
String |
getSystemId(long locationId)
Get the URI of the document or module containing a particular location |
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 |
boolean |
isSubtreeExpression()
Determine whether the expression can be evaluated without reference to the part of the context document outside the subtree rooted at the context node. |
boolean |
isUpdatingExpression()
Determine whether this is an updating expression as defined in the XQuery update specification |
boolean |
isVacuousExpression()
Determine whether this is a vacuous expression as defined in the XQuery update specification |
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<Expression> |
iterateSameFocusSubExpressions()
Get the immediate sub-expressions of this expression that are evaluated with the same focus (context item, position, and size) as the parent expression. |
Iterator<Expression> |
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,
Expression parent)
Offer promotion for this subexpression. |
boolean |
replaceSubExpression(Expression original,
Expression replacement)
Replace one subexpression by a replacement subexpression |
protected void |
resetLocalStaticProperties()
Reset the static properties of the expression to -1, so that they have to be recomputed next time they are used. |
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. |
protected void |
typeError(String message,
String errorCode,
XPathContext context)
Method used in subclasses to signal a runtime type error |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, 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
protected int staticProperties
protected int locationId
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 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, Expression parent) throws XPathException
This method must be overridden for any Expression that has subexpressions.
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 expressionparent
-
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<Expression> iterateSubExpressions()
public Iterator<Expression> iterateSameFocusSubExpressions()
public boolean hasLoopingSubexpression(Expression child)
child
- the immediate subexpression
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 void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul) throws XPathException
context
- the XPath dynamic evaluation contextpul
- the pending update list to which the results should be written
XPathException
public String toString()
toString
in class Object
public 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
getLineNumber
in interface InstructionInfo
getLineNumber
in interface Locator
public int getColumnNumber()
getColumnNumber
in interface SourceLocator
getColumnNumber
in interface Locator
public String getSystemId()
getSystemId
in interface SourceLocator
getSystemId
in interface InstructionInfo
getSystemId
in interface Locator
public final String getPublicId()
getPublicId
in interface SourceLocator
getPublicId
in interface Locator
public Executable getExecutable()
public LocationProvider getLocationProvider()
public final Expression doPromotion(Expression parentExpression, Expression subexpression, PromotionOffer offer) throws XPathException
parentExpression
- subexpression
- the subexpression that is a candidate for promotionoffer
- details of the promotion being considered @return the result of the promotion. This will be the current expression if no promotion
actions have taken place
XPathException
public final void computeStaticProperties()
protected void resetLocalStaticProperties()
protected abstract int computeCardinality()
StaticProperty.ALLOWS_ZERO_OR_ONE
,
StaticProperty.EXACTLY_ONE
, StaticProperty.ALLOWS_ONE_OR_MORE
,
StaticProperty.ALLOWS_ZERO_OR_MORE
protected int computeSpecialProperties()
StaticProperty
. The "special" properties are properties
other than cardinality and dependencies, and most of them relate to properties of node sequences, for
example whether the nodes are in document order.
public int computeDependencies()
public int getIntrinsicDependencies()
public void checkForUpdatingSubexpressions() throws XPathException
XPathException
- if the expression has a non-permitted updating subexpressionpublic boolean isUpdatingExpression()
public boolean isVacuousExpression()
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 final int[] getSlotsUsed()
protected void dynamicError(String message, String code, XPathContext context) throws XPathException
message
- the error messagecode
- the error codecontext
- the XPath dynamic context
XPathException
protected void typeError(String message, String errorCode, XPathContext context) throws XPathException
message
- the error messageerrorCode
- the error codecontext
- the XPath dynamic context
XPathException
public int getConstructType()
getConstructType
in interface InstructionInfo
Location
public StructuredQName getObjectName()
InstructionInfo
getObjectName
in interface InstructionInfo
public Object getProperty(String name)
InstructionInfo
getProperty
in interface InstructionInfo
name
- The name of the required property
public int getLineNumber(long locationId)
getLineNumber
in interface LocationProvider
locationId
- identifier of the location in question (as passed down the Receiver pipeline)
public int getColumnNumber(long locationId)
LocationProvider
getColumnNumber
in interface LocationProvider
locationId
- identifier of the location in question (as passed down the Receiver pipeline)
public String getSystemId(long locationId)
getSystemId
in interface LocationProvider
locationId
- identifier of the location in question (as passed down the Receiver pipeline)
public Iterator getProperties()
getProperties
in interface InstructionInfo
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
public boolean isSubtreeExpression()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |