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
51 package org.jaxen.saxpath;
52
53 import org.jaxen.JaxenRuntimeException;
54
55
56
57 /***
58 *
59 * Internal SAXPath class that contains constants representing
60 * XPath operators to avoid a lot of string comparisons.
61 */
62 public class Axis
63 {
64
65 private Axis() {}
66
67
68 /*** Marker for an invalid axis */
69 public final static int INVALID_AXIS = 0;
70
71 /*** The <code>child</code> axis */
72 public final static int CHILD = 1;
73
74 /*** The <code>descendant</code> axis */
75 public final static int DESCENDANT = 2;
76
77 /*** The <code>parent</code> axis */
78 public final static int PARENT = 3;
79
80 /*** The <code>ancestor</code> axis */
81 public final static int ANCESTOR = 4;
82
83 /*** The <code>following-sibling</code> axis */
84 public final static int FOLLOWING_SIBLING = 5;
85
86 /*** The <code>preceding-sibling</code> axis */
87 public final static int PRECEDING_SIBLING = 6;
88
89 /*** The <code>following</code> axis */
90 public final static int FOLLOWING = 7;
91
92 /*** The <code>preceding</code> axis */
93 public final static int PRECEDING = 8;
94
95 /*** The <code>attribute</code> axis */
96 public final static int ATTRIBUTE = 9;
97
98 /*** The <code>namespace</code> axis */
99 public final static int NAMESPACE = 10;
100
101 /*** The <code>self</code> axis */
102 public final static int SELF = 11;
103
104 /*** The <code>descendant-or-self</code> axis */
105 public final static int DESCENDANT_OR_SELF = 12;
106
107 /*** The <code>ancestor-or-self</code> axis */
108 public final static int ANCESTOR_OR_SELF = 13;
109
110 /***
111 * <p>
112 * Returns the name of the axis.
113 * </p>
114 *
115 * @param axisNum the axis code
116 * @return the name of the axis such as might be used in an XPath expression
117 * @throws JaxenRuntimeException if the number does not represent one of the 13
118 * XPath axes
119 */
120 public static String lookup(int axisNum)
121 {
122 switch ( axisNum )
123 {
124 case CHILD:
125 return "child";
126
127 case DESCENDANT:
128 return "descendant";
129
130 case PARENT:
131 return "parent";
132
133 case ANCESTOR:
134 return "ancestor";
135
136 case FOLLOWING_SIBLING:
137 return "following-sibling";
138
139 case PRECEDING_SIBLING:
140 return "preceding-sibling";
141
142 case FOLLOWING:
143 return "following";
144
145 case PRECEDING:
146 return "preceding";
147
148 case ATTRIBUTE:
149 return "attribute";
150
151 case NAMESPACE:
152 return "namespace";
153
154 case SELF:
155 return "self";
156
157 case DESCENDANT_OR_SELF:
158 return "descendant-or-self";
159
160 case ANCESTOR_OR_SELF:
161 return "ancestor-or-self";
162 }
163
164 throw new JaxenRuntimeException("Illegal Axis Number");
165 }
166
167 /***
168 * <p>
169 * Returns the code for an axis given its name.
170 * </p>
171 *
172 * @param axisName the name of the axis: child, parent, descendant, descendant-or-self, etc.
173 * @return the axis code
174 */
175 public static int lookup(String axisName)
176 {
177
178
179
180 if ( "child".equals( axisName ) )
181 {
182 return CHILD;
183 }
184
185 if ( "descendant".equals( axisName ) )
186 {
187 return DESCENDANT;
188 }
189
190 if ( "parent".equals( axisName ) )
191 {
192 return PARENT;
193 }
194
195 if ( "ancestor".equals( axisName ) )
196 {
197 return ANCESTOR;
198 }
199
200 if ( "following-sibling".equals( axisName ) )
201 {
202 return FOLLOWING_SIBLING;
203 }
204
205 if ( "preceding-sibling".equals( axisName ) )
206 {
207 return PRECEDING_SIBLING;
208 }
209
210 if ( "following".equals( axisName ) )
211 {
212 return FOLLOWING;
213 }
214
215 if ( "preceding".equals( axisName ) )
216 {
217 return PRECEDING;
218 }
219
220 if ( "attribute".equals( axisName ) )
221 {
222 return ATTRIBUTE;
223 }
224
225 if ( "namespace".equals( axisName ) )
226 {
227 return NAMESPACE;
228 }
229
230 if ( "self".equals( axisName ) )
231 {
232 return SELF;
233 }
234
235 if ( "descendant-or-self".equals( axisName ) )
236 {
237 return DESCENDANT_OR_SELF;
238 }
239
240 if ( "ancestor-or-self".equals( axisName ) )
241 {
242 return ANCESTOR_OR_SELF;
243 }
244
245 return INVALID_AXIS;
246 }
247 }