1 19 20 package org.netbeans.modules.xml.xpath; 21 22 import java.util.HashMap ; 23 24 import org.apache.commons.jxpath.ri.compiler.VariableReference; 25 26 27 33 public abstract class AbstractXPathModelHelper { 34 35 39 protected static HashMap opHash = new HashMap (); 40 44 private static HashMap funcHash = new HashMap (); 45 46 static { 47 opHash.put("+", new Integer (XPathCoreOperation.OP_SUM)); 48 opHash.put("-", new Integer (XPathCoreOperation.OP_MINUS)); 49 opHash.put("*", new Integer (XPathCoreOperation.OP_MULT)); 50 opHash.put("div", new Integer (XPathCoreOperation.OP_DIV)); 51 opHash.put("mod", new Integer (XPathCoreOperation.OP_MOD)); 52 opHash.put("negative", new Integer (XPathCoreOperation.OP_NEGATIVE)); 54 opHash.put("and", new Integer (XPathCoreOperation.OP_AND)); 55 opHash.put("or", new Integer (XPathCoreOperation.OP_OR)); 56 opHash.put("==", new Integer (XPathCoreOperation.OP_EQ)); 57 opHash.put("!=", new Integer (XPathCoreOperation.OP_NE)); 58 opHash.put("<", new Integer (XPathCoreOperation.OP_LT)); 59 opHash.put("<", new Integer (XPathCoreOperation.OP_LT)); 60 opHash.put("<=", new Integer (XPathCoreOperation.OP_LE)); 61 opHash.put("<=", new Integer (XPathCoreOperation.OP_LE)); 62 opHash.put(">", new Integer (XPathCoreOperation.OP_GT)); 63 opHash.put(">", new Integer (XPathCoreOperation.OP_GT)); 64 opHash.put(">=", new Integer (XPathCoreOperation.OP_GE)); 65 opHash.put(">=", new Integer (XPathCoreOperation.OP_GE)); 66 } 67 68 69 static { 70 71 funcHash.put("concat", new Integer (XPathCoreFunction.FUNC_CONCAT)); 72 funcHash.put("last", new Integer (XPathCoreFunction.FUNC_LAST)); 73 funcHash.put("position", new Integer (XPathCoreFunction.FUNC_POSITION)); 74 funcHash.put("count", new Integer (XPathCoreFunction.FUNC_COUNT)); 75 funcHash.put("id", new Integer (XPathCoreFunction.FUNC_ID)); 76 funcHash.put("local-name", new Integer (XPathCoreFunction.FUNC_LOCAL_NAME)); 77 funcHash.put("namespace-uri", new Integer (XPathCoreFunction.FUNC_NAMESPACE_URI)); 78 funcHash.put("name", new Integer (XPathCoreFunction.FUNC_NAME)); 79 funcHash.put("string", new Integer (XPathCoreFunction.FUNC_STRING)); 80 funcHash.put("starts-with", new Integer (XPathCoreFunction.FUNC_STARTS_WITH)); 81 funcHash.put("contains", new Integer (XPathCoreFunction.FUNC_CONTAINS)); 82 funcHash.put("substring-before", new Integer (XPathCoreFunction.FUNC_SUBSTRING_BEFORE)); 83 funcHash.put("substring-after", new Integer (XPathCoreFunction.FUNC_SUBSTRING_AFTER)); 84 funcHash.put("substring", new Integer (XPathCoreFunction.FUNC_SUBSTRING)); 85 funcHash.put("string-length", new Integer (XPathCoreFunction.FUNC_STRING_LENGTH)); 86 funcHash.put("normalize-space", new Integer (XPathCoreFunction.FUNC_NORMALIZE_SPACE)); 87 funcHash.put("translate", new Integer (XPathCoreFunction.FUNC_TRANSLATE)); 88 funcHash.put("boolean", new Integer (XPathCoreFunction.FUNC_BOOLEAN)); 89 funcHash.put("not", new Integer (XPathCoreFunction.FUNC_NOT)); 90 funcHash.put("true", new Integer (XPathCoreFunction.FUNC_TRUE)); 91 funcHash.put("false", new Integer (XPathCoreFunction.FUNC_FALSE)); 92 funcHash.put("lang", new Integer (XPathCoreFunction.FUNC_LANG)); 93 funcHash.put("number", new Integer (XPathCoreFunction.FUNC_NUMBER)); 94 funcHash.put("sum", new Integer (XPathCoreFunction.FUNC_SUM)); 95 funcHash.put("floor", new Integer (XPathCoreFunction.FUNC_FLOOR)); 96 funcHash.put("ceiling", new Integer (XPathCoreFunction.FUNC_CEILING)); 97 funcHash.put("round", new Integer (XPathCoreFunction.FUNC_ROUND)); 98 funcHash.put("null", new Integer (XPathCoreFunction.FUNC_NULL)); 99 funcHash.put("key", new Integer (XPathCoreFunction.FUNC_KEY)); 100 } 101 102 103 private static AbstractXPathModelHelper mXPathModelHelper = null; 104 105 109 public static synchronized AbstractXPathModelHelper getInstance() { 110 if (mXPathModelHelper == null) { 111 mXPathModelHelper = loadImpl(null); 112 } 113 114 return mXPathModelHelper; 115 } 116 117 123 public static synchronized AbstractXPathModelHelper getInstance(ClassLoader loader) { 124 if (null == mXPathModelHelper) { 125 mXPathModelHelper = loadImpl(loader); 126 } 127 return mXPathModelHelper; 128 } 129 130 134 private static AbstractXPathModelHelper loadImpl(ClassLoader loader) { 135 String implClassName = null; 136 AbstractXPathModelHelper axmh = null; 137 try { 138 implClassName = 139 System.getProperty 140 ("org.netbeans.modules.xml.xpath.AbstractXPathModelHelper", 141 "org.netbeans.modules.xml.xpath.impl.XPathModelHelperImpl"); 142 Class implClass = null; 143 if (loader != null) { 144 implClass = Class.forName(implClassName, true, loader); 145 } else { 146 implClass = Class.forName(implClassName); 147 } 148 axmh = (AbstractXPathModelHelper) implClass.newInstance(); 149 } catch (Exception e) { 150 throw new IllegalArgumentException ("Cannot find/load " + implClassName, e); 151 } 152 return axmh; 153 } 154 155 159 public abstract XPathModel newXPathModel(); 160 161 166 public abstract XPathStringLiteral newXPathStringLiteral(String value); 167 168 173 public abstract XPathNumericLiteral newXPathNumericLiteral(Number value); 174 175 180 public abstract XPathPredicateNumericLiteral newXPathPredicateNumericLiteral(Long value); 181 182 187 public abstract XPathCoreFunction newXPathCoreFunction(int function); 188 189 194 public abstract XPathExtensionFunction newXPathExtensionFunction(String name); 195 196 201 public abstract XPathCoreOperation newXPathCoreOperation(int code); 202 203 208 public abstract XPathLocationPath newXPathLocationPath(LocationStep[] steps); 209 210 216 public abstract XPathExpressionPath newXPathExpressionPath(XPathExpression rootExpression, 217 LocationStep[] steps); 218 219 224 public abstract XPathVariableReference newXPathVariableReference(VariableReference vReference); 225 226 231 public abstract XPathPredicateExpression newXPathPredicateExpression(XPathExpression expression); 232 233 238 public Integer getOperatorType(String operator) { 239 240 return (Integer ) opHash.get(operator); 241 } 242 243 248 public Integer getFunctionType(String function) { 249 250 return (Integer ) funcHash.get(function); 251 } 252 253 259 public abstract boolean isValidFunction(String functionName); 260 261 267 public abstract boolean isValidOperator(String operatorName); 268 } 269 | Popular Tags |