KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xpath > impl > XPathModelHelper


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.xpath.impl;
21
22 import java.util.HashMap JavaDoc;
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 /**
36  * XPathModel helper class.
37  *
38  * @author Enrico Lelina
39  * @version $Revision: 1.4 $
40  * @deprecated Replaced by {@link #org.netbeans.modules.xml.xpath.AbstractXPathModelHelper}
41  */

42 public abstract class XPathModelHelper {
43
44     /**
45      * Describe variable <code>opHash</code> here.
46      *
47      */

48     private static HashMap JavaDoc opHash = new HashMap JavaDoc();
49     /**
50      * Describe variable <code>funcHash</code> here.
51      *
52      */

53     private static HashMap JavaDoc funcHash = new HashMap JavaDoc();
54
55     static {
56         opHash.put("+", new Integer JavaDoc(XPathCoreOperation.OP_SUM));
57         opHash.put("-", new Integer JavaDoc(XPathCoreOperation.OP_MINUS));
58         opHash.put("*", new Integer JavaDoc(XPathCoreOperation.OP_MULT));
59         opHash.put("div", new Integer JavaDoc(XPathCoreOperation.OP_DIV));
60         opHash.put("mod", new Integer JavaDoc(XPathCoreOperation.OP_MOD));
61         // **FIX* opHash.put("", new Integer(XPathCoreOperation.OP_NEGATIVE));
62
opHash.put("negative", new Integer JavaDoc(XPathCoreOperation.OP_NEGATIVE));
63         opHash.put("and", new Integer JavaDoc(XPathCoreOperation.OP_AND));
64         opHash.put("or", new Integer JavaDoc(XPathCoreOperation.OP_OR));
65         opHash.put("==", new Integer JavaDoc(XPathCoreOperation.OP_EQ));
66         opHash.put("!=", new Integer JavaDoc(XPathCoreOperation.OP_NE));
67         opHash.put("&lt;", new Integer JavaDoc(XPathCoreOperation.OP_LT));
68         opHash.put("<", new Integer JavaDoc(XPathCoreOperation.OP_LT));
69         opHash.put("&lt;=", new Integer JavaDoc(XPathCoreOperation.OP_LE));
70         opHash.put("<=", new Integer JavaDoc(XPathCoreOperation.OP_LE));
71         opHash.put("&gt;", new Integer JavaDoc(XPathCoreOperation.OP_GT));
72         opHash.put(">", new Integer JavaDoc(XPathCoreOperation.OP_GT));
73         opHash.put("&gt;=", new Integer JavaDoc(XPathCoreOperation.OP_GE));
74         opHash.put(">=", new Integer JavaDoc(XPathCoreOperation.OP_GE));
75     }
76     
77
78     static {
79
80         funcHash.put("concat", new Integer JavaDoc(XPathCoreFunction.FUNC_CONCAT));
81         funcHash.put("last", new Integer JavaDoc(XPathCoreFunction.FUNC_LAST));
82         funcHash.put("position", new Integer JavaDoc(XPathCoreFunction.FUNC_POSITION));
83         funcHash.put("count", new Integer JavaDoc(XPathCoreFunction.FUNC_COUNT));
84         funcHash.put("id", new Integer JavaDoc(XPathCoreFunction.FUNC_ID));
85         funcHash.put("local-name", new Integer JavaDoc(XPathCoreFunction.FUNC_LOCAL_NAME));
86         funcHash.put("namespace-uri", new Integer JavaDoc(XPathCoreFunction.FUNC_NAMESPACE_URI));
87         funcHash.put("name", new Integer JavaDoc(XPathCoreFunction.FUNC_NAME));
88         funcHash.put("string", new Integer JavaDoc(XPathCoreFunction.FUNC_STRING));
89         funcHash.put("starts-with", new Integer JavaDoc(XPathCoreFunction.FUNC_STARTS_WITH));
90         funcHash.put("contains", new Integer JavaDoc(XPathCoreFunction.FUNC_CONTAINS));
91         funcHash.put("substring-before", new Integer JavaDoc(XPathCoreFunction.FUNC_SUBSTRING_BEFORE));
92         funcHash.put("substring-after", new Integer JavaDoc(XPathCoreFunction.FUNC_SUBSTRING_AFTER));
93         funcHash.put("substring", new Integer JavaDoc(XPathCoreFunction.FUNC_SUBSTRING));
94         funcHash.put("string-length", new Integer JavaDoc(XPathCoreFunction.FUNC_STRING_LENGTH));
95         funcHash.put("normalize-space", new Integer JavaDoc(XPathCoreFunction.FUNC_NORMALIZE_SPACE));
96         funcHash.put("translate", new Integer JavaDoc(XPathCoreFunction.FUNC_TRANSLATE));
97         funcHash.put("boolean", new Integer JavaDoc(XPathCoreFunction.FUNC_BOOLEAN));
98         funcHash.put("not", new Integer JavaDoc(XPathCoreFunction.FUNC_NOT));
99         funcHash.put("true", new Integer JavaDoc(XPathCoreFunction.FUNC_TRUE));
100         funcHash.put("false", new Integer JavaDoc(XPathCoreFunction.FUNC_FALSE));
101         funcHash.put("lang", new Integer JavaDoc(XPathCoreFunction.FUNC_LANG));
102         funcHash.put("number", new Integer JavaDoc(XPathCoreFunction.FUNC_NUMBER));
103         funcHash.put("sum", new Integer JavaDoc(XPathCoreFunction.FUNC_SUM));
104         funcHash.put("floor", new Integer JavaDoc(XPathCoreFunction.FUNC_FLOOR));
105         funcHash.put("ceiling", new Integer JavaDoc(XPathCoreFunction.FUNC_CEILING));
106         funcHash.put("round", new Integer JavaDoc(XPathCoreFunction.FUNC_ROUND));
107         funcHash.put("null", new Integer JavaDoc(XPathCoreFunction.FUNC_NULL));
108         funcHash.put("key", new Integer JavaDoc(XPathCoreFunction.FUNC_KEY));
109     }
110
111
112     /**
113      * Instantiates a new XPathModel object.
114      * @return a new XPathModel object instance
115      */

116     public static XPathModel newXPathModel() {
117         return new XPathModelImpl();
118     }
119     
120     
121     /**
122      * Instantiates a new XPathStringLiteral object.
123      * @param value the value
124      * @return a new XPathStringLiteral object instance
125      */

126     public static XPathStringLiteral newXPathStringLiteral(String JavaDoc value) {
127         return new XPathStringLiteralImpl(value);
128     }
129     
130     
131     /**
132      * Instantiates a new XPathNumericLiteral object.
133      * @param value the value
134      * @return a new XPathNumericLiteral object instance
135      */

136     public static XPathNumericLiteral newXPathNumericLiteral(Number JavaDoc value) {
137         return new XPathNumericLiteralImpl(value);
138     }
139     
140     
141     /**
142      * Instantiates a new XPathCoreFunction object.
143      * @param function the function code
144      * @return a new XPathCoreFunction object instance
145      */

146     public static XPathCoreFunction newXPathCoreFunction(int function) {
147         return new XPathCoreFunctionImpl(function);
148     }
149     
150     
151     /**
152      * Instantiates a new XPathExtension Function object.
153      * @param name the function name
154      * @return a new XPathExtensionFunction object instance
155      */

156     public static XPathExtensionFunction newXPathExtensionFunction(
157                                                             String JavaDoc name) {
158         return new XPathExtensionFunctionImpl(name);
159     }
160     
161     
162     /**
163      * Instantiates a new XPathCoreOperation object.
164      * @param code the operation code
165      * @return a new XPathCoreOperatoin object instance
166      */

167     public static XPathCoreOperation newXPathCoreOperation(int code) {
168         return new XPathCoreOperationImpl(code);
169     }
170     
171     
172     /**
173      * Instantiates a new XPathLocationPath object.
174      * @param steps the steps
175      * @return a new XPathLocationPath object instance
176      */

177     public static XPathLocationPath newXPathLocationPath(LocationStep[] steps) {
178         return new XPathLocationPathImpl(steps);
179     }
180
181     /**
182      * gives the type of the core operation given the operator string
183      * @param operator String
184      * @return int (type)
185      */

186     public static Integer JavaDoc getOperatorType(String JavaDoc operator) {
187         
188         return (Integer JavaDoc) opHash.get(operator);
189     }
190
191     /**
192      * gives the type of the function given the function
193      * @param function String
194      * @return int (type)
195      */

196     public static Integer JavaDoc getFunctionType(String JavaDoc function) {
197         
198         return (Integer JavaDoc) funcHash.get(function);
199     }
200
201     /**
202      * Determines if a function name is valid. Assumes the function name is
203      * not one of the core functions.
204      * @param functionName the name of the function
205      * @return true if the function name is valid, false otherwise
206      */

207     public static boolean isValidFunction(String JavaDoc functionName) {
208         return XPathModelImpl.isValidFunction(functionName);
209     }
210 }
211
Popular Tags