Class SortExpression
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.sort.SortExpression
-
- All Implemented Interfaces:
ExportAgent
,Locatable
,SortKeyEvaluator
,IdentityComparable
,Traceable
public class SortExpression extends Expression implements SortKeyEvaluator
Expression equivalent to the imaginary syntax expr sortby (sort-key)+
-
-
Field Summary
-
Fields inherited from class net.sf.saxon.expr.Expression
EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD
-
-
Constructor Summary
Constructors Constructor Description SortExpression(Expression select, SortKeyDefinitionList sortKeys)
Create a sort expression
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PathMap.PathMapNodeSet
addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap.int
computeCardinality()
Determine the static cardinalityint
computeSpecialProperties()
Get the static properties of this expression (other than its type).Expression
copy(RebindingMap rebindings)
Copy an expression.AtomicValue
evaluateSortKey(int n, XPathContext c)
Callback for evaluating the sort keysvoid
export(ExpressionPresenter out)
Diagnostic print of expression structure.Expression
getBaseExpression()
Get the expression defining the sequence being sortedOperand
getBaseOperand()
Get the operand representing the expresion being sortedAtomicComparer[]
getComparators()
Get the comparators, if known statically.java.lang.String
getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.int
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().ItemType
getItemType()
Determine the data type of the items returned by the expression, if possibleExpression
getSelect()
SortKeyDefinition
getSortKeyDefinition(int i)
SortKeyDefinitionList
getSortKeyDefinitionList()
java.lang.String
getStreamerName()
Get the (partial) name of a class that supports streaming of this kind of expressionboolean
isSortKey(Expression child)
Test whether a given expression is one of the sort keysSequenceIterator
iterate(XPathContext context)
Enumerate the results of the expressionjava.lang.Iterable<Operand>
operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.Expression
optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)
Perform optimisation of an expression and its subexpressions.void
setSelect(Expression select)
void
setSortKeyDefinitionList(SortKeyDefinitionList skd)
java.lang.String
toShortString()
Produce a short string identifying the expression for use in error messagesExpression
typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)
Type-check the expression-
Methods inherited from class net.sf.saxon.expr.Expression
adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeHashCode, computeStaticProperties, dynamicError, effectiveBooleanValue, equals, evaluateAsString, evaluateItem, evaluatePendingUpdates, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getInterpretedExpression, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, process, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, toString, typeCheckChildren, typeError, unordered, verifyParentPointers
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.trace.Traceable
gatherProperties
-
-
-
-
Constructor Detail
-
SortExpression
public SortExpression(Expression select, SortKeyDefinitionList sortKeys)
Create a sort expression- Parameters:
select
- the expression whose result is to be sortedsortKeys
- the set of sort key definitions to be used, in major to minor order
-
-
Method Detail
-
getExpressionName
public java.lang.String getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.- Overrides:
getExpressionName
in classExpression
- Returns:
- a name identifying the kind of expression, in terms meaningful to a user. The name will always be in the form of a lexical XML QName, and should match the name used in explain() output displaying the expression.
-
getBaseOperand
public Operand getBaseOperand()
Get the operand representing the expresion being sorted
-
getBaseExpression
public Expression getBaseExpression()
Get the expression defining the sequence being sorted- Returns:
- the expression whose result is to be sorted
-
getComparators
public AtomicComparer[] getComparators()
Get the comparators, if known statically. Otherwise, return null.- Returns:
- The comparators, if they have been allocated; otherwise null
-
operands
public java.lang.Iterable<Operand> operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression. Default implementation returns a zero-length array, appropriate for an expression that has no sub-expressions.- Overrides:
operands
in classExpression
- Returns:
- an iterator containing the sub-expressions of this expression
-
addToPathMap
public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap. The PathMap captures a map of the nodes visited by an expression in a source tree.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.
- Overrides:
addToPathMap
in classExpression
- Parameters:
pathMap
- the PathMap to which the expression should be addedpathMapNodeSet
- the PathMapNodeSet to which the paths embodied in this expression should be added- Returns:
- the pathMapNode representing the focus established by this expression, in the case where this expression is the first operand of a path expression or filter expression. For an expression that does navigation, it represents the end of the arc in the path map that describes the navigation route. For other expressions, it is the same as the input pathMapNode.
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
Type-check the expression- Overrides:
typeCheck
in classExpression
- Parameters:
visitor
- an expression visitorcontextInfo
- Information available statically about the context item: whether it is (possibly) absent; its static type; its streaming posture.- Returns:
- the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
optimize
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException
Perform optimisation of an expression and its subexpressions.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.
- Overrides:
optimize
in classExpression
- Parameters:
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 toType.ITEM_TYPE
- Returns:
- the original expression, rewritten if appropriate to optimize execution
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
copy
public Expression copy(RebindingMap rebindings)
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Parameters:
rebindings
- variables that need to be re-bound- Returns:
- the copy of the original expression
-
isSortKey
public boolean isSortKey(Expression child)
Test whether a given expression is one of the sort keys- Parameters:
child
- the given expression- Returns:
- true if the given expression is one of the sort keys
-
computeCardinality
public int computeCardinality()
Determine the static cardinality- Specified by:
computeCardinality
in classExpression
- Returns:
- the computed cardinality, as one of the values
StaticProperty.ALLOWS_ZERO_OR_ONE
,StaticProperty.EXACTLY_ONE
,StaticProperty.ALLOWS_ONE_OR_MORE
,StaticProperty.ALLOWS_ZERO_OR_MORE
. May also returnStaticProperty.ALLOWS_ZERO
if the result is known to be an empty sequence, orStaticProperty.ALLOWS_MANY
if if is known to return a sequence of length two or more.
-
getItemType
public ItemType getItemType()
Determine the data type of the items returned by the expression, if possible- Specified by:
getItemType
in classExpression
- Returns:
- a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known in advance)
-
computeSpecialProperties
public int computeSpecialProperties()
Get the static properties of this expression (other than its type). The result is bit-significant. 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.- Overrides:
computeSpecialProperties
in classExpression
- Returns:
- the special properties, as a bit-significant integer
-
getImplementationMethod
public int getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is provided directly. The other methods will always be available indirectly, using an implementation that relies on one of the other methods.- Specified by:
getImplementationMethod
in classExpression
- Returns:
- the implementation method, for example
Expression.ITERATE_METHOD
orExpression.EVALUATE_METHOD
orExpression.PROCESS_METHOD
-
iterate
public SequenceIterator iterate(XPathContext context) throws XPathException
Enumerate the results of the expression- Overrides:
iterate
in classExpression
- 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
-
evaluateSortKey
public AtomicValue evaluateSortKey(int n, XPathContext c) throws XPathException
Callback for evaluating the sort keys- Specified by:
evaluateSortKey
in interfaceSortKeyEvaluator
- Throws:
XPathException
-
toShortString
public java.lang.String toShortString()
Description copied from class:Expression
Produce a short string identifying the expression for use in error messages- Overrides:
toShortString
in classExpression
- Returns:
- a short string, sufficient to identify the expression
-
getStreamerName
public java.lang.String getStreamerName()
Get the (partial) name of a class that supports streaming of this kind of expression- Overrides:
getStreamerName
in classExpression
- Returns:
- the partial name of a class that can be instantiated to provide streaming support in Saxon-EE, or null if there is no such class
-
export
public void export(ExpressionPresenter out) throws XPathException
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
export
in interfaceExportAgent
- Specified by:
export
in classExpression
- Parameters:
out
- the expression presenter used to display the structure- Throws:
XPathException
- if the export fails, for example if an expression is found that won't work in the target environment.
-
getSelect
public Expression getSelect()
-
setSelect
public void setSelect(Expression select)
-
getSortKeyDefinitionList
public SortKeyDefinitionList getSortKeyDefinitionList()
-
getSortKeyDefinition
public SortKeyDefinition getSortKeyDefinition(int i)
-
setSortKeyDefinitionList
public void setSortKeyDefinitionList(SortKeyDefinitionList skd)
-
-