Package com.saxonica.ee.stream.watch
Class WatchManager
- java.lang.Object
-
- net.sf.saxon.event.SequenceReceiver
-
- com.saxonica.ee.stream.watch.WatchManager
-
- All Implemented Interfaces:
javax.xml.transform.Result
,Receiver
,NamespaceResolver
- Direct Known Subclasses:
ConstraintChecker
public class WatchManager extends SequenceReceiver implements NamespaceResolver
This class sits on a push pipeline and evaluates the passing element and attribute nodes. One or more Watch objects can be registered with the pipeline at any time; element and attribute events are notified to the active Watch objects. A watch that is added immediately after a startElement call is automatically dropped at the corresponding endElement call. If a Watch matches a startElement call, then it becomes an active Watch; it is automatically deactivated (but not dropped) at the corresponding endElement call.A Watch is not itself a receiver, but it can nominate a Receiver to receive all events while it is active. It will stop receiving events when it is deactivated.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WatchManager.GroupingScope
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Stack<java.util.List<com.saxonica.ee.stream.watch.WatchManager.ClosedownAction>>
activeWatchStack
protected int
elementStackTop
protected java.util.List<Watch>
watchList
-
Fields inherited from class net.sf.saxon.event.SequenceReceiver
pipelineConfiguration, previousAtomic, systemId
-
-
Constructor Summary
Constructors Constructor Description WatchManager(PipelineConfiguration pipe)
Create a WatchManager
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addPrearrangedWatches()
void
addWatch(Watch watch, boolean autoClose)
Add a new Watch.void
append(Item item, Location locationId, int copyNamespaces)
Append an arbitrary item (node or atomic value) to the outputvoid
characters(java.lang.CharSequence chars, Location locationId, int properties)
Text nodevoid
close()
Notify the end of the event streamvoid
comment(java.lang.CharSequence chars, Location locationId, int properties)
Output a commentvoid
endDocument()
Notify the end of a document nodevoid
endElement()
Notify end of elementvoid
endGroupingScope(WatchManager.GroupingScope current)
Called during a partitioning for-each-group whenever a group is closedFleetingParentNode
getCurrentNode()
int
getDepth()
FleetingDocumentNode
getDocumentNode()
MultiAccumulatorWatch
getMultiAccumulatorWatch()
Outputter
getOutputter()
java.lang.String
getURIForPrefix(java.lang.String prefix, boolean useDefault)
Get the namespace URI corresponding to a given prefix.XPathContext
getXPathContext()
java.util.Iterator<java.lang.String>
iteratePrefixes()
Get an iterator over all the prefixes declared in this namespace context.void
processingInstruction(java.lang.String target, java.lang.CharSequence data, Location locationId, int properties)
Processing Instructionvoid
removeWatch(Watch watch)
Remove a watchvoid
restartElement(Watch watch)
During schema validation, the startElement() event is emitted before we can examine all the streamed assertions that might apply to that element.void
setOutputter(Outputter outputter)
void
setUnparsedEntity(java.lang.String name, java.lang.String systemID, java.lang.String publicID)
Notify an unparsed entity URI.void
setXPathContext(XPathContext context)
void
startCapturingGroupingWatches(WatchManager.GroupingScope scope)
void
startDocument(int properties)
Start of a document node.void
startElement(NodeName elementName, SchemaType typeCode, AttributeMap attributes, NamespaceMap namespaces, Location location, int properties)
Output element start tagWatchManager.GroupingScope
startGroupingScope()
Called during a partitioning for-each-group whenever a new group is startedvoid
stopCapturingGroupingWatches(WatchManager.GroupingScope scope)
boolean
usesTypeAnnotations()
Ask whether this Receiver (or the downstream pipeline) makes any use of the type annotations supplied on element and attribute eventsvoid
watchAccumulators(MultiAccumulatorWatch multiWatch)
-
Methods inherited from class net.sf.saxon.event.SequenceReceiver
append, decompose, flatten, getConfiguration, getErrorCodeForDecomposingFunctionItems, getNamePool, getPipelineConfiguration, getSystemId, handlesAppend, open, setPipelineConfiguration, setSystemId
-
-
-
-
Field Detail
-
elementStackTop
protected int elementStackTop
-
watchList
protected java.util.List<Watch> watchList
-
activeWatchStack
protected java.util.Stack<java.util.List<com.saxonica.ee.stream.watch.WatchManager.ClosedownAction>> activeWatchStack
-
-
Constructor Detail
-
WatchManager
public WatchManager(PipelineConfiguration pipe)
Create a WatchManager- Parameters:
pipe
- the pipeline configuration
-
-
Method Detail
-
setXPathContext
public void setXPathContext(XPathContext context)
-
getXPathContext
public XPathContext getXPathContext()
-
setOutputter
public void setOutputter(Outputter outputter)
-
getOutputter
public Outputter getOutputter()
-
append
public void append(Item item, Location locationId, int copyNamespaces) throws XPathException
Append an arbitrary item (node or atomic value) to the output- Specified by:
append
in interfaceReceiver
- Specified by:
append
in classSequenceReceiver
- Parameters:
item
- the item to be appendedlocationId
- the location of the calling instruction, for diagnosticscopyNamespaces
- if the item is an element node, this indicates whether its namespaces need to be copied. Values areReceiverOption.ALL_NAMESPACES
; the default (0) means- Throws:
XPathException
- if an error occurs
-
close
public void close() throws XPathException
Notify the end of the event stream- Specified by:
close
in interfaceReceiver
- Throws:
XPathException
- if an error occurs
-
startDocument
public void startDocument(int properties) throws XPathException
Start of a document node.- Specified by:
startDocument
in interfaceReceiver
- Parameters:
properties
-- Throws:
XPathException
- if an error occurs
-
startElement
public void startElement(NodeName elementName, SchemaType typeCode, AttributeMap attributes, NamespaceMap namespaces, Location location, int properties) throws XPathException
Output element start tag- Specified by:
startElement
in interfaceReceiver
- Parameters:
elementName
- the name of the element.typeCode
- the type annotation of the element.attributes
- the attributes of this elementnamespaces
- the in-scope namespaces of this element: generally this is all the in-scope namespaces, without relying on inheriting namespaces from parent elementslocation
- an object providing information about the module, line, and column where the node originatedproperties
- bit-significant properties of the element node. If there are no relevant properties, zero is supplied. The definitions of the bits are in classReceiverOption
- Throws:
XPathException
- if an error occurs
-
restartElement
public void restartElement(Watch watch) throws XPathException
During schema validation, the startElement() event is emitted before we can examine all the streamed assertions that might apply to that element. So this method can be used to process a Watch against the most recent start element event, on the basis that we might have missed it the first time round.- Throws:
XPathException
-
getDepth
public int getDepth()
-
getCurrentNode
public FleetingParentNode getCurrentNode()
-
addPrearrangedWatches
protected void addPrearrangedWatches() throws XPathException
- Throws:
XPathException
-
characters
public void characters(java.lang.CharSequence chars, Location locationId, int properties) throws XPathException
Text node- Specified by:
characters
in interfaceReceiver
- Parameters:
chars
- The characterslocationId
- provides information such as line number and system ID.properties
- Bit significant value. The following bits are defined:- DISABLE_ESCAPING
- Disable escaping for this text node
- USE_CDATA
- Output as a CDATA section
- Throws:
XPathException
- if an error occurs
-
endElement
public void endElement() throws XPathException
Notify end of element- Specified by:
endElement
in interfaceReceiver
- Throws:
XPathException
- if an error occurs
-
endDocument
public void endDocument() throws XPathException
Notify the end of a document node- Specified by:
endDocument
in interfaceReceiver
- Throws:
XPathException
- if an error occurs
-
comment
public void comment(java.lang.CharSequence chars, Location locationId, int properties) throws XPathException
Output a comment- Specified by:
comment
in interfaceReceiver
- Parameters:
chars
- The content of the commentlocationId
- provides information such as line number and system ID.properties
- Additional information about the comment.- Throws:
XPathException
- if an error occurs
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.CharSequence data, Location locationId, int properties) throws XPathException
Processing Instruction- Specified by:
processingInstruction
in interfaceReceiver
- Parameters:
target
- The PI name. This must be a legal name (it will not be checked).data
- The data portion of the processing instructionlocationId
- provides information such as line number and system ID.properties
- Additional information about the PI.- Throws:
XPathException
- if an error occurs
-
setUnparsedEntity
public void setUnparsedEntity(java.lang.String name, java.lang.String systemID, java.lang.String publicID) throws XPathException
Notify an unparsed entity URI.- Specified by:
setUnparsedEntity
in interfaceReceiver
- Overrides:
setUnparsedEntity
in classSequenceReceiver
- Parameters:
name
- The name of the unparsed entitysystemID
- The system identifier of the unparsed entitypublicID
- The public identifier of the unparsed entity- Throws:
XPathException
- if an error occurs
-
addWatch
public void addWatch(Watch watch, boolean autoClose) throws XPathException
Add a new Watch. This is associated with the current level in the element stack, and is automatically closed and dropped when the current element goes out of scope.- Parameters:
watch
- the watch to be addedautoClose
- set to true if the watch is to be automatically opened as soon as it is registered, and is to be automatically closed when it goes out of scope.- Throws:
XPathException
- if any error occurs
-
removeWatch
public void removeWatch(Watch watch)
Remove a watch- Parameters:
watch
- the watch to be removed. No error occurs if the watch is unknown or inactive.
-
getURIForPrefix
public java.lang.String getURIForPrefix(java.lang.String prefix, boolean useDefault)
Get the namespace URI corresponding to a given prefix. Return null if the prefix is not in scope.- Specified by:
getURIForPrefix
in interfaceNamespaceResolver
- Parameters:
prefix
- the namespace prefix. May be the zero-length string, indicating that there is no prefix. This indicates either the default namespace or the null namespace, depending on the value of useDefault.useDefault
- true if the default namespace is to be used when the prefix is "". If false, the method returns "" when the prefix is "".- Returns:
- the uri for the namespace, or null if the prefix is not in scope. The "null namespace" is represented by the pseudo-URI "".
-
iteratePrefixes
public java.util.Iterator<java.lang.String> iteratePrefixes()
Description copied from interface:NamespaceResolver
Get an iterator over all the prefixes declared in this namespace context. This will include the default namespace (prefix="") and the XML namespace where appropriate- Specified by:
iteratePrefixes
in interfaceNamespaceResolver
- Returns:
- an iterator over all the prefixes for which a namespace binding exists, including the zero-length string to represent the null/absent prefix if it is bound
-
usesTypeAnnotations
public boolean usesTypeAnnotations()
Ask whether this Receiver (or the downstream pipeline) makes any use of the type annotations supplied on element and attribute events- Specified by:
usesTypeAnnotations
in interfaceReceiver
- Returns:
- true if the Receiver makes any use of this information. If false, the caller may supply untyped nodes instead of supplying the type annotation
-
getDocumentNode
public FleetingDocumentNode getDocumentNode()
-
getMultiAccumulatorWatch
public MultiAccumulatorWatch getMultiAccumulatorWatch()
-
watchAccumulators
public void watchAccumulators(MultiAccumulatorWatch multiWatch) throws XPathException
- Throws:
XPathException
-
startGroupingScope
public WatchManager.GroupingScope startGroupingScope()
Called during a partitioning for-each-group whenever a new group is started
-
endGroupingScope
public void endGroupingScope(WatchManager.GroupingScope current) throws XPathException
Called during a partitioning for-each-group whenever a group is closed- Throws:
XPathException
- if a failure occurs
-
startCapturingGroupingWatches
public void startCapturingGroupingWatches(WatchManager.GroupingScope scope)
-
stopCapturingGroupingWatches
public void stopCapturingGroupingWatches(WatchManager.GroupingScope scope)
-
-