- All Implemented Interfaces:
- Direct Known Subclasses:
public abstract class ItemFeed extends ProxyOutputterAn ItemFeed evaluates an expression in "composed push" mode. Its streaming input is supplied via a sequence of event calls (start element, end element, etc) that represent the value of the streamed operand of the expression; other operands are evaluated in pull mode in the usual way.
Expressions are thus evaluated "bottom up": instead of a parent expression triggering the evaluation of its children, the appearance of data needed by a child expression causes evaluation of the child expression, which then triggers evaluation of its parent, and so on.
One consequence of this is that special mechanisms are needed for error handling. In particular, it's not possible for a child expression to notify its parent expression of dynamic errors simply by throwing a Java exception: the error information needs to be passed up the pipeline in the same way as regular results.
Some expressions (inspection expressions) are only interested in top-level events: for example
instance ofonly need to know about a
startElementevent, they are not interested in the content of the element, only in its existence. Other expressions (absorption expression) need access to the content of the element: in most cases, the typed value of the element, but in some cases (such as
snapshot()a finer-grained representation of the content. In such cases the
startSelectedParentNode(FleetingParentNode, Location)method (which is notified of a top-level event in the input stream) returns a
Receiver, which is then notified of all the contained events up to the corresponding
Some expressions (transmission expression) pass data on to their parent expressions directly, and in these cases the decision whether to ask for full details of the content is delegated to the parent expression, or beyond.
An expression whose result is known before all the input is available (for example,
exists()can call a supplied
Terminatorto indicate that no more input is required. In some cases (where the expression would otherwise read an entire document) this enables parsing of the streamed input file to be abandoned.
The events passed up the pipeline will usually correspond to nodes in the streamed source document, or to atomic values computed from those nodes. In unusual edge cases, however, a consuming expression may generate new element or document nodes, which are still delivered incrementally because their content is established by streaming the source document. Events representing these constructed elements are passed up the pipeline as if they came from the source document. (Note, because this situation is unusual and somewhat contrived, it probably has incomplete test coverage and may not be fully implemented for all kinds of expression).
The start of an element may be represented either as a single event containing all the attributes and namespaces, or as a sequence of separate events (start element, attributes, namespaces, then
startContent). Events coming directly from parsing the streamed input will use the more efficient "bundled" form, but events representing constructed nodes may be "unbundled" because attributes and namespaces can be constructed incrementally as the streamed input is processed. An
ItemFeedfor a parent expression should therefore be prepared to accept either form.
Constructors Constructor Description
ItemFeed(ItemFeed result, XPathContext context)
ItemFeed(Outputter result, XPathContext context, boolean thisIsAnExceptionalCase)Special constructor for the last ItemFeed in the pipeline, which feeds into an Outputter rather than into another ItemFeed.
ItemFeed(Expression exp, ItemFeed result, XPathContext context)
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description
append(Item item)Supply one item towards the streamed input of the expression
append(Item item, Location locationId, int properties)Supply one item towards the streamed input of the expression.
close()Finish evaluating the expression.
dynamicError(XPathException error)Report a dynamic error.
endSelectedParentNode(Location locationId)Signal that the endElement event has occurred for the element whose startElement event caused the Watch to be activated.
getContext()Get the dynamic evaluation context
getExpression()Get the expression being evaluated by this ItemFeed.
getResultFeed()Get the result, that is, the ItemFeed to which the items in the result of the expression should be supplied
getTerminator()Get the Terminator which can be used to request early termination of the Feed
open(Terminator terminator)Start evaluating the expression.
processItems(SequenceIterator iter, Outputter result)Convenience method to process all the items selected by an iterator and push them to the next feed in the push pipeline
setExpression(Expression exp)Set the expression being evaluated by this ItemFeed
setHasFailed()Mark this feed as having failed (that is, as having detected and reported a dynamic error).
setTerminator(Terminator terminator)Provide a callback that can be used to request early termination of the streaming of this input document
startSelectedParentNode(FleetingParentNode node, Location locationId)Signal that an element or document node has been found that matches the selection that this Watch is looking for.
Methods inherited from class net.sf.saxon.event.ProxyOutputter
attribute, characters, comment, endDocument, endElement, getNextOutputter, namespace, open, processingInstruction, setUnparsedEntity, startContent, startDocument, startElement, startElement, usesTypeAnnotations
Methods inherited from class net.sf.saxon.event.Outputter
getConfiguration, getPipelineConfiguration, getStringReceiver, getSystemId, namespaces, setPipelineConfiguration, setSystemId
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public ItemFeed(Outputter result, XPathContext context, boolean thisIsAnExceptionalCase)Special constructor for the last ItemFeed in the pipeline, which feeds into an Outputter rather than into another ItemFeed. Note that the getResult() method in this situation will throw an exception.
result- the resulting outputter
context- the dynamic evaluation context
thisIsAnExceptionalCase- value is ignored; the parameter is there simply to flag this constructor as a special case
public static void processItems(SequenceIterator iter, Outputter result) throws XPathExceptionConvenience method to process all the items selected by an iterator and push them to the next feed in the push pipeline
iter- iterator over the selected items
result- the next feed in the pipeline
XPathException- if any dynamic error occurs
public void setExpression(Expression exp)Set the expression being evaluated by this ItemFeed
exp- the relevant expression
public Expression getExpression()Get the expression being evaluated by this ItemFeed. May be null if not known or not relevant
- the expression being evaluated
public void setTerminator(Terminator terminator)Provide a callback that can be used to request early termination of the streaming of this input document
terminator- the class that can be called to request termination
public void setHasFailed()Mark this feed as having failed (that is, as having detected and reported a dynamic error). Once the feed is marked as having failed, it should not attempt to process any further input.
public Terminator getTerminator()Get the Terminator which can be used to request early termination of the Feed
- the Terminator that was passed to the open() call, or null if open() has not been called
public ItemFeed getResultFeed()Get the result, that is, the ItemFeed to which the items in the result of the expression should be supplied
- the Outputter that consumes the results of this expression
public XPathContext getContext()Get the dynamic evaluation context
- the dynamic evaluation context
public void open(Terminator terminator) throws XPathExceptionStart evaluating the expression. The default implementation does nothing.
terminator- used to achieve early exit
XPathException- if a dynamic error occurs
public Receiver startSelectedParentNode(FleetingParentNode node, Location locationId) throws XPathExceptionSignal that an element or document node has been found that matches the selection that this Watch is looking for. This method is called by the WatchManager while processing the startElement or startDocument event that matches the selection.
node- the element or document node whose start event has been matched
locationId- the location associated with the element or document node (may be the location of the instruction that created it)
- a Receiver to be notified of all events starting with the startElement/startDocument event for the matched element, and ending with the endElement event for that element; or null if this feature is not required.
XPathException- May be raised if a dynamic error occurs
public abstract void append(Item item) throws XPathExceptionSupply one item towards the streamed input of the expression
public final void append(Item item, Location locationId, int properties) throws XPathExceptionSupply one item towards the streamed input of the expression. This implementation calls
append(Item). Subclasses do not have to cater for this event
- Specified by:
item- the item to be supplied
locationId- the location of the calling instruction, for diagnostics
properties- if the item is an element node, this indicates whether its namespaces need to be copied. Values are
ReceiverOption.ALL_NAMESPACES; the default (0) means
XPathException- if an error occurs
public void endSelectedParentNode(Location locationId) throws XPathExceptionSignal that the endElement event has occurred for the element whose startElement event caused the Watch to be activated.
locationId- the location of the element
XPathException- May be raised if a constraint implemented by this Watch is violated
public void close() throws XPathExceptionFinish evaluating the expression.
public void dynamicError(XPathException error) throws XPathExceptionReport a dynamic error. This requires searching up the "feed" pipeline to see if there is a try/catch expression interested in being notified of this error; if there is none, the error is thrown as an exception
error- the exception representing the dynamic error
XPathException- if there is no try/catch expression wanting to catch this error
public boolean hasFailed()