1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 package org.jaxen.util;
51
52 import java.util.Iterator;
53 import java.util.NoSuchElementException;
54
55 import org.jaxen.JaxenConstants;
56 import org.jaxen.Navigator;
57 import org.jaxen.UnsupportedAxisException;
58
59 /***
60 *
61 * Represents the XPath <code>following-sibling</code> axis.
62 * The "<code>following-sibling</code> axis contains all the
63 * folowing siblings of the context node; if the context node is an
64 * attribute node or namespace node, the <code>following-sibling</code>
65 * axis is empty."
66 *
67 * @version 1.2b12
68 *
69 */
70 public class FollowingSiblingAxisIterator implements Iterator
71 {
72 private Object contextNode;
73 private Navigator navigator;
74 private Iterator siblingIter;
75
76 /***
77 * Create a new <code>following-sibling</code> axis iterator.
78 *
79 * @param contextNode the node to start from
80 * @param navigator the object model specific navigator
81 */
82 public FollowingSiblingAxisIterator(Object contextNode,
83 Navigator navigator) throws UnsupportedAxisException
84 {
85 this.contextNode = contextNode;
86 this.navigator = navigator;
87 init();
88 }
89
90 private void init() throws UnsupportedAxisException
91 {
92 Object parent = this.navigator.getParentNode( this.contextNode );
93
94 if ( parent != null )
95 {
96 siblingIter = this.navigator.getChildAxisIterator( parent );
97
98 while ( siblingIter.hasNext() )
99 {
100 Object eachChild = siblingIter.next();
101 if ( eachChild.equals(this.contextNode) ) break;
102 }
103 }
104 else {
105 siblingIter = JaxenConstants.EMPTY_ITERATOR;
106 }
107
108 }
109
110 /***
111 * Returns true if there are any following siblings remain; false otherwise.
112 *
113 * @return true if any following siblings remain; false otherwise
114 *
115 * @see java.util.Iterator#hasNext()
116 */
117 public boolean hasNext()
118 {
119 return siblingIter.hasNext();
120 }
121
122 /***
123 * Returns the next following sibling.
124 *
125 * @return the next following sibling
126 *
127 * @throws NoSuchElementException if no following siblings remain
128 *
129 * @see java.util.Iterator#next()
130 */
131 public Object next() throws NoSuchElementException
132 {
133 return siblingIter.next();
134 }
135
136 /***
137 * This operation is not supported.
138 *
139 * @throws UnsupportedOperationException always
140 */
141 public void remove() throws UnsupportedOperationException
142 {
143 throw new UnsupportedOperationException();
144 }
145
146 }