001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.xpath.impl;
043:
044: import java.util.HashMap;
045:
046: import org.netbeans.modules.xml.xpath.LocationStep;
047: import org.netbeans.modules.xml.xpath.XPathCoreFunction;
048: import org.netbeans.modules.xml.xpath.XPathCoreOperation;
049: import org.netbeans.modules.xml.xpath.XPathExtensionFunction;
050: import org.netbeans.modules.xml.xpath.XPathLocationPath;
051: import org.netbeans.modules.xml.xpath.XPathModel;
052: import org.netbeans.modules.xml.xpath.XPathNumericLiteral;
053: import org.netbeans.modules.xml.xpath.XPathStringLiteral;
054:
055: /**
056: * XPathModel helper class.
057: *
058: * @author Enrico Lelina
059: * @version
060: * @deprecated Replaced by {@link #org.netbeans.modules.xml.xpath.AbstractXPathModelHelper}
061: */
062: public abstract class XPathModelHelper {
063:
064: /**
065: * Describe variable <code>opHash</code> here.
066: *
067: */
068: private static HashMap opHash = new HashMap();
069: /**
070: * Describe variable <code>funcHash</code> here.
071: *
072: */
073: private static HashMap funcHash = new HashMap();
074:
075: static {
076: opHash.put("+", new Integer(XPathCoreOperation.OP_SUM));
077: opHash.put("-", new Integer(XPathCoreOperation.OP_MINUS));
078: opHash.put("*", new Integer(XPathCoreOperation.OP_MULT));
079: opHash.put("div", new Integer(XPathCoreOperation.OP_DIV));
080: opHash.put("mod", new Integer(XPathCoreOperation.OP_MOD));
081: // **FIX* opHash.put("", new Integer(XPathCoreOperation.OP_NEGATIVE));
082: opHash.put("negative", new Integer(
083: XPathCoreOperation.OP_NEGATIVE));
084: opHash.put("and", new Integer(XPathCoreOperation.OP_AND));
085: opHash.put("or", new Integer(XPathCoreOperation.OP_OR));
086: opHash.put("==", new Integer(XPathCoreOperation.OP_EQ));
087: opHash.put("!=", new Integer(XPathCoreOperation.OP_NE));
088: opHash.put("<", new Integer(XPathCoreOperation.OP_LT));
089: opHash.put("<", new Integer(XPathCoreOperation.OP_LT));
090: opHash.put("<=", new Integer(XPathCoreOperation.OP_LE));
091: opHash.put("<=", new Integer(XPathCoreOperation.OP_LE));
092: opHash.put(">", new Integer(XPathCoreOperation.OP_GT));
093: opHash.put(">", new Integer(XPathCoreOperation.OP_GT));
094: opHash.put(">=", new Integer(XPathCoreOperation.OP_GE));
095: opHash.put(">=", new Integer(XPathCoreOperation.OP_GE));
096: }
097:
098: static {
099:
100: funcHash.put("concat", new Integer(
101: XPathCoreFunction.FUNC_CONCAT));
102: funcHash.put("last", new Integer(XPathCoreFunction.FUNC_LAST));
103: funcHash.put("position", new Integer(
104: XPathCoreFunction.FUNC_POSITION));
105: funcHash
106: .put("count", new Integer(XPathCoreFunction.FUNC_COUNT));
107: funcHash.put("id", new Integer(XPathCoreFunction.FUNC_ID));
108: funcHash.put("local-name", new Integer(
109: XPathCoreFunction.FUNC_LOCAL_NAME));
110: funcHash.put("namespace-uri", new Integer(
111: XPathCoreFunction.FUNC_NAMESPACE_URI));
112: funcHash.put("name", new Integer(XPathCoreFunction.FUNC_NAME));
113: funcHash.put("string", new Integer(
114: XPathCoreFunction.FUNC_STRING));
115: funcHash.put("starts-with", new Integer(
116: XPathCoreFunction.FUNC_STARTS_WITH));
117: funcHash.put("contains", new Integer(
118: XPathCoreFunction.FUNC_CONTAINS));
119: funcHash.put("substring-before", new Integer(
120: XPathCoreFunction.FUNC_SUBSTRING_BEFORE));
121: funcHash.put("substring-after", new Integer(
122: XPathCoreFunction.FUNC_SUBSTRING_AFTER));
123: funcHash.put("substring", new Integer(
124: XPathCoreFunction.FUNC_SUBSTRING));
125: funcHash.put("string-length", new Integer(
126: XPathCoreFunction.FUNC_STRING_LENGTH));
127: funcHash.put("normalize-space", new Integer(
128: XPathCoreFunction.FUNC_NORMALIZE_SPACE));
129: funcHash.put("translate", new Integer(
130: XPathCoreFunction.FUNC_TRANSLATE));
131: funcHash.put("boolean", new Integer(
132: XPathCoreFunction.FUNC_BOOLEAN));
133: funcHash.put("not", new Integer(XPathCoreFunction.FUNC_NOT));
134: funcHash.put("true", new Integer(XPathCoreFunction.FUNC_TRUE));
135: funcHash
136: .put("false", new Integer(XPathCoreFunction.FUNC_FALSE));
137: funcHash.put("lang", new Integer(XPathCoreFunction.FUNC_LANG));
138: funcHash.put("number", new Integer(
139: XPathCoreFunction.FUNC_NUMBER));
140: funcHash.put("sum", new Integer(XPathCoreFunction.FUNC_SUM));
141: funcHash
142: .put("floor", new Integer(XPathCoreFunction.FUNC_FLOOR));
143: funcHash.put("ceiling", new Integer(
144: XPathCoreFunction.FUNC_CEILING));
145: funcHash
146: .put("round", new Integer(XPathCoreFunction.FUNC_ROUND));
147: funcHash.put("null", new Integer(XPathCoreFunction.FUNC_NULL));
148: funcHash.put("key", new Integer(XPathCoreFunction.FUNC_KEY));
149: }
150:
151: /**
152: * Instantiates a new XPathModel object.
153: * @return a new XPathModel object instance
154: */
155: public static XPathModel newXPathModel() {
156: return new XPathModelImpl();
157: }
158:
159: /**
160: * Instantiates a new XPathStringLiteral object.
161: * @param value the value
162: * @return a new XPathStringLiteral object instance
163: */
164: public static XPathStringLiteral newXPathStringLiteral(String value) {
165: return new XPathStringLiteralImpl(value);
166: }
167:
168: /**
169: * Instantiates a new XPathNumericLiteral object.
170: * @param value the value
171: * @return a new XPathNumericLiteral object instance
172: */
173: public static XPathNumericLiteral newXPathNumericLiteral(
174: Number value) {
175: return new XPathNumericLiteralImpl(value);
176: }
177:
178: /**
179: * Instantiates a new XPathCoreFunction object.
180: * @param function the function code
181: * @return a new XPathCoreFunction object instance
182: */
183: public static XPathCoreFunction newXPathCoreFunction(int function) {
184: return new XPathCoreFunctionImpl(function);
185: }
186:
187: /**
188: * Instantiates a new XPathExtension Function object.
189: * @param name the function name
190: * @return a new XPathExtensionFunction object instance
191: */
192: public static XPathExtensionFunction newXPathExtensionFunction(
193: String name) {
194: return new XPathExtensionFunctionImpl(name);
195: }
196:
197: /**
198: * Instantiates a new XPathCoreOperation object.
199: * @param code the operation code
200: * @return a new XPathCoreOperatoin object instance
201: */
202: public static XPathCoreOperation newXPathCoreOperation(int code) {
203: return new XPathCoreOperationImpl(code);
204: }
205:
206: /**
207: * Instantiates a new XPathLocationPath object.
208: * @param steps the steps
209: * @return a new XPathLocationPath object instance
210: */
211: public static XPathLocationPath newXPathLocationPath(
212: LocationStep[] steps) {
213: return new XPathLocationPathImpl(steps);
214: }
215:
216: /**
217: * gives the type of the core operation given the operator string
218: * @param operator String
219: * @return int (type)
220: */
221: public static Integer getOperatorType(String operator) {
222:
223: return (Integer) opHash.get(operator);
224: }
225:
226: /**
227: * gives the type of the function given the function
228: * @param function String
229: * @return int (type)
230: */
231: public static Integer getFunctionType(String function) {
232:
233: return (Integer) funcHash.get(function);
234: }
235:
236: /**
237: * Determines if a function name is valid. Assumes the function name is
238: * not one of the core functions.
239: * @param functionName the name of the function
240: * @return true if the function name is valid, false otherwise
241: */
242: public static boolean isValidFunction(String functionName) {
243: return XPathModelImpl.isValidFunction(functionName);
244: }
245: }
|