KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > tinytree > DeclaredPrefixIterator


1 package net.sf.saxon.tinytree;
2 import net.sf.saxon.om.NamePool;
3
4 import java.util.Iterator JavaDoc;
5
6 /**
7 * An iterator supplying the prefixes of the declared namespaces for an element node in a TinyTree
8 */

9
10 final class DeclaredPrefixIterator implements Iterator JavaDoc {
11
12     private TinyTree tree;
13     private NamePool pool;
14     private int owner;
15     private int index;
16
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 JavaDoc next() {
48         int nscode = tree.namespaceCode[index--];
49         return pool.getPrefix(nscode>>16);
50     }
51
52
53     /**
54      * Removes from the underlying collection the last element returned by the
55      * iterator (optional operation). This method can be called only once per
56      * call to <tt>next</tt>. The behavior of an iterator is unspecified if
57      * the underlying collection is modified while the iteration is in
58      * progress in any way other than by calling this method.
59      *
60      * @throws UnsupportedOperationException if the <tt>remove</tt>
61      * operation is not supported by this Iterator.
62      * @throws IllegalStateException if the <tt>next</tt> method has not
63      * yet been called, or the <tt>remove</tt> method has already
64      * been called after the last call to the <tt>next</tt>
65      * method.
66      */

67     public void remove() {
68         throw new UnsupportedOperationException JavaDoc();
69     }
70 }
71
72
73
74 //
75
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
76
// you may not use this file except in compliance with the License. You may obtain a copy of the
77
// License at http://www.mozilla.org/MPL/
78
//
79
// Software distributed under the License is distributed on an "AS IS" basis,
80
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
81
// See the License for the specific language governing rights and limitations under the License.
82
//
83
// The Original Code is: all this file.
84
//
85
// The Initial Developer of the Original Code is Michael H. Kay.
86
//
87
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
88
//
89
// Contributor(s): none.
90
//
91
Popular Tags