Debian Codegraph @

net/sf/saxon/pull/PullFilter.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.pull;
9
10 import net.sf.saxon.event.PipelineConfiguration;
11 import net.sf.saxon.om.AttributeCollection;
12 import net.sf.saxon.om.NamePool;
13 import net.sf.saxon.om.NamespaceBinding;
14 import net.sf.saxon.om.NodeName;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.type.SchemaType;
17 import net.sf.saxon.value.AtomicValue;
18
19 import java.util.List;
20
21 /**
22 * PullFilter is a pass-through filter class that links one PullProvider to another PullProvider
23 * in a pipeline. This class passes all events through completely unchanged. The class is designed
24 * so that subclasses can modify this behavior by altering some of the events.
25 */
26
27 public class PullFilter implements PullProvider {
28
29 private PullProvider base;
30 private PipelineConfiguration pipe;
31 protected int currentEvent;
32
33 /**
34 * Create a PullFilter
35 *
36 * @param base the PullProvider to which requests are to be passed
37 */
38
39 public PullFilter(/*@NotNull*/ PullProvider base) {
40 this.base = base;
41 if (base.getPipelineConfiguration() != null) {
42 setPipelineConfiguration(base.getPipelineConfiguration());
43 }
44 }
45
46 /**
47 * Set configuration information. This must only be called before any events
48 * have been read.
49 */
50
51 public void setPipelineConfiguration(PipelineConfiguration pipe) {
52 this.pipe = pipe;
53 base.setPipelineConfiguration(pipe);
54 }
55
56 /**
57 * Get configuration information.
58 */
59
60 public PipelineConfiguration getPipelineConfiguration() {
61 return pipe;
62 }
63
64 /**
65 * Helper method to get the current namePool
66 *
67 * @return the NamePool
68 */
69
70 public final NamePool getNamePool() {
71 return getPipelineConfiguration().getConfiguration().getNamePool();
72 }
73
74 /**
75 * Get the underlying PullProvider
76 *
77 * @return the underlying PullProvider
78 */
79
80 public PullProvider getUnderlyingProvider() {
81 return base;
82 }
83
84 /**
85 * Get the next event.
86 * <p>Note that a subclass that overrides this method is responsible for ensuring
87 * that current() works properly. This can be achieved by setting the field
88 * currentEvent to the event returned by any call on next().</p>
89 *
90 * @return an integer code indicating the type of event. The code
91 * {@link #END_OF_INPUT} is returned at the end of the sequence.
92 */
93
94 public int next() throws XPathException {
95 return base.next();
96 }
97
98 /**
99 * Get the event most recently returned by next(), or by other calls that change
100 * the position, for example getStringValue() and skipToMatchingEnd(). This
101 * method does not change the position of the PullProvider.
102 *
103 * @return the current event
104 */
105
106 public int current() {
107 return currentEvent;
108 }
109
110 /**
111 * Get the attributes associated with the current element. This method must
112 * be called only after a START_ELEMENT event has been notified. The contents
113 * of the returned AttributeCollection are guaranteed to remain unchanged
114 * until the next START_ELEMENT event, but may be modified thereafter. The object
115 * should not be modified by the client.
116 * <p>Attributes may be read before or after reading the namespaces of an element,
117 * but must not be read after the first child node has been read, or after calling
118 * one of the methods skipToEnd(), getStringValue(), or getTypedValue().</p>
119 *
120 * @return an AttributeCollection representing the attributes of the element
121 * that has just been notified.
122 */
123
124 public AttributeCollection getAttributes() throws XPathException {
125 return base.getAttributes();
126 }
127
128 /**
129 * Get the namespace declarations associated with the current element. This method must
130 * be called only after a START_ELEMENT event has been notified. In the case of a top-level
131 * START_ELEMENT event (that is, an element that either has no parent node, or whose parent
132 * is not included in the sequence being read), the NamespaceDeclarations object returned
133 * will contain a namespace declaration for each namespace that is in-scope for this element
134 * node. In the case of a non-top-level element, the NamespaceDeclarations will contain
135 * a set of namespace declarations and undeclarations, representing the differences between
136 * this element and its parent.
137 * <p>It is permissible for this method to return namespace declarations that are redundant.</p>
138 * <p>The NamespaceDeclarations object is guaranteed to remain unchanged until the next START_ELEMENT
139 * event, but may then be overwritten. The object should not be modified by the client.</p>
140 * <p>Namespaces may be read before or after reading the attributes of an element,
141 * but must not be read after the first child node has been read, or after calling
142 * one of the methods skipToEnd(), getStringValue(), or getTypedValue().</p>
143 */
144
145 public NamespaceBinding[] getNamespaceDeclarations() throws XPathException {
146 return base.getNamespaceDeclarations();
147 }
148
149 /**
150 * Skip the current subtree. This method may be called only immediately after
151 * a START_DOCUMENT or START_ELEMENT event. This call returns the matching
152 * END_DOCUMENT or END_ELEMENT event; the next call on next() will return
153 * the event following the END_DOCUMENT or END_ELEMENT.
154 */
155
156 public int skipToMatchingEnd() throws XPathException {
157 return base.skipToMatchingEnd();
158 }
159
160 /**
161 * Close the event reader. This indicates that no further events are required.
162 * It is not necessary to close an event reader after {@link #END_OF_INPUT} has
163 * been reported, but it is recommended to close it if reading terminates
164 * prematurely. Once an event reader has been closed, the effect of further
165 * calls on next() is undefined.
166 */
167
168 public void close() {
169 base.close();
170 }
171
172 public NodeName getNodeName() {
173 return base.getNodeName();
174 }
175
176 /**
177 * Get the string value of the current element, text node, processing-instruction,
178 * or top-level attribute or namespace node, or atomic value.
179 * <p>In other situations the result is undefined and may result in an IllegalStateException.</p>
180 * <p>If the most recent event was a {@link #START_ELEMENT}, this method causes the content
181 * of the element to be read. The next event notified will be the corresponding {@link #END_ELEMENT}.</p>
182 *
183 * @return the String Value of the node in question, defined according to the rules in the
184 * XPath data model.
185 */
186
187 public CharSequence getStringValue() throws XPathException {
188 return base.getStringValue();
189 }
190
191 /**
192 * Get an atomic value. This call may be used only when the last event reported was
193 * ATOMIC_VALUE. This indicates that the PullProvider is reading a sequence that contains
194 * a free-standing atomic value; it is never used when reading the content of a node.
195 */
196
197 public AtomicValue getAtomicValue() {
198 return base.getAtomicValue();
199 }
200
201 /**
202 * Get the type annotation of the current attribute or element node, or atomic value.
203 * The result of this method is undefined unless the most recent event was START_ELEMENT,
204 * ATTRIBUTE, or ATOMIC_VALUE.
205 *
206 * @return the type annotation.
207 */
208
209 public SchemaType getSchemaType() {
210 return base.getSchemaType();
211 }
212
213 /**
214 * Get the location of the current event.
215 * For an event stream representing a real document, the location information
216 * should identify the location in the lexical XML source. For a constructed document, it should
217 * identify the location in the query or stylesheet that caused the node to be created.
218 * A value of null can be returned if no location information is available.
219 */
220
221 public net.sf.saxon.expr.parser.Location getSourceLocator() {
222 return base.getSourceLocator();
223 }
224
225 /**
226 * Get a list of unparsed entities.
227 *
228 * @return a list of unparsed entities, or null if the information is not available, or
229 * an empty list if there are no unparsed entities.
230 */
231
232 public List<UnparsedEntity> getUnparsedEntities() {
233 return base.getUnparsedEntities();
234 }
235 }
236