KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.commons.jxpath.ri.compiler.VariableReference;
23 import org.netbeans.modules.xml.xpath.AbstractXPathModelHelper;
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.XPathExpression;
28 import org.netbeans.modules.xml.xpath.XPathExpressionPath;
29 import org.netbeans.modules.xml.xpath.XPathExtensionFunction;
30 import org.netbeans.modules.xml.xpath.XPathLocationPath;
31 import org.netbeans.modules.xml.xpath.XPathModel;
32 import org.netbeans.modules.xml.xpath.XPathNumericLiteral;
33 import org.netbeans.modules.xml.xpath.XPathPredicateExpression;
34 import org.netbeans.modules.xml.xpath.XPathPredicateNumericLiteral;
35 import org.netbeans.modules.xml.xpath.XPathStringLiteral;
36 import org.netbeans.modules.xml.xpath.XPathVariableReference;
37 import org.netbeans.modules.xml.xpath.function.extension.GetContainerDataFunction;
38 import org.netbeans.modules.xml.xpath.function.extension.impl.GetContainerDataFunctionImpl;
39
40
41
42 /**
43  * XPathModel helper class.
44  *
45  * @author Enrico Lelina
46  * @version $Revision: 1.4 $
47  */

48 public class XPathModelHelperImpl extends AbstractXPathModelHelper {
49
50     /**
51      * Instantiates a new XPathModel object.
52      * @return a new XPathModel object instance
53      */

54     public XPathModel newXPathModel() {
55         return new XPathModelImpl();
56     }
57     
58     
59     /**
60      * Instantiates a new XPathStringLiteral object.
61      * @param value the value
62      * @return a new XPathStringLiteral object instance
63      */

64     public XPathStringLiteral newXPathStringLiteral(String JavaDoc value) {
65         return new XPathStringLiteralImpl(value);
66     }
67    
68     /**
69      * Instantiates a new XPathVariableReference object of the type variable.
70      * @param value the value
71      * @return a new XPathVariableReference object instance
72      */

73     public XPathVariableReference newXPathVariableReference(VariableReference vReference) {
74
75         return new XPathVariableReferenceImpl(vReference);
76     }
77
78     
79     /**
80      * Instantiates a new XPathPredicateExpression object for given expression.
81      * @param expression which is a predicate expression
82      * @return a new XPathPredicateExpression object instance
83      */

84     public XPathPredicateExpression newXPathPredicateExpression(XPathExpression expression) {
85         return new XPathPredicateExpressionImpl(expression);
86     }
87
88
89     /**
90      * Instantiates a new XPathNumericLiteral object.
91      * @param value the value
92      * @return a new XPathNumericLiteral object instance
93      */

94     public XPathNumericLiteral newXPathNumericLiteral(Number JavaDoc value) {
95         return new XPathNumericLiteralImpl(value);
96     }
97     
98    /**
99      * Instantiates a new XPathPredicateNumericLiteral object.
100      * @param value the value
101      * @return a new XPathPredicateNumericLiteral object instance
102      */

103     public XPathPredicateNumericLiteral newXPathPredicateNumericLiteral(Long JavaDoc value) {
104         return new XPathPredicateNumericLiteralImpl(value);
105     }
106         
107     /**
108      * Instantiates a new XPathCoreFunction object.
109      * @param function the function code
110      * @return a new XPathCoreFunction object instance
111      */

112     public XPathCoreFunction newXPathCoreFunction(int function) {
113         return new XPathCoreFunctionImpl(function);
114     }
115     
116     
117     /**
118      * Instantiates a new XPathExtension Function object.
119      * @param name the function name
120      * @return a new XPathExtensionFunction object instance
121      */

122     public XPathExtensionFunction newXPathExtensionFunction(
123                                                             String JavaDoc name) {
124         if(name != null && name.equals(GetContainerDataFunction.NAME)) {
125             return new GetContainerDataFunctionImpl(name);
126         } else {
127             return new XPathExtensionFunctionImpl(name);
128         }
129     }
130     
131     
132     /**
133      * Instantiates a new XPathCoreOperation object.
134      * @param code the operation code
135      * @return a new XPathCoreOperatoin object instance
136      */

137     public XPathCoreOperation newXPathCoreOperation(int code) {
138         return new XPathCoreOperationImpl(code);
139     }
140     
141     
142     /**
143      * Instantiates a new XPathLocationPath object.
144      * @param steps the steps
145      * @return a new XPathLocationPath object instance
146      */

147     public XPathLocationPath newXPathLocationPath(LocationStep[] steps) {
148         return new XPathLocationPathImpl(steps);
149     }
150
151     /**
152      * Instantiates a new XPathExpressionPath object.
153      * @param rootExpression root expression if any
154      * @param steps the steps
155      * @return a new XPathLocationPath object instance
156      */

157     public XPathExpressionPath newXPathExpressionPath(XPathExpression rootExpression,
158                                                            LocationStep[] steps) {
159         
160         return new XPathExpressionPathImpl(rootExpression, steps, false);
161     }
162     
163     /**
164      * Determines if a function name is valid. Assumes the function name is
165      * not one of the core functions.
166      * @param functionName the name of the function
167      * @return true if the function name is valid, false otherwise
168      */

169     public boolean isValidFunction(String JavaDoc functionName) {
170         return XPathModelImpl.isValidFunction(functionName);
171     }
172     
173     /**
174      * Determines if a operator name is valid. Assumes the operatior name is
175      * built in operator.
176      * @param operatorName the name of the function
177      * @return true if the operatorName name is valid, false otherwise
178      */

179     public boolean isValidOperator(String JavaDoc operatorName) {
180         if(opHash != null && opHash.keySet().contains(operatorName)) {
181             return true;
182         }
183         
184         return false;
185     }
186 }
187
Popular Tags