View Javadoc

1   /*
2    * $Header: /home/projects/jaxen/scm/jaxen/src/java/main/org/jaxen/saxpath/Axis.java,v 1.2 2004/06/15 01:36:01 proyal Exp $
3    * $Revision: 1.2 $
4    * $Date: 2004/06/15 01:36:01 $
5    *
6    * ====================================================================
7    *
8    * Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
9    * All rights reserved.
10   *
11   * Redistribution and use in source and binary forms, with or without
12   * modification, are permitted provided that the following conditions
13   * are met:
14   *
15   * 1. Redistributions of source code must retain the above copyright
16   *    notice, this list of conditions, and the following disclaimer.
17   *
18   * 2. Redistributions in binary form must reproduce the above copyright
19   *    notice, this list of conditions, and the disclaimer that follows
20   *    these conditions in the documentation and/or other materials
21   *    provided with the distribution.
22   *
23   * 3. The name "Jaxen" must not be used to endorse or promote products
24   *    derived from this software without prior written permission.  For
25   *    written permission, please contact license@jaxen.org.
26   *
27   * 4. Products derived from this software may not be called "Jaxen", nor
28   *    may "Jaxen" appear in their name, without prior written permission
29   *    from the Jaxen Project Management (pm@jaxen.org).
30   *
31   * In addition, we request (but do not require) that you include in the
32   * end-user documentation provided with the redistribution and/or in the
33   * software itself an acknowledgement equivalent to the following:
34   *     "This product includes software developed by the
35   *      Jaxen Project (http://www.jaxen.org/)."
36   * Alternatively, the acknowledgment may be graphical using the logos
37   * available at http://www.jaxen.org/
38   *
39   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42   * DISCLAIMED.  IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
43   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50   * SUCH DAMAGE.
51   *
52   * ====================================================================
53   * This software consists of voluntary contributions made by many
54   * individuals on behalf of the Jaxen Project and was originally
55   * created by bob mcwhirter <bob@werken.com> and
56   * James Strachan <jstrachan@apache.org>.  For more information on the
57   * Jaxen Project, please see <http://www.jaxen.org/>.
58   *
59   * $Id: Axis.java,v 1.2 2004/06/15 01:36:01 proyal Exp $
60   */
61  
62  
63  
64  package org.jaxen.saxpath;
65  
66  
67  
68  public class Axis
69  {
70      /*** Marker for an invalid axis */
71      public final static int INVALID_AXIS       =  0;
72  
73      /*** The <code>child</code> axis */
74      public final static int CHILD              =  1;
75  
76      /*** The <code>descendant</code> axis */
77      public final static int DESCENDANT         =  2;
78  
79      /*** The <code>parent</code> axis */
80      public final static int PARENT             =  3;
81  
82      /*** The <code>ancestor</code> axis */
83      public final static int ANCESTOR           =  4;
84  
85      /*** The <code>following-sibling</code> axis */
86      public final static int FOLLOWING_SIBLING  =  5;
87  
88      /*** The <code>preceding-sibling</code> axis */
89      public final static int PRECEDING_SIBLING  =  6;
90  
91      /*** The <code>following</code> axis */
92      public final static int FOLLOWING          =  7;
93  
94      /*** The <code>preceding</code> axis */
95      public final static int PRECEDING          =  8;
96  
97      /*** The <code>attribute</code> axis */
98      public final static int ATTRIBUTE          =  9;
99  
100     /*** The <code>namespace</code> axis */
101     public final static int NAMESPACE          = 10;
102 
103     /*** The <code>self</code> axis */
104     public final static int SELF               = 11;
105 
106     /*** The <code>descendant-or-self</code> axis */
107     public final static int DESCENDANT_OR_SELF = 12;
108 
109     /*** The <code>ancestor-or-self</code> axis */
110     public final static int ANCESTOR_OR_SELF   = 13;
111 
112     public static String lookup(int axisNum)
113     {
114         switch ( axisNum )
115         {
116             case CHILD:
117                 return "child";
118 
119             case DESCENDANT:
120                 return "descendant";
121 
122             case PARENT:
123                 return "parent";
124 
125             case ANCESTOR:
126                 return "ancestor";
127 
128             case FOLLOWING_SIBLING:
129                 return "following-sibling";
130 
131             case PRECEDING_SIBLING:
132                 return "preceding-sibling";
133 
134             case FOLLOWING:
135                 return "following";
136 
137             case PRECEDING:
138                 return "preceding";
139 
140             case ATTRIBUTE:
141                 return "attribute";
142 
143             case NAMESPACE:
144                 return "namespace";
145 
146             case SELF:
147                 return "self";
148 
149             case DESCENDANT_OR_SELF:
150                 return "descendant-or-self";
151 
152             case ANCESTOR_OR_SELF:
153                 return "ancestor-or-self";
154         }
155 
156         return null;
157     }
158 
159     public static int lookup(String axisName)
160     {
161         if ( "child".equals( axisName ) )
162         {
163             return CHILD;
164         }
165 
166         if ( "descendant".equals( axisName ) )
167         {
168             return DESCENDANT;
169         }
170 
171         if ( "parent".equals( axisName ) )
172         {
173             return PARENT;
174         }
175 
176         if ( "ancestor".equals( axisName ) )
177         {
178             return ANCESTOR;
179         }
180 
181         if ( "following-sibling".equals( axisName ) )
182         {
183             return FOLLOWING_SIBLING;
184         }
185 
186         if ( "preceding-sibling".equals( axisName ) )
187         {
188             return PRECEDING_SIBLING;
189         }
190 
191         if ( "following".equals( axisName ) )
192         {
193             return FOLLOWING;
194         }
195 
196         if ( "preceding".equals( axisName ) )
197         {
198             return PRECEDING;
199         }
200 
201         if ( "attribute".equals( axisName ) )
202         {
203             return ATTRIBUTE;
204         }
205 
206         if ( "namespace".equals( axisName ) )
207         {
208             return NAMESPACE;
209         }
210 
211         if ( "self".equals( axisName ) )
212         {
213             return SELF;
214         }
215 
216         if ( "descendant-or-self".equals( axisName ) )
217         {
218             return DESCENDANT_OR_SELF;
219         }
220 
221         if ( "ancestor-or-self".equals( axisName ) )
222         {
223             return ANCESTOR_OR_SELF;
224         }
225 
226         return INVALID_AXIS;
227     }
228 }