net.sf.saxon.sort

Class SortKeyDefinition

public class SortKeyDefinition extends Object implements Serializable

A SortKeyDefinition defines one component of a sort key.
Note that most attributes defining the sort key can be attribute value templates, and can therefore vary from one invocation to another. We hold them as expressions. As soon as they are all known (which in general is only at run-time), the SortKeyDefinition is replaced by a FixedSortKeyDefinition in which all these values are fixed.
Field Summary
protected booleanbackwardsCompatible
protected StringbaseURI
protected ExpressioncaseOrder
protected StringCollatorcollation
protected ExpressioncollationName
protected ExpressiondataTypeExpression
protected booleanemptyLeast
protected Expressionlanguage
protected Expressionorder
protected ExpressionsortKey
protected Expressionstable
Method Summary
StringgetBaseURI()
Get the static base URI of the expression.
ExpressiongetCaseOrder()
Get the expression that defines the case order of the sort keys.
StringCollatorgetCollation()
Get the collation to be used
ExpressiongetCollationNameExpression()
Get the selected collation name (specifically, an expression which when evaluated returns the collation URI).
ExpressiongetDataTypeExpression()
Get the expression that defines the data type of the sort keys
booleangetEmptyLeast()
Ask whether empty sequence comes before other values or after them
AtomicComparergetFinalComparator()
Get the comparator which is used to compare two values according to this sort key.
ExpressiongetLanguage()
Get the expression that defines the language of the sort keys
ExpressiongetOrder()
Get the expression that defines the order as ascending or descending
ExpressiongetSortKey()
Get the expression used as the sort key
ExpressiongetStable()
Ask whether this sort key definition is stable
booleanisBackwardsCompatible()
Ask whether this sort key is evaluated in XSLT 1.0 backwards compatibility mode
booleanisFixed()
Ask whether the sort key definition is fixed, that is, whether all the information needed to create a Comparator is known statically
AtomicComparermakeComparator(XPathContext context)
Allocate an AtomicComparer to perform the comparisons described by this sort key component.
voidsetBackwardsCompatible(boolean compatible)
Set whether this sort key is evaluated in XSLT 1.0 backwards compatibility mode
voidsetBaseURI(String baseURI)
Set the base URI of the expression.
voidsetCaseOrder(Expression exp)
Set the case order.
voidsetCollation(StringCollator collation)
Set the collation to be used
voidsetCollationNameExpression(Expression collationName)
Set the collation name (specifically, an expression which when evaluated returns the collation URI).
voidsetDataTypeExpression(Expression exp)
Set the data type.
voidsetEmptyLeast(boolean emptyLeast)
Set whether empty sequence comes before other values or after them
voidsetFinalComparator(AtomicComparer comp)
Set the comparator which is used to compare two values according to this sort key.
voidsetLanguage(Expression exp)
Set the language.
voidsetOrder(Expression exp)
Set the order.
voidsetSortKey(Expression exp)
Set the expression used as the sort key
voidsetStable(Expression stable)
Set whether this sort key definition is stable
SortKeyDefinitionsimplify(ExpressionVisitor visitor)
Simplify this sort key definition
voidtypeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Type-check this sort key definition (all properties other than the sort key select expression, which has a different dynamic context

Field Detail

backwardsCompatible

protected boolean backwardsCompatible

baseURI

protected String baseURI

caseOrder

protected Expression caseOrder

collation

protected StringCollator collation

collationName

protected Expression collationName

dataTypeExpression

protected Expression dataTypeExpression

emptyLeast

protected boolean emptyLeast

language

protected Expression language

order

protected Expression order

sortKey

protected Expression sortKey

stable

protected Expression stable

Method Detail

getBaseURI

public String getBaseURI()
Get the static base URI of the expression. This is needed to handle the case where a collation URI evaluated at run-time turns out to be a relative URI.

Returns: the static base URI of the expression

getCaseOrder

public Expression getCaseOrder()
Get the expression that defines the case order of the sort keys.

Returns: the expression that defines the case order, whose run-time value will be "upper-first", "lower-first", or "#default".

getCollation

public StringCollator getCollation()
Get the collation to be used

Returns: A StringCollator, which encapsulates both the collation URI and the collating function

getCollationNameExpression

public Expression getCollationNameExpression()
Get the selected collation name (specifically, an expression which when evaluated returns the collation URI).

Returns: the expression that determines the collation name

getDataTypeExpression

public Expression getDataTypeExpression()
Get the expression that defines the data type of the sort keys

Returns: the expression that defines the data type, as used in XSLT 1.0

getEmptyLeast

public boolean getEmptyLeast()
Ask whether empty sequence comes before other values or after them

Returns: true if () is considered lower than any other value

getFinalComparator

public AtomicComparer getFinalComparator()
Get the comparator which is used to compare two values according to this sort key. This method may be called either at compile time or at run-time. If no comparator has been allocated, it returns null. It is then necessary to allocate a comparator using the SortKeyDefinition method.

Returns: the Atomic Comparer to be used

getLanguage

public Expression getLanguage()
Get the expression that defines the language of the sort keys

Returns: exp the expression that determines the language

getOrder

public Expression getOrder()
Get the expression that defines the order as ascending or descending

Returns: the expression that determines the order (always a literal in XQuery, but can be defined by an AVT in XSLT)

getSortKey

public Expression getSortKey()
Get the expression used as the sort key

Returns: the sort key select expression

getStable

public Expression getStable()
Ask whether this sort key definition is stable

Returns: the expression that determines whether the sort key definition is stable (it evaluates to the string "yes" or "no".

isBackwardsCompatible

public boolean isBackwardsCompatible()
Ask whether this sort key is evaluated in XSLT 1.0 backwards compatibility mode

Returns: true if backwards compatibility mode was selected

isFixed

public boolean isFixed()
Ask whether the sort key definition is fixed, that is, whether all the information needed to create a Comparator is known statically

Returns: true if all information needed to create a Comparator is known statically

makeComparator

public AtomicComparer makeComparator(XPathContext context)
Allocate an AtomicComparer to perform the comparisons described by this sort key component. This method is called at run-time. The AtomicComparer takes into account not only the collation, but also parameters such as order=descending and handling of empty sequence and NaN (the result of the compare() method of the comparator is +1 if the second item is to sort after the first item)

Parameters: context the dynamic evaluation context

Returns: an AtomicComparer suitable for making the sort comparisons

setBackwardsCompatible

public void setBackwardsCompatible(boolean compatible)
Set whether this sort key is evaluated in XSLT 1.0 backwards compatibility mode

Parameters: compatible true if backwards compatibility mode is selected

setBaseURI

public void setBaseURI(String baseURI)
Set the base URI of the expression. This is needed to handle the case where a collation URI evaluated at run-time turns out to be a relative URI.

Parameters: baseURI the static base URI of the expression

setCaseOrder

public void setCaseOrder(Expression exp)
Set the case order. This is supplied as an expression which must evaluate to "upper-first" or "lower-first" or "#default". If the order is fixed, supply e.g. new StringValue("lower-first"). Default is "#default".

Parameters: exp the expression that defines the case order

setCollation

public void setCollation(StringCollator collation)
Set the collation to be used

Parameters: collation A StringCollator, which encapsulates both the collation URI and the collating function

setCollationNameExpression

public void setCollationNameExpression(Expression collationName)
Set the collation name (specifically, an expression which when evaluated returns the collation URI).

Parameters: collationName the expression that determines the collation name

setDataTypeExpression

public void setDataTypeExpression(Expression exp)
Set the data type. This is supplied as an expression which must evaluate to "text", "number", or a QName. If the data type is fixed, the valus should be supplied using setDataType() and not via this method.

Parameters: exp the expression that defines the data type, as used in XSLT 1.0

setEmptyLeast

public void setEmptyLeast(boolean emptyLeast)
Set whether empty sequence comes before other values or after them

Parameters: emptyLeast true if () is considered lower than any other value

setFinalComparator

public void setFinalComparator(AtomicComparer comp)
Set the comparator which is used to compare two values according to this sort key. The comparator makes the final decision whether one value sorts before or after another: this takes into account the data type, the collation, whether empty comes first or last, whether the sort order is ascending or descending.

This method is called at compile time if all these factors are known at compile time. It must not be called at run-time, except to reconstitute a finalComparator that has been lost by virtue of serialization .

Parameters: comp the Atomic Comparer to be used

setLanguage

public void setLanguage(Expression exp)
Set the language. This is supplied as an expression which evaluates to the language name. If the order is fixed, supply e.g. new StringValue("de").

Parameters: exp the expression that determines the language

setOrder

public void setOrder(Expression exp)
Set the order. This is supplied as an expression which must evaluate to "ascending" or "descending". If the order is fixed, supply e.g. new StringValue("ascending"). Default is "ascending".

Parameters: exp the expression that determines the order (always a literal in XQuery, but can be defined by an AVT in XSLT)

setSortKey

public void setSortKey(Expression exp)
Set the expression used as the sort key

Parameters: exp the sort key select expression

setStable

public void setStable(Expression stable)
Set whether this sort key definition is stable

Parameters: stable the expression that determines whether the sort key definition is stable (it evaluates to the string "yes" or "no".

simplify

public SortKeyDefinition simplify(ExpressionVisitor visitor)
Simplify this sort key definition

Parameters: visitor the expression visitor

Returns: the simplified sort key definition

Throws: XPathException if any failure occurs

typeCheck

public void typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Type-check this sort key definition (all properties other than the sort key select expression, which has a different dynamic context

Parameters: visitor the expression visitor contextItemType the type of the context item

Throws: XPathException if any failure occurs