01: package net.sf.saxon.tinytree;
02:
03: import net.sf.saxon.om.NamePool;
04:
05: import java.util.Iterator;
06:
07: /**
08: * An iterator supplying the prefixes of the declared namespaces for an element node in a TinyTree
09: */
10:
11: final class DeclaredPrefixIterator implements Iterator {
12:
13: private TinyTree tree;
14: private NamePool pool;
15: private int owner;
16: private int index;
17:
18: public DeclaredPrefixIterator(TinyElementImpl node) {
19: owner = node.nodeNr;
20: tree = node.tree;
21: pool = tree.getNamePool();
22: index = tree.beta[owner]; // by convention
23: }
24:
25: /**
26: * Returns <tt>true</tt> if the iteration has more elements. (In other
27: * words, returns <tt>true</tt> if <tt>next</tt> would return an element
28: * rather than throwing an exception.)
29: *
30: * @return <tt>true</tt> if the iterator has more elements.
31: */
32:
33: public boolean hasNext() {
34: return index >= 0 && tree.namespaceParent[index] == owner;
35: }
36:
37: /**
38: * Returns the next element in the iteration. Calling this method
39: * repeatedly until the {@link #hasNext()} method returns false will
40: * return each element in the underlying collection exactly once.
41: *
42: * @return the next element in the iteration.
43: * @throws java.util.NoSuchElementException
44: * iteration has no more elements.
45: */
46:
47: public Object next() {
48: int nscode = tree.namespaceCode[index--];
49: return pool.getPrefix(nscode >> 16);
50: }
51:
52: /**
53: * Removes from the underlying collection the last element returned by the
54: * iterator (optional operation). This method can be called only once per
55: * call to <tt>next</tt>. The behavior of an iterator is unspecified if
56: * the underlying collection is modified while the iteration is in
57: * progress in any way other than by calling this method.
58: *
59: * @throws UnsupportedOperationException if the <tt>remove</tt>
60: * operation is not supported by this Iterator.
61: * @throws IllegalStateException if the <tt>next</tt> method has not
62: * yet been called, or the <tt>remove</tt> method has already
63: * been called after the last call to the <tt>next</tt>
64: * method.
65: */
66: public void remove() {
67: throw new UnsupportedOperationException();
68: }
69: }
70:
71: //
72: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
73: // you may not use this file except in compliance with the License. You may obtain a copy of the
74: // License at http://www.mozilla.org/MPL/
75: //
76: // Software distributed under the License is distributed on an "AS IS" basis,
77: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
78: // See the License for the specific language governing rights and limitations under the License.
79: //
80: // The Original Code is: all this file.
81: //
82: // The Initial Developer of the Original Code is Michael H. Kay.
83: //
84: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
85: //
86: // Contributor(s): none.
87: //
|