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 classWatchManager.GroupingScope
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Stack<java.util.List<com.saxonica.ee.stream.watch.WatchManager.ClosedownAction>>activeWatchStackprotected intelementStackTopprotected 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 voidaddPrearrangedWatches()voidaddWatch(Watch watch, boolean autoClose)Add a new Watch.voidappend(Item item, Location locationId, int copyNamespaces)Append an arbitrary item (node or atomic value) to the outputvoidcharacters(java.lang.CharSequence chars, Location locationId, int properties)Text nodevoidclose()Notify the end of the event streamvoidcomment(java.lang.CharSequence chars, Location locationId, int properties)Output a commentvoidendDocument()Notify the end of a document nodevoidendElement()Notify end of elementvoidendGroupingScope(WatchManager.GroupingScope current)Called during a partitioning for-each-group whenever a group is closedFleetingParentNodegetCurrentNode()intgetDepth()FleetingDocumentNodegetDocumentNode()MultiAccumulatorWatchgetMultiAccumulatorWatch()OutputtergetOutputter()java.lang.StringgetURIForPrefix(java.lang.String prefix, boolean useDefault)Get the namespace URI corresponding to a given prefix.XPathContextgetXPathContext()java.util.Iterator<java.lang.String>iteratePrefixes()Get an iterator over all the prefixes declared in this namespace context.voidprocessingInstruction(java.lang.String target, java.lang.CharSequence data, Location locationId, int properties)Processing InstructionvoidremoveWatch(Watch watch)Remove a watchvoidrestartElement(Watch watch)During schema validation, the startElement() event is emitted before we can examine all the streamed assertions that might apply to that element.voidsetOutputter(Outputter outputter)voidsetUnparsedEntity(java.lang.String name, java.lang.String systemID, java.lang.String publicID)Notify an unparsed entity URI.voidsetXPathContext(XPathContext context)voidstartCapturingGroupingWatches(WatchManager.GroupingScope scope)voidstartDocument(int properties)Start of a document node.voidstartElement(NodeName elementName, SchemaType typeCode, AttributeMap attributes, NamespaceMap namespaces, Location location, int properties)Output element start tagWatchManager.GroupingScopestartGroupingScope()Called during a partitioning for-each-group whenever a new group is startedvoidstopCapturingGroupingWatches(WatchManager.GroupingScope scope)booleanusesTypeAnnotations()Ask whether this Receiver (or the downstream pipeline) makes any use of the type annotations supplied on element and attribute eventsvoidwatchAccumulators(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:
appendin interfaceReceiver- Specified by:
appendin 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 XPathExceptionNotify the end of the event stream- Specified by:
closein interfaceReceiver- Throws:
XPathException- if an error occurs
-
startDocument
public void startDocument(int properties) throws XPathExceptionStart of a document node.- Specified by:
startDocumentin 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:
startElementin 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 XPathExceptionText node- Specified by:
charactersin 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 XPathExceptionNotify end of element- Specified by:
endElementin interfaceReceiver- Throws:
XPathException- if an error occurs
-
endDocument
public void endDocument() throws XPathExceptionNotify the end of a document node- Specified by:
endDocumentin interfaceReceiver- Throws:
XPathException- if an error occurs
-
comment
public void comment(java.lang.CharSequence chars, Location locationId, int properties) throws XPathExceptionOutput a comment- Specified by:
commentin 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 XPathExceptionProcessing Instruction- Specified by:
processingInstructionin 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 XPathExceptionNotify an unparsed entity URI.- Specified by:
setUnparsedEntityin interfaceReceiver- Overrides:
setUnparsedEntityin 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:
getURIForPrefixin 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:NamespaceResolverGet 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:
iteratePrefixesin 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:
usesTypeAnnotationsin 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)
-
-