Home | History | Annotate | Download | only in dtm
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one
      3  * or more contributor license agreements. See the NOTICE file
      4  * distributed with this work for additional information
      5  * regarding copyright ownership. The ASF licenses this file
      6  * to you under the Apache License, Version 2.0 (the  "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *     http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  */
     18 /*
     19  * $Id: Axis.java 468653 2006-10-28 07:07:05Z minchau $
     20  */
     21 package org.apache.xml.dtm;
     22 
     23 /**
     24  * Specifies values related to XPath Axes.
     25  * <p>The ancestor, descendant, following, preceding and self axes partition a
     26  * document (ignoring attribute and namespace nodes): they do not overlap
     27  * and together they contain all the nodes in the document.</p>
     28  *
     29  */
     30 public final class Axis
     31 {
     32 
     33   /**
     34    * The ancestor axis contains the ancestors of the context node;
     35    *  the ancestors of the context node consist of the parent of context
     36    *  node and the parent's parent and so on; thus, the ancestor axis will
     37    *  always include the root node, unless the context node is the root node.
     38    */
     39   public static final int ANCESTOR = 0;
     40 
     41   /**
     42    * the ancestor-or-self axis contains the context node and the ancestors of
     43    *  the context node; thus, the ancestor axis will always include the
     44    *  root node.
     45    */
     46   public static final int ANCESTORORSELF = 1;
     47 
     48   /**
     49    * the attribute axis contains the attributes of the context node; the axis
     50    *  will be empty unless the context node is an element.
     51    */
     52   public static final int ATTRIBUTE = 2;
     53 
     54   /** The child axis contains the children of the context node. */
     55   public static final int CHILD = 3;
     56 
     57   /**
     58    * The descendant axis contains the descendants of the context node;
     59    *  a descendant is a child or a child of a child and so on; thus the
     60    *  descendant axis never contains attribute or namespace nodes.
     61    */
     62   public static final int DESCENDANT = 4;
     63 
     64   /**
     65    * The descendant-or-self axis contains the context node and the
     66    *  descendants of the context node.
     67    */
     68   public static final int DESCENDANTORSELF = 5;
     69 
     70   /**
     71    * the following axis contains all nodes in the same document as the
     72    *  context node that are after the context node in document order, excluding
     73    *  any descendants and excluding attribute nodes and namespace nodes.
     74    */
     75   public static final int FOLLOWING = 6;
     76 
     77   /**
     78    * The following-sibling axis contains all the following siblings of the
     79    *  context node; if the context node is an attribute node or namespace node,
     80    *  the following-sibling axis is empty.
     81    */
     82   public static final int FOLLOWINGSIBLING = 7;
     83 
     84   /**
     85    * The namespace axis contains the namespace nodes of the context node; the
     86    *  axis will be empty unless the context node is an element.
     87    */
     88   public static final int NAMESPACEDECLS = 8;
     89 
     90   /**
     91    * The namespace axis contains the namespace nodes of the context node; the
     92    *  axis will be empty unless the context node is an element.
     93    */
     94   public static final int NAMESPACE = 9;
     95 
     96   /**
     97    * The parent axis contains the parent of the context node,
     98    *  if there is one.
     99    */
    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 }
    221