Project

Profile

Help

Revision 1d527cc3

Added by Michael Kay over 12 years ago

Fix bug 2711894 (location info in EventPull pipeline)

View differences:

latest9.1/bj/net/sf/saxon/tinytree/TinyTreeEventIterator.java
1 1
package net.sf.saxon.tinytree;
2 2

  
3
import net.sf.saxon.event.LocationProvider;
4
import net.sf.saxon.event.PipelineConfiguration;
3 5
import net.sf.saxon.evpull.*;
4 6
import net.sf.saxon.om.NamespaceDeclarationsImpl;
5 7
import net.sf.saxon.trans.XPathException;
6 8
import net.sf.saxon.type.Type;
7
import net.sf.saxon.event.PipelineConfiguration;
8 9

  
9 10
/**
10 11
 * This implementation of the Saxon event-pull interface starts from a document, element,
......
16 17
 * materializes any Node objects.
17 18
 */
18 19

  
19
public class TinyTreeEventIterator implements EventIterator {
20
public class TinyTreeEventIterator implements EventIterator, LocationProvider {
20 21

  
21 22
    private int startNodeNr;
22 23
    private int currentNodeNr;
......
36 37

  
37 38
    public TinyTreeEventIterator(TinyNodeImpl startNode, PipelineConfiguration pipe) {
38 39
        this.pipe = pipe;
40
        this.pipe.setLocationProvider(this);
39 41
        int kind = startNode.getNodeKind();
40 42
        if (kind != Type.DOCUMENT && kind != Type.ELEMENT) {
41 43
            throw new IllegalArgumentException("TinyTreeEventIterator must start at a document or element node");
......
112 114
                StartElementEvent see = new StartElementEvent(pipe);
113 115
                see.setNameCode(tree.nameCode[currentNodeNr]);
114 116
                see.setTypeCode(tree.getTypeAnnotation(currentNodeNr));
117
                see.setLocationId(currentNodeNr);
115 118
                // add the attributes
116 119
                int index = tree.alpha[currentNodeNr];
117 120
                if (index >= 0) {
......
144 147

  
145 148
    }
146 149

  
147

  
148

  
149 150
    /**
150
     * Get the attributes associated with the current element. This method must
151
     * be called only after a START_ELEMENT event has been notified. The contents
152
     * of the returned AttributeCollection are guaranteed to remain unchanged
153
     * until the next START_ELEMENT event, but may be modified thereafter. The object
154
     * should not be modified by the client.
155
     * <p/>
156
     * <p>Attributes may be read before or after reading the namespaces of an element,
157
     * but must not be read after the first child node has been read, or after calling
158
     * one of the methods skipToEnd(), getStringValue(), or getTypedValue().</p>
151
     * Determine whether the EventIterator returns a flat sequence of events, or whether it can return
152
     * nested event iterators
159 153
     *
160
     * @return an AttributeCollection representing the attributes of the element
161
     *         that has just been notified.
154
     * @return true if the next() method is guaranteed never to return an EventIterator
162 155
     */
163 156

  
164
//    public AttributeCollection getAttributes() throws XPathException {
165
//        if (tree.nodeKind[currentNodeNr] == Type.ELEMENT) {
166
//            if (tree.alpha[currentNodeNr] == -1) {
167
//                return AttributeCollectionImpl.EMPTY_ATTRIBUTE_COLLECTION;
168
//            }
169
//            return new TinyAttributeCollection(tree, currentNodeNr);
170
//        } else {
171
//            throw new IllegalStateException("getAttributes() called when current event is not ELEMENT_START");
172
//        }
173
//    }
157
    public boolean isFlatSequence() {
158
        return true;
159
    }
174 160

  
175 161
    /**
176
     * Get the namespace declarations associated with the current element. This method must
177
     * be called only after a START_ELEMENT event has been notified. In the case of a top-level
178
     * START_ELEMENT event (that is, an element that either has no parent node, or whose parent
179
     * is not included in the sequence being read), the NamespaceDeclarations object returned
180
     * will contain a namespace declaration for each namespace that is in-scope for this element
181
     * node. In the case of a non-top-level element, the NamespaceDeclarations will contain
182
     * a set of namespace declarations and undeclarations, representing the differences between
183
     * this element and its parent.
184
     * <p/>
185
     * <p>It is permissible for this method to return namespace declarations that are redundant.</p>
186
     * <p/>
187
     * <p>The NamespaceDeclarations object is guaranteed to remain unchanged until the next START_ELEMENT
188
     * event, but may then be overwritten. The object should not be modified by the client.</p>
189
     * <p/>
190
     * <p>Namespaces may be read before or after reading the attributes of an element,
191
     * but must not be read after the first child node has been read, or after calling
192
     * one of the methods skipToEnd(), getStringValue(), or getTypedValue().</p>*
162
     * Get location information: the system Id of the current start element event
163
     * @param locationId in this case, the node number in the tiny tree
164
     * @return the system Id of the node: that is its base URI, before taking xml:base into account
193 165
     */
194 166

  
195
//    public NamespaceDeclarations getNamespaceDeclarations() throws XPathException {
196
//        if (tree.nodeKind[currentNodeNr] == Type.ELEMENT) {
197
//            int[] decl;
198
//            if (currentNodeNr == startNodeNr) {
199
//                // get all inscope namespaces for a top-level element in the sequence.
200
//                decl = TinyElementImpl.getInScopeNamespaces(tree, currentNodeNr, nsBuffer);
201
//            } else {
202
//                // only namespace declarations (and undeclarations) on this element are required
203
//                decl = TinyElementImpl.getDeclaredNamespaces(tree, currentNodeNr, nsBuffer);
204
//            }
205
//            nsDeclarations.setNamespaceCodes(decl);
206
//            return nsDeclarations;
207
//        }
208
//        throw new IllegalStateException("getNamespaceDeclarations() called when current event is not START_ELEMENT");
209
//    }
167
    public String getSystemId(long locationId) {
168
        return tree.getSystemId((int)locationId);
169
    }
210 170

  
171
    /**
172
     * Get location information: the line number of the current start element event
173
     * @param locationId in this case, the node number in the tiny tree
174
     * @return the line number of the node if known, or -1 otherwise
175
     */
211 176

  
177
    public int getLineNumber(long locationId) {
178
        return tree.getLineNumber((int)locationId);
179
    }
212 180

  
213 181
    /**
214
     * Determine whether the EventIterator returns a flat sequence of events, or whether it can return
215
     * nested event iterators
216
     *
217
     * @return true if the next() method is guaranteed never to return an EventIterator
182
     * Get location information: the column number of the current start element event
183
     * @param locationId in this case, the node number in the tiny tree
184
     * @return the column number of the node if known, or -1 otherwise
218 185
     */
219 186

  
220
    public boolean isFlatSequence() {
221
        return true;
187
    public int getColumnNumber(long locationId) {
188
        return tree.getColumnNumber((int)locationId);
222 189
    }
223 190
}
224 191

  

Also available in: Unified diff