001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: Axis.java,v 1.6 2004/12/15 17:35:47 jycli Exp $
018: */
019: package org.apache.xml.dtm;
020:
021: /**
022: * Specifies values related to XPath Axes.
023: * <p>The ancestor, descendant, following, preceding and self axes partition a
024: * document (ignoring attribute and namespace nodes): they do not overlap
025: * and together they contain all the nodes in the document.</p>
026: *
027: */
028: public final class Axis {
029:
030: /**
031: * The ancestor axis contains the ancestors of the context node;
032: * the ancestors of the context node consist of the parent of context
033: * node and the parent's parent and so on; thus, the ancestor axis will
034: * always include the root node, unless the context node is the root node.
035: */
036: public static final int ANCESTOR = 0;
037:
038: /**
039: * the ancestor-or-self axis contains the context node and the ancestors of
040: * the context node; thus, the ancestor axis will always include the
041: * root node.
042: */
043: public static final int ANCESTORORSELF = 1;
044:
045: /**
046: * the attribute axis contains the attributes of the context node; the axis
047: * will be empty unless the context node is an element.
048: */
049: public static final int ATTRIBUTE = 2;
050:
051: /** The child axis contains the children of the context node. */
052: public static final int CHILD = 3;
053:
054: /**
055: * The descendant axis contains the descendants of the context node;
056: * a descendant is a child or a child of a child and so on; thus the
057: * descendant axis never contains attribute or namespace nodes.
058: */
059: public static final int DESCENDANT = 4;
060:
061: /**
062: * The descendant-or-self axis contains the context node and the
063: * descendants of the context node.
064: */
065: public static final int DESCENDANTORSELF = 5;
066:
067: /**
068: * the following axis contains all nodes in the same document as the
069: * context node that are after the context node in document order, excluding
070: * any descendants and excluding attribute nodes and namespace nodes.
071: */
072: public static final int FOLLOWING = 6;
073:
074: /**
075: * The following-sibling axis contains all the following siblings of the
076: * context node; if the context node is an attribute node or namespace node,
077: * the following-sibling axis is empty.
078: */
079: public static final int FOLLOWINGSIBLING = 7;
080:
081: /**
082: * The namespace axis contains the namespace nodes of the context node; the
083: * axis will be empty unless the context node is an element.
084: */
085: public static final int NAMESPACEDECLS = 8;
086:
087: /**
088: * The namespace axis contains the namespace nodes of the context node; the
089: * axis will be empty unless the context node is an element.
090: */
091: public static final int NAMESPACE = 9;
092:
093: /**
094: * The parent axis contains the parent of the context node,
095: * if there is one.
096: */
097: public static final int PARENT = 10;
098:
099: /**
100: * The preceding axis contains all nodes in the same document as the context
101: * node that are before the context node in document order, excluding any
102: * ancestors and excluding attribute nodes and namespace nodes
103: */
104: public static final int PRECEDING = 11;
105:
106: /**
107: * The preceding-sibling axis contains all the preceding siblings of the
108: * context node; if the context node is an attribute node or namespace node,
109: * the preceding-sibling axis is empty.
110: */
111: public static final int PRECEDINGSIBLING = 12;
112:
113: /** The self axis contains just the context node itself. */
114: public static final int SELF = 13;
115:
116: /**
117: * A non-xpath axis, traversing the subtree including the subtree
118: * root, descendants, attributes, and namespace node decls.
119: */
120: public static final int ALLFROMNODE = 14;
121:
122: /**
123: * A non-xpath axis, traversing the the preceding and the ancestor nodes,
124: * needed for inverseing select patterns to match patterns.
125: */
126: public static final int PRECEDINGANDANCESTOR = 15;
127:
128: // ===========================================
129: // All axis past this are absolute.
130:
131: /**
132: * A non-xpath axis, returns all nodes in the tree from and including the
133: * root.
134: */
135: public static final int ALL = 16;
136:
137: /**
138: * A non-xpath axis, returns all nodes that aren't namespaces or attributes,
139: * from and including the root.
140: */
141: public static final int DESCENDANTSFROMROOT = 17;
142:
143: /**
144: * A non-xpath axis, returns all nodes that aren't namespaces or attributes,
145: * from and including the root.
146: */
147: public static final int DESCENDANTSORSELFFROMROOT = 18;
148:
149: /**
150: * A non-xpath axis, returns root only.
151: */
152: public static final int ROOT = 19;
153:
154: /**
155: * A non-xpath axis, for functions.
156: */
157: public static final int FILTEREDLIST = 20;
158:
159: /**
160: * A table to identify whether an axis is a reverse axis;
161: */
162: private static final boolean[] isReverse = { true, // ancestor
163: true, // ancestor-or-self
164: false, // attribute
165: false, // child
166: false, // descendant
167: false, // descendant-or-self
168: false, // following
169: false, // following-sibling
170: false, // namespace
171: false, // namespace-declarations
172: false, // parent (one node, has no order)
173: true, // preceding
174: true, // preceding-sibling
175: false // self (one node, has no order)
176: };
177:
178: /** The names of the axes for diagnostic purposes. */
179: private static final String[] names = { "ancestor", // 0
180: "ancestor-or-self", // 1
181: "attribute", // 2
182: "child", // 3
183: "descendant", // 4
184: "descendant-or-self", // 5
185: "following", // 6
186: "following-sibling", // 7
187: "namespace-decls", // 8
188: "namespace", // 9
189: "parent", // 10
190: "preceding", // 11
191: "preceding-sibling", // 12
192: "self", // 13
193: "all-from-node", // 14
194: "preceding-and-ancestor", // 15
195: "all", // 16
196: "descendants-from-root", // 17
197: "descendants-or-self-from-root", // 18
198: "root", // 19
199: "filtered-list" // 20
200: };
201:
202: public static boolean isReverse(int axis) {
203: return isReverse[axis];
204: }
205:
206: public static String getNames(int index) {
207: return names[index];
208: }
209:
210: public static int getNamesLength() {
211: return names.length;
212: }
213:
214: }
|