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