1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.jxpath.ri;
  17. /**
  18. * The Compiler APIs are completely agnostic to the actual types of objects
  19. * produced and consumed by the APIs. Arguments and return values are
  20. * declared as java.lang.Object.
  21. * <p>
  22. * Since objects returned by Compiler methods are passed as arguments to other
  23. * Compiler methods, the descriptions of these methods use virtual types. There
  24. * are four virtual object types: EXPRESSION, QNAME, STEP and NODE_TEST.
  25. * <p>
  26. * The following example illustrates this notion. This sequence compiles
  27. * the xpath "foo[round(1 div 2)]/text()":
  28. * <blockquote><pre>
  29. * Object qname1 = compiler.qname(null, "foo")
  30. * Object expr1 = compiler.number("1");
  31. * Object expr2 = compiler.number("2");
  32. * Object expr3 = compiler.div(expr1, expr2);
  33. * Object expr4 = compiler.
  34. * coreFunction(Compiler.FUNCTION_ROUND, new Object[]{expr3});
  35. * Object test1 = compiler.nodeNameTest(qname1);
  36. * Object step1 = compiler.
  37. * step(Compiler.AXIS_CHILD, test1, new Object[]{expr4});
  38. * Object test2 = compiler.nodeTypeTest(Compiler.NODE_TYPE_TEXT);
  39. * Object step2 = compiler.nodeTypeTest(Compiler.AXIS_CHILD, test2, null);
  40. * Object expr5 = compiler.locationPath(false, new Object[]{step1, step2});
  41. * </pre></blockquote>
  42. *
  43. * @author Dmitri Plotnikov
  44. * @version $Revision: 1.9 $ $Date: 2004/02/29 14:17:45 $
  45. */
  46. public interface Compiler {
  47. public static final int NODE_TYPE_NODE = 1;
  48. public static final int NODE_TYPE_TEXT = 2;
  49. public static final int NODE_TYPE_COMMENT = 3;
  50. public static final int NODE_TYPE_PI = 4;
  51. public static final int AXIS_SELF = 1;
  52. public static final int AXIS_CHILD = 2;
  53. public static final int AXIS_PARENT = 3;
  54. public static final int AXIS_ANCESTOR = 4;
  55. public static final int AXIS_ATTRIBUTE = 5;
  56. public static final int AXIS_NAMESPACE = 6;
  57. public static final int AXIS_PRECEDING = 7;
  58. public static final int AXIS_FOLLOWING = 8;
  59. public static final int AXIS_DESCENDANT = 9;
  60. public static final int AXIS_ANCESTOR_OR_SELF = 10;
  61. public static final int AXIS_FOLLOWING_SIBLING = 11;
  62. public static final int AXIS_PRECEDING_SIBLING = 12;
  63. public static final int AXIS_DESCENDANT_OR_SELF = 13;
  64. public static final int FUNCTION_LAST = 1;
  65. public static final int FUNCTION_POSITION = 2;
  66. public static final int FUNCTION_COUNT = 3;
  67. public static final int FUNCTION_ID = 4;
  68. public static final int FUNCTION_LOCAL_NAME = 5;
  69. public static final int FUNCTION_NAMESPACE_URI = 6;
  70. public static final int FUNCTION_NAME = 7;
  71. public static final int FUNCTION_STRING = 8;
  72. public static final int FUNCTION_CONCAT = 9;
  73. public static final int FUNCTION_STARTS_WITH = 10;
  74. public static final int FUNCTION_CONTAINS = 11;
  75. public static final int FUNCTION_SUBSTRING_BEFORE = 12;
  76. public static final int FUNCTION_SUBSTRING_AFTER = 13;
  77. public static final int FUNCTION_SUBSTRING = 14;
  78. public static final int FUNCTION_STRING_LENGTH = 15;
  79. public static final int FUNCTION_NORMALIZE_SPACE = 16;
  80. public static final int FUNCTION_TRANSLATE = 17;
  81. public static final int FUNCTION_BOOLEAN = 18;
  82. public static final int FUNCTION_NOT = 19;
  83. public static final int FUNCTION_TRUE = 20;
  84. public static final int FUNCTION_FALSE = 21;
  85. public static final int FUNCTION_LANG = 22;
  86. public static final int FUNCTION_NUMBER = 23;
  87. public static final int FUNCTION_SUM = 24;
  88. public static final int FUNCTION_FLOOR = 25;
  89. public static final int FUNCTION_CEILING = 26;
  90. public static final int FUNCTION_ROUND = 27;
  91. public static final int FUNCTION_NULL = 28;
  92. public static final int FUNCTION_KEY = 29;
  93. public static final int FUNCTION_FORMAT_NUMBER = 30;
  94. /**
  95. * Produces an EXPRESSION object that represents a numeric constant.
  96. */
  97. Object number(String value);
  98. /**
  99. * Produces an EXPRESSION object that represents a string constant.
  100. */
  101. Object literal(String value);
  102. /**
  103. * Produces an QNAME that represents a name with an optional prefix.
  104. */
  105. Object qname(String prefix, String name);
  106. /**
  107. * Produces an EXPRESSION object representing the sum of all argumens
  108. *
  109. * @param arguments are EXPRESSION objects
  110. */
  111. Object sum(Object[] arguments);
  112. /**
  113. * Produces an EXPRESSION object representing <i>left</i> minus <i>right</i>
  114. *
  115. * @param left is an EXPRESSION object
  116. * @param right is an EXPRESSION object
  117. */
  118. Object minus(Object left, Object right);
  119. /**
  120. * Produces an EXPRESSION object representing <i>left</i> multiplied by
  121. * <i>right</i>
  122. *
  123. * @param left is an EXPRESSION object
  124. * @param right is an EXPRESSION object
  125. */
  126. Object multiply(Object left, Object right);
  127. /**
  128. * Produces an EXPRESSION object representing <i>left</i> divided by
  129. * <i>right</i>
  130. *
  131. * @param left is an EXPRESSION object
  132. * @param right is an EXPRESSION object
  133. */
  134. Object divide(Object left, Object right);
  135. /**
  136. * Produces an EXPRESSION object representing <i>left</i> modulo
  137. * <i>right</i>
  138. *
  139. * @param left is an EXPRESSION object
  140. * @param right is an EXPRESSION object
  141. */
  142. Object mod(Object left, Object right);
  143. /**
  144. * Produces an EXPRESSION object representing the comparison:
  145. * <i>left</i> less than <i>right</i>
  146. *
  147. * @param left is an EXPRESSION object
  148. * @param right is an EXPRESSION object
  149. */
  150. Object lessThan(Object left, Object right);
  151. /**
  152. * Produces an EXPRESSION object representing the comparison:
  153. * <i>left</i> less than or equal to <i>right</i>
  154. *
  155. * @param left is an EXPRESSION object
  156. * @param right is an EXPRESSION object
  157. */
  158. Object lessThanOrEqual(Object left, Object right);
  159. /**
  160. * Produces an EXPRESSION object representing the comparison:
  161. * <i>left</i> greater than <i>right</i>
  162. *
  163. * @param left is an EXPRESSION object
  164. * @param right is an EXPRESSION object
  165. */
  166. Object greaterThan(Object left, Object right);
  167. /**
  168. * Produces an EXPRESSION object representing the comparison:
  169. * <i>left</i> greater than or equal to <i>right</i>
  170. *
  171. * @param left is an EXPRESSION object
  172. * @param right is an EXPRESSION object
  173. */
  174. Object greaterThanOrEqual(Object left, Object right);
  175. /**
  176. * Produces an EXPRESSION object representing the comparison:
  177. * <i>left</i> equals to <i>right</i>
  178. *
  179. * @param left is an EXPRESSION object
  180. * @param right is an EXPRESSION object
  181. */
  182. Object equal(Object left, Object right);
  183. /**
  184. * Produces an EXPRESSION object representing the comparison:
  185. * <i>left</i> is not equal to <i>right</i>
  186. *
  187. * @param left is an EXPRESSION object
  188. * @param right is an EXPRESSION object
  189. */
  190. Object notEqual(Object left, Object right);
  191. /**
  192. * Produces an EXPRESSION object representing unary negation of the argument
  193. *
  194. * @param argument is an EXPRESSION object
  195. */
  196. Object minus(Object argument);
  197. /**
  198. * Produces an EXPRESSION object representing variable reference
  199. *
  200. * @param qname is a QNAME object
  201. */
  202. Object variableReference(Object qName);
  203. /**
  204. * Produces an EXPRESSION object representing the computation of
  205. * a core function with the supplied arguments.
  206. *
  207. * @param code is one of FUNCTION_... constants
  208. * @param args are EXPRESSION objects
  209. */
  210. Object function(int code, Object[] args);
  211. /**
  212. * Produces an EXPRESSION object representing the computation of
  213. * a library function with the supplied arguments.
  214. *
  215. * @param name is a QNAME object (function name)
  216. * @param args are EXPRESSION objects
  217. */
  218. Object function(Object name, Object[] args);
  219. /**
  220. * Produces an EXPRESSION object representing logical conjunction of
  221. * all arguments
  222. *
  223. * @param arguments are EXPRESSION objects
  224. */
  225. Object and(Object arguments[]);
  226. /**
  227. * Produces an EXPRESSION object representing logical disjunction of
  228. * all arguments
  229. *
  230. * @param arguments are EXPRESSION objects
  231. */
  232. Object or(Object arguments[]);
  233. /**
  234. * Produces an EXPRESSION object representing union of all node sets
  235. *
  236. * @param arguments are EXPRESSION objects
  237. */
  238. Object union(Object[] arguments);
  239. /**
  240. * Produces a NODE_TEST object that represents a node name test.
  241. *
  242. * @param qname is a QNAME object
  243. */
  244. Object nodeNameTest(Object qname);
  245. /**
  246. * Produces a NODE_TEST object that represents a node type test.
  247. *
  248. * @param qname is a QNAME object
  249. */
  250. Object nodeTypeTest(int nodeType);
  251. /**
  252. * Produces a NODE_TEST object that represents a processing instruction
  253. * test.
  254. *
  255. * @param qname is a QNAME object
  256. */
  257. Object processingInstructionTest(String instruction);
  258. /**
  259. * Produces a STEP object that represents a node test.
  260. *
  261. * @param axis is one of the AXIS_... constants
  262. * @param nodeTest is a NODE_TEST object
  263. * @param predicates are EXPRESSION objects
  264. */
  265. Object step(int axis, Object nodeTest, Object[] predicates);
  266. /**
  267. * Produces an EXPRESSION object representing a location path
  268. *
  269. * @param absolute indicates whether the path is absolute
  270. * @param steps are STEP objects
  271. */
  272. Object locationPath(boolean absolute, Object[] steps);
  273. /**
  274. * Produces an EXPRESSION object representing a filter expression
  275. *
  276. * @param expression is an EXPRESSION object
  277. * @param predicates are EXPRESSION objects
  278. * @param steps are STEP objects
  279. */
  280. Object expressionPath(
  281. Object expression,
  282. Object[] predicates,
  283. Object[] steps);
  284. }