com.saxonica.deploy
Class CompiledClosure

java.lang.Object
  extended by net.sf.saxon.value.Value
      extended by com.saxonica.deploy.CompiledClosure
All Implemented Interfaces:
Serializable, SequenceIterable, ValueRepresentation
Direct Known Subclasses:
CompiledMemoClosure

public class CompiledClosure
extends Value

A Closure represents a value that has not yet been evaluated: the value is represented by an expression, together with saved values of all the context variables that the expression depends on.

This Closure is designed for use when the value is only read once. If the value is read more than once, a new iterator over the underlying expression is obtained each time: this may (for example in the case of a filter expression) involve significant re-calculation.

The CompiledClosure class is similar to Closure, but is used only at run-time by queries that have been compiled into Java. It relies on the fact that Java provides a limited facility supporting closures: an anonymous inner class is allowed to reference local variables declared as "final", and these are automatically saved with the class instance so they are still available when the original stackframe disappears or changes. The code generator takes care to ensure that all variables that can be referenced from the inner class (specifically, those representing XPath variables as well as the context item) are held in variables that are declared final.

See Also:
Serialized Form

Field Summary
protected  int cardinality
           
protected  SequenceIterator inputIterator
           
protected  int primitiveType
           
 
Fields inherited from class net.sf.saxon.value.Value
INDETERMINATE_ORDERING
 
Fields inherited from interface net.sf.saxon.om.ValueRepresentation
EMPTY_VALUE_ARRAY
 
Constructor Summary
protected CompiledClosure()
           
  CompiledClosure(SequenceIterator inputIterator, int primitiveType, int cardinality)
          Create a compiled closure
 
Method Summary
 int getCardinality()
          Get the cardinality.
 ItemType getItemType(TypeHierarchy th)
          Get the static item type
 int getLength()
          Get the length of the value.
 Comparable getSchemaComparable()
          Get a Comparable value that implements the XML Schema ordering comparison semantics for this value.
 SequenceIterator iterate()
          Evaluate the expression in a given context to return an iterator over a sequence
 Value reduce()
          Reduce a value to its simplest form.
 
Methods inherited from class net.sf.saxon.value.Value
asItem, asItem, asIterator, asValue, checkPermittedContents, convertToJava, effectiveBooleanValue, equals, fromItem, getCanonicalLexicalRepresentation, getIterator, getStringValue, getStringValueCS, isIdentical, itemAt, iterate, process, stringToNumber
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputIterator

protected SequenceIterator inputIterator

primitiveType

protected int primitiveType

cardinality

protected int cardinality
Constructor Detail

CompiledClosure

protected CompiledClosure()

CompiledClosure

public CompiledClosure(SequenceIterator inputIterator,
                       int primitiveType,
                       int cardinality)
Create a compiled closure

Parameters:
inputIterator - iterator over the values delivered by the expression
primitiveType - lowest-common primitive type of the items delivered by the iterator
cardinality - cardinality of the expression
Method Detail

getItemType

public ItemType getItemType(TypeHierarchy th)
Get the static item type

Overrides:
getItemType in class Value
Parameters:
th - the type hierarchy cache
Returns:
for the default implementation: AnyItemType (not known)

getCardinality

public int getCardinality()
Get the cardinality. This method is intended to be implemented in a subclass, but if it is not implemented, the fallback implementation simply returns StaticProperty.ALLOWS_ZERO_OR_MORE

Overrides:
getCardinality in class Value
Returns:
the cardinality

iterate

public SequenceIterator iterate()
                         throws XPathException
Evaluate the expression in a given context to return an iterator over a sequence

Specified by:
iterate in class Value
Returns:
an iterator over the sequence of items
Throws:
XPathException - if a dynamic error occurs. This is possible only in the case of values that are materialized lazily, that is, where the iterate() method leads to computation of an expression that delivers the values.

reduce

public Value reduce()
             throws XPathException
Reduce a value to its simplest form. If the value is a closure or some other form of deferred value such as a FunctionCallPackage, then it is reduced to a SequenceExtent. If it is a SequenceExtent containing a single item, then it is reduced to that item. One consequence that is exploited by class FilterExpression is that if the value is a singleton numeric value, then the result will be an instance of NumericValue

Overrides:
reduce in class Value
Returns:
the value in simplified form
Throws:
XPathException

getLength

public int getLength()
              throws XPathException
Get the length of the value. Note: this consumes the iterator!

Overrides:
getLength in class Value
Returns:
the number of items in the sequence
Throws:
XPathException

getSchemaComparable

public Comparable getSchemaComparable()
Get a Comparable value that implements the XML Schema ordering comparison semantics for this value. The default implementation returns "this", which ensures that comparisons between list values are handled by the equals() and compareTo() methods on this class itself. This is overridden for atomic values.

In the case of data types that are partially ordered, the returned Comparable extends the standard semantics of the compareTo() method by returning the value Value.INDETERMINATE_ORDERING when there is no defined order relationship between two given values.

Overrides:
getSchemaComparable in class Value
Returns:
a Comparable that follows XML Schema comparison rules


Copyright (c) Saxonica Limited. All rights reserved.