1 19 20 package org.netbeans.modules.xml.xpath.impl; 21 22 import java.util.HashMap ; 23 24 import org.netbeans.modules.xml.xpath.LocationStep; 25 import org.netbeans.modules.xml.xpath.XPathCoreFunction; 26 import org.netbeans.modules.xml.xpath.XPathCoreOperation; 27 import org.netbeans.modules.xml.xpath.XPathExtensionFunction; 28 import org.netbeans.modules.xml.xpath.XPathLocationPath; 29 import org.netbeans.modules.xml.xpath.XPathModel; 30 import org.netbeans.modules.xml.xpath.XPathNumericLiteral; 31 import org.netbeans.modules.xml.xpath.XPathStringLiteral; 32 33 34 35 42 public abstract class XPathModelHelper { 43 44 48 private static HashMap opHash = new HashMap (); 49 53 private static HashMap funcHash = new HashMap (); 54 55 static { 56 opHash.put("+", new Integer (XPathCoreOperation.OP_SUM)); 57 opHash.put("-", new Integer (XPathCoreOperation.OP_MINUS)); 58 opHash.put("*", new Integer (XPathCoreOperation.OP_MULT)); 59 opHash.put("div", new Integer (XPathCoreOperation.OP_DIV)); 60 opHash.put("mod", new Integer (XPathCoreOperation.OP_MOD)); 61 opHash.put("negative", new Integer (XPathCoreOperation.OP_NEGATIVE)); 63 opHash.put("and", new Integer (XPathCoreOperation.OP_AND)); 64 opHash.put("or", new Integer (XPathCoreOperation.OP_OR)); 65 opHash.put("==", new Integer (XPathCoreOperation.OP_EQ)); 66 opHash.put("!=", new Integer (XPathCoreOperation.OP_NE)); 67 opHash.put("<", new Integer (XPathCoreOperation.OP_LT)); 68 opHash.put("<", new Integer (XPathCoreOperation.OP_LT)); 69 opHash.put("<=", new Integer (XPathCoreOperation.OP_LE)); 70 opHash.put("<=", new Integer (XPathCoreOperation.OP_LE)); 71 opHash.put(">", new Integer (XPathCoreOperation.OP_GT)); 72 opHash.put(">", new Integer (XPathCoreOperation.OP_GT)); 73 opHash.put(">=", new Integer (XPathCoreOperation.OP_GE)); 74 opHash.put(">=", new Integer (XPathCoreOperation.OP_GE)); 75 } 76 77 78 static { 79 80 funcHash.put("concat", new Integer (XPathCoreFunction.FUNC_CONCAT)); 81 funcHash.put("last", new Integer (XPathCoreFunction.FUNC_LAST)); 82 funcHash.put("position", new Integer (XPathCoreFunction.FUNC_POSITION)); 83 funcHash.put("count", new Integer (XPathCoreFunction.FUNC_COUNT)); 84 funcHash.put("id", new Integer (XPathCoreFunction.FUNC_ID)); 85 funcHash.put("local-name", new Integer (XPathCoreFunction.FUNC_LOCAL_NAME)); 86 funcHash.put("namespace-uri", new Integer (XPathCoreFunction.FUNC_NAMESPACE_URI)); 87 funcHash.put("name", new Integer (XPathCoreFunction.FUNC_NAME)); 88 funcHash.put("string", new Integer (XPathCoreFunction.FUNC_STRING)); 89 funcHash.put("starts-with", new Integer (XPathCoreFunction.FUNC_STARTS_WITH)); 90 funcHash.put("contains", new Integer (XPathCoreFunction.FUNC_CONTAINS)); 91 funcHash.put("substring-before", new Integer (XPathCoreFunction.FUNC_SUBSTRING_BEFORE)); 92 funcHash.put("substring-after", new Integer (XPathCoreFunction.FUNC_SUBSTRING_AFTER)); 93 funcHash.put("substring", new Integer (XPathCoreFunction.FUNC_SUBSTRING)); 94 funcHash.put("string-length", new Integer (XPathCoreFunction.FUNC_STRING_LENGTH)); 95 funcHash.put("normalize-space", new Integer (XPathCoreFunction.FUNC_NORMALIZE_SPACE)); 96 funcHash.put("translate", new Integer (XPathCoreFunction.FUNC_TRANSLATE)); 97 funcHash.put("boolean", new Integer (XPathCoreFunction.FUNC_BOOLEAN)); 98 funcHash.put("not", new Integer (XPathCoreFunction.FUNC_NOT)); 99 funcHash.put("true", new Integer (XPathCoreFunction.FUNC_TRUE)); 100 funcHash.put("false", new Integer (XPathCoreFunction.FUNC_FALSE)); 101 funcHash.put("lang", new Integer (XPathCoreFunction.FUNC_LANG)); 102 funcHash.put("number", new Integer (XPathCoreFunction.FUNC_NUMBER)); 103 funcHash.put("sum", new Integer (XPathCoreFunction.FUNC_SUM)); 104 funcHash.put("floor", new Integer (XPathCoreFunction.FUNC_FLOOR)); 105 funcHash.put("ceiling", new Integer (XPathCoreFunction.FUNC_CEILING)); 106 funcHash.put("round", new Integer (XPathCoreFunction.FUNC_ROUND)); 107 funcHash.put("null", new Integer (XPathCoreFunction.FUNC_NULL)); 108 funcHash.put("key", new Integer (XPathCoreFunction.FUNC_KEY)); 109 } 110 111 112 116 public static XPathModel newXPathModel() { 117 return new XPathModelImpl(); 118 } 119 120 121 126 public static XPathStringLiteral newXPathStringLiteral(String value) { 127 return new XPathStringLiteralImpl(value); 128 } 129 130 131 136 public static XPathNumericLiteral newXPathNumericLiteral(Number value) { 137 return new XPathNumericLiteralImpl(value); 138 } 139 140 141 146 public static XPathCoreFunction newXPathCoreFunction(int function) { 147 return new XPathCoreFunctionImpl(function); 148 } 149 150 151 156 public static XPathExtensionFunction newXPathExtensionFunction( 157 String name) { 158 return new XPathExtensionFunctionImpl(name); 159 } 160 161 162 167 public static XPathCoreOperation newXPathCoreOperation(int code) { 168 return new XPathCoreOperationImpl(code); 169 } 170 171 172 177 public static XPathLocationPath newXPathLocationPath(LocationStep[] steps) { 178 return new XPathLocationPathImpl(steps); 179 } 180 181 186 public static Integer getOperatorType(String operator) { 187 188 return (Integer ) opHash.get(operator); 189 } 190 191 196 public static Integer getFunctionType(String function) { 197 198 return (Integer ) funcHash.get(function); 199 } 200 201 207 public static boolean isValidFunction(String functionName) { 208 return XPathModelImpl.isValidFunction(functionName); 209 } 210 } 211 | Popular Tags |