Package com.saxonica.ee.stream.watch
Class AccumulatorWatch
- java.lang.Object
-
- com.saxonica.ee.stream.watch.AbstractWatch
-
- com.saxonica.ee.stream.watch.PatternWatch
-
- com.saxonica.ee.stream.watch.AccumulatorWatch
-
- All Implemented Interfaces:
Watch
public class AccumulatorWatch extends PatternWatch
This watch implements a single accumulator in streaming mode. Unlike other watches, it is called to process every node in the stream; it then checks whether the accumulator has any rule that matches this node, and if so applies the next-value expression associated with that accumulator rule.The class also provides methods to return the "before" and "after" values of the accumulator for a given node. These have to make provision (a) for handling error situations (where evaluation of the accumulator failed), and (b) for handling the case where the value is requested (by another accumulator) before it is available.
-
-
Constructor Summary
Constructors Constructor Description AccumulatorWatch(Accumulator accumulator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
The close() method is called immediately before the Watch is destroyed, that is, when the element whose declaration scopes the constraint implemented by this Watch goes out of scope.void
endSelectedParentNode(Location locationId)
Signal that the endElement event has occurred for the element whose startElement event caused the Watch to be activated.Accumulator
getAccumulator()
XPathContext
getContext()
Sequence
getPostDescentValue(FleetingNode node)
Sequence
getPreDescentValue(FleetingNode node)
Sequence
getPreDescentValueAtDepth(int depth)
boolean
isBeingComputed(AccumulatorFn.Phase phase)
void
open(Terminator terminator)
Open the watch.void
processItem(Item item)
Signal that a node (other than an element) that matches the selection has been found.void
setNodeStack(java.util.Stack<FleetingNode> stack)
void
setWatchManager(WatchManager watchManager)
Receiver
startSelectedParentNode(FleetingParentNode node, Location locationId)
Signal that an element has been found that matches the selection that this Watch is looking for.-
Methods inherited from class com.saxonica.ee.stream.watch.PatternWatch
getAnchorNode, getSelection, matchesNode, matchesNodesOfKind, setAnchorNode, setSelection
-
Methods inherited from class com.saxonica.ee.stream.watch.AbstractWatch
getNamespaceResolver, getPipelineConfiguration, setNamespaceResolver, setPipelineConfiguration
-
-
-
-
Constructor Detail
-
AccumulatorWatch
public AccumulatorWatch(Accumulator accumulator)
-
-
Method Detail
-
getAccumulator
public Accumulator getAccumulator()
-
getContext
public XPathContext getContext()
-
open
public void open(Terminator terminator) throws XPathException
Description copied from class:PatternWatch
Open the watch. This is done at the point where it first starts watching for nodes that match the selection.- Specified by:
open
in interfaceWatch
- Overrides:
open
in classPatternWatch
- Throws:
XPathException
- May be raised if a dynamic error occurs
-
setNodeStack
public void setNodeStack(java.util.Stack<FleetingNode> stack)
-
setWatchManager
public void setWatchManager(WatchManager watchManager)
-
startSelectedParentNode
public Receiver startSelectedParentNode(FleetingParentNode node, Location locationId) throws XPathException
Signal that an element has been found that matches the selection that this Watch is looking for. This method is called by the WatchManager while processing the startElement event that matches the selection. For this purpose, any attributes selected by the last step in the selection are ignored- Parameters:
node
- the element or document node whose start event has been matchedlocationId
- the location associated with the element or document node (may be the location of the instruction that created it)- Returns:
- always null
- Throws:
ValidationException
- May be raised if the constraint implemented by this Watch is violated @param locationId the location of the node in the source, or of the instruction that created itXPathException
- May be raised if a dynamic error occurs
-
isBeingComputed
public boolean isBeingComputed(AccumulatorFn.Phase phase)
-
processItem
public void processItem(Item item) throws XPathException
Signal that a node (other than an element) that matches the selection has been found.- Specified by:
processItem
in interfaceWatch
- Overrides:
processItem
in classPatternWatch
- Parameters:
item
- the node that was matched.- Throws:
XPathException
- May be raised if a dynamic error occurs
-
endSelectedParentNode
public void endSelectedParentNode(Location locationId) throws XPathException
Signal that the endElement event has occurred for the element whose startElement event caused the Watch to be activated.- Parameters:
locationId
- the location of the parsing event- Throws:
ValidationException
- May be raised if the constraint implemented by this Watch is violated @param locationId the location of the node in the source, or of the instruction that created itXPathException
- May be raised if a constraint implemented by this Watch is violated
-
close
public void close() throws XPathException
Description copied from class:PatternWatch
The close() method is called immediately before the Watch is destroyed, that is, when the element whose declaration scopes the constraint implemented by this Watch goes out of scope. The default implementation does nothing.- Specified by:
close
in interfaceWatch
- Overrides:
close
in classPatternWatch
- Throws:
XPathException
- May be raised if a dynamic error occurs
-
getPreDescentValue
public Sequence getPreDescentValue(FleetingNode node) throws XPathException
- Throws:
XPathException
-
getPreDescentValueAtDepth
public Sequence getPreDescentValueAtDepth(int depth) throws XPathException
- Throws:
XPathException
-
getPostDescentValue
public Sequence getPostDescentValue(FleetingNode node) throws XPathException
- Throws:
XPathException
-
-