1 16 19 package org.apache.xpath.compiler; 20 21 import org.apache.xpath.Expression; 22 import org.apache.xpath.functions.Function; 23 24 27 public class FunctionTable 28 { 29 30 31 public static final int FUNC_CURRENT = 0; 32 33 34 public static final int FUNC_LAST = 1; 35 36 37 public static final int FUNC_POSITION = 2; 38 39 40 public static final int FUNC_COUNT = 3; 41 42 43 public static final int FUNC_ID = 4; 44 45 46 public static final int FUNC_KEY = 5; 47 48 49 public static final int FUNC_LOCAL_PART = 7; 50 51 52 public static final int FUNC_NAMESPACE = 8; 53 54 55 public static final int FUNC_QNAME = 9; 56 57 58 public static final int FUNC_GENERATE_ID = 10; 59 60 61 public static final int FUNC_NOT = 11; 62 63 64 public static final int FUNC_TRUE = 12; 65 66 67 public static final int FUNC_FALSE = 13; 68 69 70 public static final int FUNC_BOOLEAN = 14; 71 72 73 public static final int FUNC_NUMBER = 15; 74 75 76 public static final int FUNC_FLOOR = 16; 77 78 79 public static final int FUNC_CEILING = 17; 80 81 82 public static final int FUNC_ROUND = 18; 83 84 85 public static final int FUNC_SUM = 19; 86 87 88 public static final int FUNC_STRING = 20; 89 90 91 public static final int FUNC_STARTS_WITH = 21; 92 93 94 public static final int FUNC_CONTAINS = 22; 95 96 97 public static final int FUNC_SUBSTRING_BEFORE = 23; 98 99 100 public static final int FUNC_SUBSTRING_AFTER = 24; 101 102 103 public static final int FUNC_NORMALIZE_SPACE = 25; 104 105 106 public static final int FUNC_TRANSLATE = 26; 107 108 109 public static final int FUNC_CONCAT = 27; 110 111 112 public static final int FUNC_SUBSTRING = 29; 113 114 115 public static final int FUNC_STRING_LENGTH = 30; 116 117 118 public static final int FUNC_SYSTEM_PROPERTY = 31; 119 120 121 public static final int FUNC_LANG = 32; 122 123 124 public static final int FUNC_EXT_FUNCTION_AVAILABLE = 33; 125 126 127 public static final int FUNC_EXT_ELEM_AVAILABLE = 34; 128 129 130 public static final int FUNC_UNPARSED_ENTITY_URI = 36; 131 132 134 135 public static final int FUNC_DOCLOCATION = 35; 136 137 140 public static FuncLoader m_functions[]; 141 142 146 private static final int NUM_BUILT_IN_FUNCS = 37; 147 148 151 private static final int NUM_ALLOWABLE_ADDINS = 30; 152 153 156 static int m_funcNextFreeIndex = NUM_BUILT_IN_FUNCS; 157 158 static 159 { 160 m_functions = new FuncLoader[NUM_BUILT_IN_FUNCS + NUM_ALLOWABLE_ADDINS]; 161 m_functions[FUNC_CURRENT] = new FuncLoader("FuncCurrent", FUNC_CURRENT); 162 m_functions[FUNC_LAST] = new FuncLoader("FuncLast", FUNC_LAST); 163 m_functions[FUNC_POSITION] = new FuncLoader("FuncPosition", 164 FUNC_POSITION); 165 m_functions[FUNC_COUNT] = new FuncLoader("FuncCount", FUNC_COUNT); 166 m_functions[FUNC_ID] = new FuncLoader("FuncId", FUNC_ID); 167 m_functions[FUNC_KEY] = 168 new FuncLoader("org.apache.xalan.templates.FuncKey", FUNC_KEY); 169 170 m_functions[FUNC_LOCAL_PART] = new FuncLoader("FuncLocalPart", 172 FUNC_LOCAL_PART); 173 m_functions[FUNC_NAMESPACE] = new FuncLoader("FuncNamespace", 174 FUNC_NAMESPACE); 175 m_functions[FUNC_QNAME] = new FuncLoader("FuncQname", FUNC_QNAME); 176 m_functions[FUNC_GENERATE_ID] = new FuncLoader("FuncGenerateId", 177 FUNC_GENERATE_ID); 178 m_functions[FUNC_NOT] = new FuncLoader("FuncNot", FUNC_NOT); 179 m_functions[FUNC_TRUE] = new FuncLoader("FuncTrue", FUNC_TRUE); 180 m_functions[FUNC_FALSE] = new FuncLoader("FuncFalse", FUNC_FALSE); 181 m_functions[FUNC_BOOLEAN] = new FuncLoader("FuncBoolean", FUNC_BOOLEAN); 182 m_functions[FUNC_LANG] = new FuncLoader("FuncLang", FUNC_LANG); 183 m_functions[FUNC_NUMBER] = new FuncLoader("FuncNumber", FUNC_NUMBER); 184 m_functions[FUNC_FLOOR] = new FuncLoader("FuncFloor", FUNC_FLOOR); 185 m_functions[FUNC_CEILING] = new FuncLoader("FuncCeiling", FUNC_CEILING); 186 m_functions[FUNC_ROUND] = new FuncLoader("FuncRound", FUNC_ROUND); 187 m_functions[FUNC_SUM] = new FuncLoader("FuncSum", FUNC_SUM); 188 m_functions[FUNC_STRING] = new FuncLoader("FuncString", FUNC_STRING); 189 m_functions[FUNC_STARTS_WITH] = new FuncLoader("FuncStartsWith", 190 FUNC_STARTS_WITH); 191 m_functions[FUNC_CONTAINS] = new FuncLoader("FuncContains", 192 FUNC_CONTAINS); 193 m_functions[FUNC_SUBSTRING_BEFORE] = new FuncLoader("FuncSubstringBefore", 194 FUNC_SUBSTRING_BEFORE); 195 m_functions[FUNC_SUBSTRING_AFTER] = new FuncLoader("FuncSubstringAfter", 196 FUNC_SUBSTRING_AFTER); 197 m_functions[FUNC_NORMALIZE_SPACE] = new FuncLoader("FuncNormalizeSpace", 198 FUNC_NORMALIZE_SPACE); 199 m_functions[FUNC_TRANSLATE] = new FuncLoader("FuncTranslate", 200 FUNC_TRANSLATE); 201 m_functions[FUNC_CONCAT] = new FuncLoader("FuncConcat", FUNC_CONCAT); 202 203 m_functions[FUNC_SYSTEM_PROPERTY] = new FuncLoader("FuncSystemProperty", 205 FUNC_SYSTEM_PROPERTY); 206 m_functions[FUNC_EXT_FUNCTION_AVAILABLE] = 207 new FuncLoader("FuncExtFunctionAvailable", FUNC_EXT_FUNCTION_AVAILABLE); 208 m_functions[FUNC_EXT_ELEM_AVAILABLE] = 209 new FuncLoader("FuncExtElementAvailable", FUNC_EXT_ELEM_AVAILABLE); 210 m_functions[FUNC_SUBSTRING] = new FuncLoader("FuncSubstring", 211 FUNC_SUBSTRING); 212 m_functions[FUNC_STRING_LENGTH] = new FuncLoader("FuncStringLength", 213 FUNC_STRING_LENGTH); 214 m_functions[FUNC_DOCLOCATION] = new FuncLoader("FuncDoclocation", 215 FUNC_DOCLOCATION); 216 m_functions[FUNC_UNPARSED_ENTITY_URI] = 217 new FuncLoader("FuncUnparsedEntityURI", FUNC_UNPARSED_ENTITY_URI); 218 } 219 220 232 public static Function getFunction(int which) 233 throws javax.xml.transform.TransformerException 234 { 235 return m_functions[which].getFunction(); 236 } 237 238 244 public static int installFunction(String name, Expression func) 245 { 246 247 int funcIndex; 248 Object funcIndexObj = Keywords.m_functions.get(name); 249 250 if (null != funcIndexObj) 251 { 252 funcIndex = ((Integer ) funcIndexObj).intValue(); 253 } 254 else 255 { 256 funcIndex = m_funcNextFreeIndex; 257 258 m_funcNextFreeIndex++; 259 260 Keywords.m_functions.put(name, new Integer (funcIndex)); 261 } 262 263 FuncLoader loader = new FuncLoader(func.getClass().getName(), funcIndex); 264 265 m_functions[funcIndex] = loader; 266 267 return funcIndex; 268 } 269 270 278 public static void installFunction(Expression func, int funcIndex) 279 { 280 281 FuncLoader loader = new FuncLoader(func.getClass().getName(), funcIndex); 282 283 m_functions[funcIndex] = loader; 284 } 285 } 286 | Popular Tags |