net.sf.saxon.evpull

Class NamespaceMaintainer

public class NamespaceMaintainer extends Object implements EventIterator, NamespaceResolver

NamespaceMaintainer is an EventIterator responsible for maintaining namespace context in an event stream. It allows the current namespace context to be determined at any time while processing the stream of events.

Note that this class merely provides the service of keeping track of which namespaces are currently in scope. It does not attempt to remove duplicate namespace declarations, and it does not perform namespace fixup.

Constructor Summary
NamespaceMaintainer(EventIterator base, NamePool namePool)
Create a namespace context for a pull-events pipeline
Method Summary
protected shortgetURICode(short prefixCode)
Get the URI code corresponding to a given prefix code, by searching the in-scope namespaces.
StringgetURIForPrefix(String prefix, boolean useDefault)
Get the namespace URI corresponding to a given prefix.
booleanisFlatSequence()
Determine whether the EventIterator returns a flat sequence of events, or whether it can return nested event iterators
IteratoriteratePrefixes()
Get an iterator over all the prefixes declared in this namespace context.
PullEventnext()
Get the next event in the sequence

Constructor Detail

NamespaceMaintainer

public NamespaceMaintainer(EventIterator base, NamePool namePool)
Create a namespace context for a pull-events pipeline

Parameters: base the previous stage in the pipeline, from which events are read namePool the NamePool

Method Detail

getURICode

protected short getURICode(short prefixCode)
Get the URI code corresponding to a given prefix code, by searching the in-scope namespaces. This is a service provided to subclasses.

Parameters: prefixCode the 16-bit prefix code required

Returns: the 16-bit URI code, or -1 if the prefix is not found

getURIForPrefix

public String getURIForPrefix(String prefix, boolean useDefault)
Get the namespace URI corresponding to a given prefix. Return null if the prefix is not in scope.

Parameters: prefix the namespace prefix useDefault true if the default namespace is to be used when the prefix is ""

Returns: the uri for the namespace, or null if the prefix is not in scope

isFlatSequence

public boolean isFlatSequence()
Determine whether the EventIterator returns a flat sequence of events, or whether it can return nested event iterators

Returns: true if the next() method is guaranteed never to return an EventIterator

iteratePrefixes

public Iterator iteratePrefixes()
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

next

public PullEvent next()
Get the next event in the sequence

Returns: the next event, or null when the sequence is exhausted. Note that since an EventIterator is itself a PullEvent, this method may return a nested iterator.

Throws: net.sf.saxon.trans.XPathException if a dynamic evaluation error occurs