KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > pull > PullFilter


1 package net.sf.saxon.pull;
2
3 import net.sf.saxon.event.PipelineConfiguration;
4 import net.sf.saxon.om.AttributeCollection;
5 import net.sf.saxon.om.NamespaceDeclarations;
6 import net.sf.saxon.om.NamePool;
7 import net.sf.saxon.trans.XPathException;
8 import net.sf.saxon.value.AtomicValue;
9
10 import javax.xml.transform.SourceLocator JavaDoc;
11
12 /**
13  * PullFilter is a pass-through filter class that links one PullProvider to another PullProvider
14  * in a pipeline. This class passes all events through completely unchanged. The class is designed
15  * so that subclasses can modify this behavior by altering some of the events.
16 */

17
18 public class PullFilter implements PullProvider {
19
20     private PullProvider base;
21     private PipelineConfiguration pipe;
22     protected int currentEvent;
23
24     /**
25      * Create a PullFilter
26      * @param base the PullProvider to which requests are to be passed
27      */

28
29     public PullFilter(PullProvider base) {
30         this.base = base;
31         setPipelineConfiguration(base.getPipelineConfiguration());
32     }
33
34     /**
35      * Set configuration information. This must only be called before any events
36      * have been read.
37      */

38
39     public void setPipelineConfiguration(PipelineConfiguration pipe) {
40         this.pipe = pipe;
41         base.setPipelineConfiguration(pipe);
42     }
43
44     /**
45      * Get configuration information.
46      */

47
48     public PipelineConfiguration getPipelineConfiguration() {
49         return pipe;
50     }
51
52     /**
53      * Helper method to get the current namePool
54      */

55
56     public final NamePool getNamePool() {
57         return getPipelineConfiguration().getConfiguration().getNamePool();
58     }
59
60     /**
61      * Get the underlying PullProvider
62      */

63
64     public PullProvider getUnderlyingProvider() {
65         return base;
66     }
67
68     /**
69      * Get the next event.
70      *
71      * <p>Note that a subclass that overrides this method is responsible for ensuring
72      * that current() works properly. This can be achieved by setting the field
73      * currentEvent to the event returned by any call on next().</p>
74      *
75      * @return an integer code indicating the type of event. The code
76      * {@link #END_OF_INPUT} is returned at the end of the sequence.
77      */

78
79     public int next() throws XPathException {
80         return base.next();
81     }
82
83     /**
84      * Get the event most recently returned by next(), or by other calls that change
85      * the position, for example getStringValue() and skipToMatchingEnd(). This
86      * method does not change the position of the PullProvider.
87      *
88      * @return the current event
89      */

90
91     public int current() {
92         return currentEvent;
93     }
94
95     /**
96      * Get the attributes associated with the current element. This method must
97      * be called only after a START_ELEMENT event has been notified. The contents
98      * of the returned AttributeCollection are guaranteed to remain unchanged
99      * until the next START_ELEMENT event, but may be modified thereafter. The object
100      * should not be modified by the client.
101      * <p/>
102      * <p>Attributes may be read before or after reading the namespaces of an element,
103      * but must not be read after the first child node has been read, or after calling
104      * one of the methods skipToEnd(), getStringValue(), or getTypedValue().</p>
105      *
106      * @return an AttributeCollection representing the attributes of the element
107      * that has just been notified.
108      */

109
110     public AttributeCollection getAttributes() throws XPathException {
111         return base.getAttributes();
112     }
113
114     /**
115      * Get the namespace declarations associated with the current element. This method must
116      * be called only after a START_ELEMENT event has been notified. In the case of a top-level
117      * START_ELEMENT event (that is, an element that either has no parent node, or whose parent
118      * is not included in the sequence being read), the NamespaceDeclarations object returned
119      * will contain a namespace declaration for each namespace that is in-scope for this element
120      * node. In the case of a non-top-level element, the NamespaceDeclarations will contain
121      * a set of namespace declarations and undeclarations, representing the differences between
122      * this element and its parent.
123      * <p/>
124      * <p>It is permissible for this method to return namespace declarations that are redundant.</p>
125      * <p/>
126      * <p>The NamespaceDeclarations object is guaranteed to remain unchanged until the next START_ELEMENT
127      * event, but may then be overwritten. The object should not be modified by the client.</p>
128      * <p/>
129      * <p>Namespaces may be read before or after reading the attributes of an element,
130      * but must not be read after the first child node has been read, or after calling
131      * one of the methods skipToEnd(), getStringValue(), or getTypedValue().</p>*
132      */

133
134     public NamespaceDeclarations getNamespaceDeclarations() throws XPathException {
135         return base.getNamespaceDeclarations();
136     }
137
138     /**
139      * Skip the current subtree. This method may be called only immediately after
140      * a START_DOCUMENT or START_ELEMENT event. This call returns the matching
141      * END_DOCUMENT or END_ELEMENT event; the next call on next() will return
142      * the event following the END_DOCUMENT or END_ELEMENT.
143      */

144
145     public int skipToMatchingEnd() throws XPathException {
146         return base.skipToMatchingEnd();
147     }
148
149     /**
150      * Close the event reader. This indicates that no further events are required.
151      * It is not necessary to close an event reader after {@link #END_OF_INPUT} has
152      * been reported, but it is recommended to close it if reading terminates
153      * prematurely. Once an event reader has been closed, the effect of further
154      * calls on next() is undefined.
155      */

156
157     public void close() {
158         base.close();
159     }
160
161     /**
162      * Get the nameCode identifying the name of the current node. This method
163      * can be used after the {@link #START_ELEMENT}, {@link #PROCESSING_INSTRUCTION},
164      * {@link #ATTRIBUTE}, or {@link #NAMESPACE} events. With some PullProvider implementations,
165      * it can also be used after {@link #END_ELEMENT}, but this is not guaranteed: a client who
166      * requires the information at that point (for example, to do serialization) should insert an
167      * {@link ElementNameTracker} into the pipeline.
168      * If called at other times, the result is undefined and may result in an IllegalStateException.
169      * If called when the current node is an unnamed namespace node (a node representing the default namespace)
170      * the returned value is -1.
171      *
172      * @return the nameCode. The nameCode can be used to obtain the prefix, local name,
173      * and namespace URI from the name pool.
174      */

175
176     public int getNameCode() {
177         return base.getNameCode();
178     }
179
180     /**
181      * Get the fingerprint of the name of the element. This is similar to the nameCode, except that
182      * it does not contain any information about the prefix: so two elements with the same fingerprint
183      * have the same name, excluding prefix. This method
184      * can be used after the {@link #START_ELEMENT}, {@link #END_ELEMENT}, {@link #PROCESSING_INSTRUCTION},
185      * {@link #ATTRIBUTE}, or {@link #NAMESPACE} events.
186      * If called at other times, the result is undefined and may result in an IllegalStateException.
187      * If called when the current node is an unnamed namespace node (a node representing the default namespace)
188      * the returned value is -1.
189      *
190      * @return the fingerprint. The fingerprint can be used to obtain the local name
191      * and namespace URI from the name pool.
192      */

193
194     public int getFingerprint() {
195         return base.getFingerprint();
196     }
197
198     /**
199      * Get the string value of the current element, text node, processing-instruction,
200      * or top-level attribute or namespace node, or atomic value.
201      * <p/>
202      * <p>In other situations the result is undefined and may result in an IllegalStateException.</p>
203      * <p/>
204      * <p>If the most recent event was a {@link #START_ELEMENT}, this method causes the content
205      * of the element to be read. The next event notified will be the corresponding {@link #END_ELEMENT}.</p>
206      *
207      * @return the String Value of the node in question, defined according to the rules in the
208      * XPath data model.
209      */

210
211     public CharSequence JavaDoc getStringValue() throws XPathException {
212         return base.getStringValue();
213     }
214
215     /**
216      * Get an atomic value. This call may be used only when the last event reported was
217      * ATOMIC_VALUE. This indicates that the PullProvider is reading a sequence that contains
218      * a free-standing atomic value; it is never used when reading the content of a node.
219      */

220
221     public AtomicValue getAtomicValue() {
222         return base.getAtomicValue();
223     }
224
225     /**
226      * Get the type annotation of the current attribute or element node, or atomic value.
227      * The result of this method is undefined unless the most recent event was START_ELEMENT,
228      * ATTRIBUTE, or ATOMIC_VALUE.
229      *
230      * @return the type annotation. This code is the fingerprint of a type name, which may be
231      * resolved to a {@link net.sf.saxon.type.SchemaType} by access to the Configuration.
232      */

233
234     public int getTypeAnnotation() {
235         return base.getTypeAnnotation();
236     }
237
238     /**
239      * Get the location of the current event.
240      * For an event stream representing a real document, the location information
241      * should identify the location in the lexical XML source. For a constructed document, it should
242      * identify the location in the query or stylesheet that caused the node to be created.
243      * A value of null can be returned if no location information is available.
244      */

245
246     public SourceLocator JavaDoc getSourceLocator() {
247         return base.getSourceLocator();
248     }
249 }
250
251 //
252
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
253
// you may not use this file except in compliance with the License. You may obtain a copy of the
254
// License at http://www.mozilla.org/MPL/
255
//
256
// Software distributed under the License is distributed on an "AS IS" basis,
257
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
258
// See the License for the specific language governing rights and limitations under the License.
259
//
260
// The Original Code is: all this file.
261
//
262
// The Initial Developer of the Original Code is Michael H. Kay.
263
//
264
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
265
//
266
// Contributor(s): none.
267
//
268
Popular Tags