KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > om > Axis


1 package com.icl.saxon.om;
2 import com.icl.saxon.pattern.NodeTest;
3 import com.icl.saxon.expr.XPathException;
4
5 /**
6 * An axis, that is a direction of navigation in the document structure.
7 */

8
9 public final class Axis {
10
11     /**
12     * Constants representing the axes
13     */

14     
15     public static final byte ANCESTOR = 0;
16     public static final byte ANCESTOR_OR_SELF = 1;
17     public static final byte ATTRIBUTE = 2;
18     public static final byte CHILD = 3;
19     public static final byte DESCENDANT = 4;
20     public static final byte DESCENDANT_OR_SELF = 5;
21     public static final byte FOLLOWING = 6;
22     public static final byte FOLLOWING_SIBLING = 7;
23     public static final byte NAMESPACE = 8;
24     public static final byte PARENT = 9;
25     public static final byte PRECEDING = 10;
26     public static final byte PRECEDING_SIBLING = 11;
27     public static final byte SELF = 12;
28     
29     // preceding-or-ancestor axis gives all preceding nodes including ancestors,
30
// in reverse document order
31

32     public static final byte PRECEDING_OR_ANCESTOR = 13;
33     
34     
35     /**
36     * Table indicating the principal node type of each axis
37     */

38     
39     public static final short[] principalNodeType =
40     {
41         NodeInfo.ELEMENT, // ANCESTOR
42
NodeInfo.ELEMENT, // ANCESTOR_OR_SELF;
43
NodeInfo.ATTRIBUTE, // ATTRIBUTE;
44
NodeInfo.ELEMENT, // CHILD;
45
NodeInfo.ELEMENT, // DESCENDANT;
46
NodeInfo.ELEMENT, // DESCENDANT_OR_SELF;
47
NodeInfo.ELEMENT, // FOLLOWING;
48
NodeInfo.ELEMENT, // FOLLOWING_SIBLING;
49
NodeInfo.NAMESPACE, // NAMESPACE;
50
NodeInfo.ELEMENT, // PARENT;
51
NodeInfo.ELEMENT, // PRECEDING;
52
NodeInfo.ELEMENT, // PRECEDING_SIBLING;
53
NodeInfo.ELEMENT, // SELF;
54
NodeInfo.ELEMENT, // PRECEDING_OR_ANCESTOR;
55
};
56     
57     /**
58     * Table indicating for each axis whether it is in forwards document order
59     */

60     
61     public static final boolean[] isForwards =
62     {
63         false, // ANCESTOR
64
false, // ANCESTOR_OR_SELF;
65
true, // ATTRIBUTE;
66
true, // CHILD;
67
true, // DESCENDANT;
68
true, // DESCENDANT_OR_SELF;
69
true, // FOLLOWING;
70
true, // FOLLOWING_SIBLING;
71
false, // NAMESPACE;
72
true, // PARENT;
73
false, // PRECEDING;
74
false, // PRECEDING_SIBLING;
75
true, // SELF;
76
false, // PRECEDING_OR_ANCESTOR;
77
};
78
79     /**
80     * Table indicating for each axis whether it is in reverse document order
81     */

82     
83     public static final boolean[] isReverse =
84     {
85         true, // ANCESTOR
86
true, // ANCESTOR_OR_SELF;
87
false, // ATTRIBUTE;
88
false, // CHILD;
89
false, // DESCENDANT;
90
false, // DESCENDANT_OR_SELF;
91
false, // FOLLOWING;
92
false, // FOLLOWING_SIBLING;
93
false, // NAMESPACE;
94
true, // PARENT;
95
true, // PRECEDING;
96
true, // PRECEDING_SIBLING;
97
true, // SELF;
98
true, // PRECEDING_OR_ANCESTOR;
99
};
100
101     /**
102     * Table indicating for each axis whether it is a peer axis. An axis is a peer
103     * axis if no node on the axis is an ancestor of another node on the axis.
104     */

105     
106     public static final boolean[] isPeerAxis =
107     {
108         false, // ANCESTOR
109
false, // ANCESTOR_OR_SELF;
110
true, // ATTRIBUTE;
111
true, // CHILD;
112
false, // DESCENDANT;
113
false, // DESCENDANT_OR_SELF;
114
false, // FOLLOWING; # TODO: old code said true... #
115
true, // FOLLOWING_SIBLING;
116
false, // NAMESPACE;
117
true, // PARENT;
118
false, // PRECEDING;
119
true, // PRECEDING_SIBLING;
120
true, // SELF;
121
false, // PRECEDING_OR_ANCESTOR;
122
};
123
124     /**
125     * Table indicating for each axis whether it is contained within the subtree
126     * rooted at the origin node.
127     */

128     
129     public static final boolean[] isSubtreeAxis =
130     {
131         false, // ANCESTOR
132
false, // ANCESTOR_OR_SELF;
133
true, // ATTRIBUTE;
134
true, // CHILD;
135
true, // DESCENDANT;
136
true, // DESCENDANT_OR_SELF;
137
false, // FOLLOWING;
138
false, // FOLLOWING_SIBLING;
139
false, // NAMESPACE;
140
false, // PARENT;
141
false, // PRECEDING;
142
false, // PRECEDING_SIBLING;
143
true, // SELF;
144
false, // PRECEDING_OR_ANCESTOR;
145
};
146   
147     /**
148     * Table giving the name each axis
149     */

150     
151     public static final String JavaDoc[] axisName =
152     {
153         "ancestor", // ANCESTOR
154
"ancestor-or-self", // ANCESTOR_OR_SELF;
155
"attribute", // ATTRIBUTE;
156
"child", // CHILD;
157
"descendant", // DESCENDANT;
158
"descendant-or-self", // DESCENDANT_OR_SELF;
159
"following", // FOLLOWING;
160
"following-sibling", // FOLLOWING_SIBLING;
161
"namespace", // NAMESPACE;
162
"parent", // PARENT;
163
"preceding", // PRECEDING;
164
"preceding-sibling", // PRECEDING_SIBLING;
165
"self", // SELF;
166
"preceding-or-ancestor",// PRECEDING_OR_ANCESTOR;
167
};
168
169     /**
170     * Resolve an axis name into a symbolic constant representing the axis
171     */

172
173     public static byte getAxisNumber(String JavaDoc name) throws XPathException {
174         if (name.equals("ancestor")) return ANCESTOR;
175         if (name.equals("ancestor-or-self")) return ANCESTOR_OR_SELF;
176         if (name.equals("attribute")) return ATTRIBUTE;
177         if (name.equals("child")) return CHILD;
178         if (name.equals("descendant")) return DESCENDANT;
179         if (name.equals("descendant-or-self")) return DESCENDANT_OR_SELF;
180         if (name.equals("following")) return FOLLOWING;
181         if (name.equals("following-sibling")) return FOLLOWING_SIBLING;
182         if (name.equals("namespace")) return NAMESPACE;
183         if (name.equals("parent")) return PARENT;
184         if (name.equals("preceding")) return PRECEDING;
185         if (name.equals("preceding-sibling")) return PRECEDING_SIBLING;
186         if (name.equals("self")) return SELF;
187         // preceding-or-ancestor cannot be used in an XPath expression
188
throw new XPathException("Unknown axis name: " + name);
189     }
190
191
192
193 }
194
195 /*
196     // a list for any future cut-and-pasting...
197     ANCESTOR
198     ANCESTOR_OR_SELF;
199     ATTRIBUTE;
200     CHILD;
201     DESCENDANT;
202     DESCENDANT_OR_SELF;
203     FOLLOWING;
204     FOLLOWING_SIBLING;
205     NAMESPACE;
206     PARENT;
207     PRECEDING;
208     PRECEDING_SIBLING;
209     SELF;
210 */

211
212
213 //
214
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
215
// you may not use this file except in compliance with the License. You may obtain a copy of the
216
// License at http://www.mozilla.org/MPL/
217
//
218
// Software distributed under the License is distributed on an "AS IS" basis,
219
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
220
// See the License for the specific language governing rights and limitations under the License.
221
//
222
// The Original Code is: all this file.
223
//
224
// The Initial Developer of the Original Code is
225
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
226
//
227
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
228
//
229
// Contributor(s): none.
230
//
231
Popular Tags