Home | History | Annotate | Download | only in compiler
      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: Keywords.java 468655 2006-10-28 07:12:06Z minchau $
     20  */
     21 package org.apache.xpath.compiler;
     22 
     23 import java.util.Hashtable;
     24 
     25 /**
     26  * Table of strings to operation code lookups.
     27  * @xsl.usage internal
     28  */
     29 public class Keywords
     30 {
     31 
     32   /** Table of keywords to opcode associations. */
     33   private static Hashtable m_keywords = new Hashtable();
     34 
     35   /** Table of axes names to opcode associations. */
     36   private static Hashtable m_axisnames = new Hashtable();
     37 
     38   /** Table of function name to function ID associations. */
     39   private static Hashtable m_nodetests = new Hashtable();
     40 
     41   /** Table of node type strings to opcode associations. */
     42   private static Hashtable m_nodetypes = new Hashtable();
     43 
     44   /** ancestor axes string. */
     45   private static final String FROM_ANCESTORS_STRING = "ancestor";
     46 
     47   /** ancestor-or-self axes string. */
     48   private static final String FROM_ANCESTORS_OR_SELF_STRING =
     49     "ancestor-or-self";
     50 
     51   /** attribute axes string. */
     52   private static final String FROM_ATTRIBUTES_STRING = "attribute";
     53 
     54   /** child axes string. */
     55   private static final String FROM_CHILDREN_STRING = "child";
     56 
     57   /** descendant-or-self axes string. */
     58   private static final String FROM_DESCENDANTS_STRING = "descendant";
     59 
     60   /** ancestor axes string. */
     61   private static final String FROM_DESCENDANTS_OR_SELF_STRING =
     62     "descendant-or-self";
     63 
     64   /** following axes string. */
     65   private static final String FROM_FOLLOWING_STRING = "following";
     66 
     67   /** following-sibling axes string. */
     68   private static final String FROM_FOLLOWING_SIBLINGS_STRING =
     69     "following-sibling";
     70 
     71   /** parent axes string. */
     72   private static final String FROM_PARENT_STRING = "parent";
     73 
     74   /** preceding axes string. */
     75   private static final String FROM_PRECEDING_STRING = "preceding";
     76 
     77   /** preceding-sibling axes string. */
     78   private static final String FROM_PRECEDING_SIBLINGS_STRING =
     79     "preceding-sibling";
     80 
     81   /** self axes string. */
     82   private static final String FROM_SELF_STRING = "self";
     83 
     84   /** namespace axes string. */
     85   private static final String FROM_NAMESPACE_STRING = "namespace";
     86 
     87   /** self axes abreviated string. */
     88   private static final String FROM_SELF_ABBREVIATED_STRING = ".";
     89 
     90   /** comment node test string. */
     91   private static final String NODETYPE_COMMENT_STRING = "comment";
     92 
     93   /** text node test string. */
     94   private static final String NODETYPE_TEXT_STRING = "text";
     95 
     96   /** processing-instruction node test string. */
     97   private static final String NODETYPE_PI_STRING = "processing-instruction";
     98 
     99   /** Any node test string. */
    100   private static final String NODETYPE_NODE_STRING = "node";
    101 
    102   /** Wildcard element string. */
    103   private static final String NODETYPE_ANYELEMENT_STRING = "*";
    104 
    105   /** current function string. */
    106   public static final String FUNC_CURRENT_STRING = "current";
    107 
    108   /** last function string. */
    109   public static final String FUNC_LAST_STRING = "last";
    110 
    111   /** position function string. */
    112   public static final String FUNC_POSITION_STRING = "position";
    113 
    114   /** count function string. */
    115   public static final String FUNC_COUNT_STRING = "count";
    116 
    117   /** id function string. */
    118   static final String FUNC_ID_STRING = "id";
    119 
    120   /** key function string (XSLT). */
    121   public static final String FUNC_KEY_STRING = "key";
    122 
    123   /** local-name function string. */
    124   public static final String FUNC_LOCAL_PART_STRING = "local-name";
    125 
    126   /** namespace-uri function string. */
    127   public static final String FUNC_NAMESPACE_STRING = "namespace-uri";
    128 
    129   /** name function string. */
    130   public static final String FUNC_NAME_STRING = "name";
    131 
    132   /** generate-id function string (XSLT). */
    133   public static final String FUNC_GENERATE_ID_STRING = "generate-id";
    134 
    135   /** not function string. */
    136   public static final String FUNC_NOT_STRING = "not";
    137 
    138   /** true function string. */
    139   public static final String FUNC_TRUE_STRING = "true";
    140 
    141   /** false function string. */
    142   public static final String FUNC_FALSE_STRING = "false";
    143 
    144   /** boolean function string. */
    145   public static final String FUNC_BOOLEAN_STRING = "boolean";
    146 
    147   /** lang function string. */
    148   public static final String FUNC_LANG_STRING = "lang";
    149 
    150   /** number function string. */
    151   public static final String FUNC_NUMBER_STRING = "number";
    152 
    153   /** floor function string. */
    154   public static final String FUNC_FLOOR_STRING = "floor";
    155 
    156   /** ceiling function string. */
    157   public static final String FUNC_CEILING_STRING = "ceiling";
    158 
    159   /** round function string. */
    160   public static final String FUNC_ROUND_STRING = "round";
    161 
    162   /** sum function string. */
    163   public static final String FUNC_SUM_STRING = "sum";
    164 
    165   /** string function string. */
    166   public static final String FUNC_STRING_STRING = "string";
    167 
    168   /** starts-with function string. */
    169   public static final String FUNC_STARTS_WITH_STRING = "starts-with";
    170 
    171   /** contains function string. */
    172   public static final String FUNC_CONTAINS_STRING = "contains";
    173 
    174   /** substring-before function string. */
    175   public static final String FUNC_SUBSTRING_BEFORE_STRING =
    176     "substring-before";
    177 
    178   /** substring-after function string. */
    179   public static final String FUNC_SUBSTRING_AFTER_STRING = "substring-after";
    180 
    181   /** normalize-space function string. */
    182   public static final String FUNC_NORMALIZE_SPACE_STRING = "normalize-space";
    183 
    184   /** translate function string. */
    185   public static final String FUNC_TRANSLATE_STRING = "translate";
    186 
    187   /** concat function string. */
    188   public static final String FUNC_CONCAT_STRING = "concat";
    189 
    190   /** system-property function string. */
    191   public static final String FUNC_SYSTEM_PROPERTY_STRING = "system-property";
    192 
    193   /** function-available function string (XSLT). */
    194   public static final String FUNC_EXT_FUNCTION_AVAILABLE_STRING =
    195     "function-available";
    196 
    197   /** element-available function string (XSLT). */
    198   public static final String FUNC_EXT_ELEM_AVAILABLE_STRING =
    199     "element-available";
    200 
    201   /** substring function string. */
    202   public static final String FUNC_SUBSTRING_STRING = "substring";
    203 
    204   /** string-length function string. */
    205   public static final String FUNC_STRING_LENGTH_STRING = "string-length";
    206 
    207   /** unparsed-entity-uri function string (XSLT). */
    208   public static final String FUNC_UNPARSED_ENTITY_URI_STRING =
    209     "unparsed-entity-uri";
    210 
    211   // Proprietary, built in functions
    212 
    213   /** current function string (Proprietary). */
    214   public static final String FUNC_DOCLOCATION_STRING = "document-location";
    215 
    216   static
    217   {
    218     m_axisnames.put(FROM_ANCESTORS_STRING,
    219                     new Integer(OpCodes.FROM_ANCESTORS));
    220     m_axisnames.put(FROM_ANCESTORS_OR_SELF_STRING,
    221                     new Integer(OpCodes.FROM_ANCESTORS_OR_SELF));
    222     m_axisnames.put(FROM_ATTRIBUTES_STRING,
    223                     new Integer(OpCodes.FROM_ATTRIBUTES));
    224     m_axisnames.put(FROM_CHILDREN_STRING,
    225                     new Integer(OpCodes.FROM_CHILDREN));
    226     m_axisnames.put(FROM_DESCENDANTS_STRING,
    227                     new Integer(OpCodes.FROM_DESCENDANTS));
    228     m_axisnames.put(FROM_DESCENDANTS_OR_SELF_STRING,
    229                     new Integer(OpCodes.FROM_DESCENDANTS_OR_SELF));
    230     m_axisnames.put(FROM_FOLLOWING_STRING,
    231                     new Integer(OpCodes.FROM_FOLLOWING));
    232     m_axisnames.put(FROM_FOLLOWING_SIBLINGS_STRING,
    233                     new Integer(OpCodes.FROM_FOLLOWING_SIBLINGS));
    234     m_axisnames.put(FROM_PARENT_STRING,
    235                     new Integer(OpCodes.FROM_PARENT));
    236     m_axisnames.put(FROM_PRECEDING_STRING,
    237                     new Integer(OpCodes.FROM_PRECEDING));
    238     m_axisnames.put(FROM_PRECEDING_SIBLINGS_STRING,
    239                     new Integer(OpCodes.FROM_PRECEDING_SIBLINGS));
    240     m_axisnames.put(FROM_SELF_STRING,
    241                     new Integer(OpCodes.FROM_SELF));
    242     m_axisnames.put(FROM_NAMESPACE_STRING,
    243                     new Integer(OpCodes.FROM_NAMESPACE));
    244     m_nodetypes.put(NODETYPE_COMMENT_STRING,
    245                     new Integer(OpCodes.NODETYPE_COMMENT));
    246     m_nodetypes.put(NODETYPE_TEXT_STRING,
    247                     new Integer(OpCodes.NODETYPE_TEXT));
    248     m_nodetypes.put(NODETYPE_PI_STRING,
    249                     new Integer(OpCodes.NODETYPE_PI));
    250     m_nodetypes.put(NODETYPE_NODE_STRING,
    251                     new Integer(OpCodes.NODETYPE_NODE));
    252     m_nodetypes.put(NODETYPE_ANYELEMENT_STRING,
    253                     new Integer(OpCodes.NODETYPE_ANYELEMENT));
    254     m_keywords.put(FROM_SELF_ABBREVIATED_STRING,
    255                    new Integer(OpCodes.FROM_SELF));
    256     m_keywords.put(FUNC_ID_STRING,
    257                    new Integer(FunctionTable.FUNC_ID));
    258     m_keywords.put(FUNC_KEY_STRING,
    259                    new Integer(FunctionTable.FUNC_KEY));
    260 
    261     m_nodetests.put(NODETYPE_COMMENT_STRING,
    262                     new Integer(OpCodes.NODETYPE_COMMENT));
    263     m_nodetests.put(NODETYPE_TEXT_STRING,
    264                     new Integer(OpCodes.NODETYPE_TEXT));
    265     m_nodetests.put(NODETYPE_PI_STRING,
    266                     new Integer(OpCodes.NODETYPE_PI));
    267     m_nodetests.put(NODETYPE_NODE_STRING,
    268                     new Integer(OpCodes.NODETYPE_NODE));
    269   }
    270 
    271   static Object getAxisName(String key){
    272           return m_axisnames.get(key);
    273   }
    274 
    275   static Object lookupNodeTest(String key){
    276           return m_nodetests.get(key);
    277   }
    278 
    279   static Object getKeyWord(String key){
    280           return m_keywords.get(key);
    281   }
    282 
    283   static Object getNodeType(String key){
    284           return m_nodetypes.get(key);
    285   }
    286 }
    287