001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.jxpath.ri;
017:
018: /**
019: * The Compiler APIs are completely agnostic to the actual types of objects
020: * produced and consumed by the APIs. Arguments and return values are
021: * declared as java.lang.Object.
022: * <p>
023: * Since objects returned by Compiler methods are passed as arguments to other
024: * Compiler methods, the descriptions of these methods use virtual types. There
025: * are four virtual object types: EXPRESSION, QNAME, STEP and NODE_TEST.
026: * <p>
027: * The following example illustrates this notion. This sequence compiles
028: * the xpath "foo[round(1 div 2)]/text()":
029: * <blockquote><pre>
030: * Object qname1 = compiler.qname(null, "foo")
031: * Object expr1 = compiler.number("1");
032: * Object expr2 = compiler.number("2");
033: * Object expr3 = compiler.div(expr1, expr2);
034: * Object expr4 = compiler.
035: * coreFunction(Compiler.FUNCTION_ROUND, new Object[]{expr3});
036: * Object test1 = compiler.nodeNameTest(qname1);
037: * Object step1 = compiler.
038: * step(Compiler.AXIS_CHILD, test1, new Object[]{expr4});
039: * Object test2 = compiler.nodeTypeTest(Compiler.NODE_TYPE_TEXT);
040: * Object step2 = compiler.nodeTypeTest(Compiler.AXIS_CHILD, test2, null);
041: * Object expr5 = compiler.locationPath(false, new Object[]{step1, step2});
042: * </pre></blockquote>
043: *
044: * @author Dmitri Plotnikov
045: * @version $Revision: 1.9 $ $Date: 2004/02/29 14:17:45 $
046: */
047: public interface Compiler {
048:
049: public static final int NODE_TYPE_NODE = 1;
050: public static final int NODE_TYPE_TEXT = 2;
051: public static final int NODE_TYPE_COMMENT = 3;
052: public static final int NODE_TYPE_PI = 4;
053:
054: public static final int AXIS_SELF = 1;
055: public static final int AXIS_CHILD = 2;
056: public static final int AXIS_PARENT = 3;
057: public static final int AXIS_ANCESTOR = 4;
058: public static final int AXIS_ATTRIBUTE = 5;
059: public static final int AXIS_NAMESPACE = 6;
060: public static final int AXIS_PRECEDING = 7;
061: public static final int AXIS_FOLLOWING = 8;
062: public static final int AXIS_DESCENDANT = 9;
063: public static final int AXIS_ANCESTOR_OR_SELF = 10;
064: public static final int AXIS_FOLLOWING_SIBLING = 11;
065: public static final int AXIS_PRECEDING_SIBLING = 12;
066: public static final int AXIS_DESCENDANT_OR_SELF = 13;
067:
068: public static final int FUNCTION_LAST = 1;
069: public static final int FUNCTION_POSITION = 2;
070: public static final int FUNCTION_COUNT = 3;
071: public static final int FUNCTION_ID = 4;
072: public static final int FUNCTION_LOCAL_NAME = 5;
073: public static final int FUNCTION_NAMESPACE_URI = 6;
074: public static final int FUNCTION_NAME = 7;
075: public static final int FUNCTION_STRING = 8;
076: public static final int FUNCTION_CONCAT = 9;
077: public static final int FUNCTION_STARTS_WITH = 10;
078: public static final int FUNCTION_CONTAINS = 11;
079: public static final int FUNCTION_SUBSTRING_BEFORE = 12;
080: public static final int FUNCTION_SUBSTRING_AFTER = 13;
081: public static final int FUNCTION_SUBSTRING = 14;
082: public static final int FUNCTION_STRING_LENGTH = 15;
083: public static final int FUNCTION_NORMALIZE_SPACE = 16;
084: public static final int FUNCTION_TRANSLATE = 17;
085: public static final int FUNCTION_BOOLEAN = 18;
086: public static final int FUNCTION_NOT = 19;
087: public static final int FUNCTION_TRUE = 20;
088: public static final int FUNCTION_FALSE = 21;
089: public static final int FUNCTION_LANG = 22;
090: public static final int FUNCTION_NUMBER = 23;
091: public static final int FUNCTION_SUM = 24;
092: public static final int FUNCTION_FLOOR = 25;
093: public static final int FUNCTION_CEILING = 26;
094: public static final int FUNCTION_ROUND = 27;
095: public static final int FUNCTION_NULL = 28;
096: public static final int FUNCTION_KEY = 29;
097: public static final int FUNCTION_FORMAT_NUMBER = 30;
098:
099: /**
100: * Produces an EXPRESSION object that represents a numeric constant.
101: */
102: Object number(String value);
103:
104: /**
105: * Produces an EXPRESSION object that represents a string constant.
106: */
107: Object literal(String value);
108:
109: /**
110: * Produces an QNAME that represents a name with an optional prefix.
111: */
112: Object qname(String prefix, String name);
113:
114: /**
115: * Produces an EXPRESSION object representing the sum of all argumens
116: *
117: * @param arguments are EXPRESSION objects
118: */
119: Object sum(Object[] arguments);
120:
121: /**
122: * Produces an EXPRESSION object representing <i>left</i> minus <i>right</i>
123: *
124: * @param left is an EXPRESSION object
125: * @param right is an EXPRESSION object
126: */
127: Object minus(Object left, Object right);
128:
129: /**
130: * Produces an EXPRESSION object representing <i>left</i> multiplied by
131: * <i>right</i>
132: *
133: * @param left is an EXPRESSION object
134: * @param right is an EXPRESSION object
135: */
136: Object multiply(Object left, Object right);
137:
138: /**
139: * Produces an EXPRESSION object representing <i>left</i> divided by
140: * <i>right</i>
141: *
142: * @param left is an EXPRESSION object
143: * @param right is an EXPRESSION object
144: */
145: Object divide(Object left, Object right);
146:
147: /**
148: * Produces an EXPRESSION object representing <i>left</i> modulo
149: * <i>right</i>
150: *
151: * @param left is an EXPRESSION object
152: * @param right is an EXPRESSION object
153: */
154: Object mod(Object left, Object right);
155:
156: /**
157: * Produces an EXPRESSION object representing the comparison:
158: * <i>left</i> less than <i>right</i>
159: *
160: * @param left is an EXPRESSION object
161: * @param right is an EXPRESSION object
162: */
163: Object lessThan(Object left, Object right);
164:
165: /**
166: * Produces an EXPRESSION object representing the comparison:
167: * <i>left</i> less than or equal to <i>right</i>
168: *
169: * @param left is an EXPRESSION object
170: * @param right is an EXPRESSION object
171: */
172: Object lessThanOrEqual(Object left, Object right);
173:
174: /**
175: * Produces an EXPRESSION object representing the comparison:
176: * <i>left</i> greater than <i>right</i>
177: *
178: * @param left is an EXPRESSION object
179: * @param right is an EXPRESSION object
180: */
181: Object greaterThan(Object left, Object right);
182:
183: /**
184: * Produces an EXPRESSION object representing the comparison:
185: * <i>left</i> greater than or equal to <i>right</i>
186: *
187: * @param left is an EXPRESSION object
188: * @param right is an EXPRESSION object
189: */
190: Object greaterThanOrEqual(Object left, Object right);
191:
192: /**
193: * Produces an EXPRESSION object representing the comparison:
194: * <i>left</i> equals to <i>right</i>
195: *
196: * @param left is an EXPRESSION object
197: * @param right is an EXPRESSION object
198: */
199: Object equal(Object left, Object right);
200:
201: /**
202: * Produces an EXPRESSION object representing the comparison:
203: * <i>left</i> is not equal to <i>right</i>
204: *
205: * @param left is an EXPRESSION object
206: * @param right is an EXPRESSION object
207: */
208: Object notEqual(Object left, Object right);
209:
210: /**
211: * Produces an EXPRESSION object representing unary negation of the argument
212: *
213: * @param argument is an EXPRESSION object
214: */
215: Object minus(Object argument);
216:
217: /**
218: * Produces an EXPRESSION object representing variable reference
219: *
220: * @param qname is a QNAME object
221: */
222: Object variableReference(Object qName);
223:
224: /**
225: * Produces an EXPRESSION object representing the computation of
226: * a core function with the supplied arguments.
227: *
228: * @param code is one of FUNCTION_... constants
229: * @param args are EXPRESSION objects
230: */
231: Object function(int code, Object[] args);
232:
233: /**
234: * Produces an EXPRESSION object representing the computation of
235: * a library function with the supplied arguments.
236: *
237: * @param name is a QNAME object (function name)
238: * @param args are EXPRESSION objects
239: */
240: Object function(Object name, Object[] args);
241:
242: /**
243: * Produces an EXPRESSION object representing logical conjunction of
244: * all arguments
245: *
246: * @param arguments are EXPRESSION objects
247: */
248: Object and(Object arguments[]);
249:
250: /**
251: * Produces an EXPRESSION object representing logical disjunction of
252: * all arguments
253: *
254: * @param arguments are EXPRESSION objects
255: */
256: Object or(Object arguments[]);
257:
258: /**
259: * Produces an EXPRESSION object representing union of all node sets
260: *
261: * @param arguments are EXPRESSION objects
262: */
263: Object union(Object[] arguments);
264:
265: /**
266: * Produces a NODE_TEST object that represents a node name test.
267: *
268: * @param qname is a QNAME object
269: */
270: Object nodeNameTest(Object qname);
271:
272: /**
273: * Produces a NODE_TEST object that represents a node type test.
274: *
275: * @param qname is a QNAME object
276: */
277: Object nodeTypeTest(int nodeType);
278:
279: /**
280: * Produces a NODE_TEST object that represents a processing instruction
281: * test.
282: *
283: * @param qname is a QNAME object
284: */
285: Object processingInstructionTest(String instruction);
286:
287: /**
288: * Produces a STEP object that represents a node test.
289: *
290: * @param axis is one of the AXIS_... constants
291: * @param nodeTest is a NODE_TEST object
292: * @param predicates are EXPRESSION objects
293: */
294: Object step(int axis, Object nodeTest, Object[] predicates);
295:
296: /**
297: * Produces an EXPRESSION object representing a location path
298: *
299: * @param absolute indicates whether the path is absolute
300: * @param steps are STEP objects
301: */
302: Object locationPath(boolean absolute, Object[] steps);
303:
304: /**
305: * Produces an EXPRESSION object representing a filter expression
306: *
307: * @param expression is an EXPRESSION object
308: * @param predicates are EXPRESSION objects
309: * @param steps are STEP objects
310: */
311: Object expressionPath(Object expression, Object[] predicates,
312: Object[] steps);
313: }
|