001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.builder;
018
019 import java.util.Map;
020
021 import org.apache.camel.Expression;
022 import org.apache.camel.builder.xml.Namespaces;
023 import org.apache.camel.model.ExpressionNode;
024 import org.apache.camel.model.language.ExpressionDefinition;
025
026 /**
027 * Represents an expression clause within the DSL which when the expression is
028 * complete the clause continues to another part of the DSL
029 *
030 * @version
031 */
032 public class ExpressionClause<T> extends ExpressionDefinition {
033 private ExpressionClauseSupport<T> delegate;
034
035 public ExpressionClause(T result) {
036 this.delegate = new ExpressionClauseSupport<T>(result);
037 }
038
039 public static <T extends ExpressionNode> ExpressionClause<T> createAndSetExpression(T result) {
040 ExpressionClause<T> clause = new ExpressionClause<T>(result);
041 result.setExpression(clause);
042 return clause;
043 }
044
045 // Helper expressions
046 // -------------------------------------------------------------------------
047
048 /**
049 * Specify an {@link Expression} instance
050 */
051 public T expression(Expression expression) {
052 return delegate.expression(expression);
053 }
054
055 /**
056 * Specify the constant expression value
057 */
058 public T constant(Object value) {
059 return delegate.constant(value);
060 }
061
062 /**
063 * An expression of the exchange
064 */
065 public T exchange() {
066 return delegate.exchange();
067 }
068
069 /**
070 * An expression of an inbound message
071 */
072 public T inMessage() {
073 return delegate.inMessage();
074 }
075
076 /**
077 * An expression of an inbound message
078 */
079 public T outMessage() {
080 return delegate.outMessage();
081 }
082
083 /**
084 * An expression of an inbound message body
085 */
086 public T body() {
087 return delegate.body();
088 }
089
090 /**
091 * An expression of an inbound message body converted to the expected type
092 */
093 public T body(Class<?> expectedType) {
094 return delegate.body(expectedType);
095 }
096
097 /**
098 * An expression of an outbound message body
099 */
100 public T outBody() {
101 return delegate.outBody();
102 }
103
104 /**
105 * An expression of an outbound message body converted to the expected type
106 */
107 public T outBody(Class<?> expectedType) {
108 return delegate.outBody(expectedType);
109 }
110
111 /**
112 * An expression of an inbound message header of the given name
113 */
114 public T header(String name) {
115 return delegate.header(name);
116 }
117
118 /**
119 * An expression of the inbound headers
120 */
121 public T headers() {
122 return delegate.headers();
123 }
124
125 /**
126 * An expression of an outbound message header of the given name
127 */
128 public T outHeader(String name) {
129 return delegate.outHeader(name);
130 }
131
132 /**
133 * An expression of the outbound headers
134 */
135 public T outHeaders() {
136 return delegate.outHeaders();
137 }
138
139 /**
140 * An expression of the inbound message attachments
141 */
142 public T attachments() {
143 return delegate.attachments();
144 }
145
146 /**
147 * An expression of an exchange property of the given name
148 */
149 public T property(String name) {
150 return delegate.property(name);
151 }
152
153 /**
154 * An expression of the exchange properties
155 */
156 public T properties() {
157 return delegate.properties();
158 }
159
160 // Languages
161 // -------------------------------------------------------------------------
162
163 /**
164 * Evaluates an expression using the <a
165 * href="http://camel.apache.org/bean-language.html>bean language</a>
166 * which basically means the bean is invoked to determine the expression
167 * value.
168 *
169 * @param bean the name of the bean looked up the registry
170 * @return the builder to continue processing the DSL
171 */
172 public T method(String bean) {
173 return delegate.method(bean);
174 }
175
176 /**
177 * Evaluates an expression using the <a
178 * href="http://camel.apache.org/bean-language.html>bean language</a>
179 * which basically means the bean is invoked to determine the expression
180 * value.
181 *
182 * @param instance the instance of the bean
183 * @return the builder to continue processing the DSL
184 */
185 public T method(Object instance) {
186 return delegate.method(instance);
187 }
188
189 /**
190 * Evaluates an expression using the <a
191 * href="http://camel.apache.org/bean-language.html>bean language</a>
192 * which basically means the bean is invoked to determine the expression
193 * value.
194 *
195 * @param beanType the Class of the bean which we want to invoke
196 * @return the builder to continue processing the DSL
197 */
198 public T method(Class<?> beanType) {
199 return delegate.method(beanType);
200 }
201
202 /**
203 * Evaluates an expression using the <a
204 * href="http://camel.apache.org/bean-language.html>bean language</a>
205 * which basically means the bean is invoked to determine the expression
206 * value.
207 *
208 * @param bean the name of the bean looked up the registry
209 * @param method the name of the method to invoke on the bean
210 * @return the builder to continue processing the DSL
211 */
212 public T method(String bean, String method) {
213 return delegate.method(bean, method);
214 }
215
216 /**
217 * Evaluates an expression using the <a
218 * href="http://camel.apache.org/bean-language.html>bean language</a>
219 * which basically means the bean is invoked to determine the expression
220 * value.
221 *
222 * @param instance the instance of the bean
223 * @param method the name of the method to invoke on the bean
224 * @return the builder to continue processing the DSL
225 */
226 public T method(Object instance, String method) {
227 return delegate.method(instance, method);
228 }
229
230 /**
231 * Evaluates an expression using the <a
232 * href="http://camel.apache.org/bean-language.html>bean language</a>
233 * which basically means the bean is invoked to determine the expression
234 * value.
235 *
236 * @param beanType the Class of the bean which we want to invoke
237 * @param method the name of the method to invoke on the bean
238 * @return the builder to continue processing the DSL
239 */
240 public T method(Class<?> beanType, String method) {
241 return delegate.method(beanType, method);
242 }
243
244 /**
245 * Evaluates the <a href="http://camel.apache.org/el.html">EL
246 * Language from JSP and JSF</a> using the <a
247 * href="http://camel.apache.org/juel.html">JUEL library</a>
248 *
249 * @param text the expression to be evaluated
250 * @return the builder to continue processing the DSL
251 */
252 public T el(String text) {
253 return delegate.el(text);
254 }
255
256 /**
257 * Evaluates a <a href="http://camel.apache.org/groovy.html">Groovy
258 * expression</a>
259 *
260 * @param text the expression to be evaluated
261 * @return the builder to continue processing the DSL
262 */
263 public T groovy(String text) {
264 return delegate.groovy(text);
265 }
266
267 /**
268 * Evaluates a <a
269 * href="http://camel.apache.org/java-script.html">JavaScript
270 * expression</a>
271 *
272 * @param text the expression to be evaluated
273 * @return the builder to continue processing the DSL
274 */
275 public T javaScript(String text) {
276 return delegate.javaScript(text);
277 }
278
279 /**
280 * Evaluates a <a href="http://commons.apache.org/jxpath/">JXPath expression</a>
281 *
282 * @param text the expression to be evaluated
283 * @return the builder to continue processing the DSL
284 */
285 public T jxpath(String text) {
286 return delegate.jxpath(text);
287 }
288
289 /**
290 * Evaluates an <a href="http://camel.apache.org/ognl.html">OGNL
291 * expression</a>
292 *
293 * @param text the expression to be evaluated
294 * @return the builder to continue processing the DSL
295 */
296 public T ognl(String text) {
297 return delegate.ognl(text);
298 }
299
300 /**
301 * Evaluates a <a href="http://camel.apache.org/mvel.html">MVEL
302 * expression</a>
303 *
304 * @param text the expression to be evaluated
305 * @return the builder to continue processing the DSL
306 */
307 public T mvel(String text) {
308 return delegate.mvel(text);
309 }
310
311 /**
312 * Evaluates a <a href="http://camel.apache.org/php.html">PHP
313 * expression</a>
314 *
315 * @param text the expression to be evaluated
316 * @return the builder to continue processing the DSL
317 */
318 public T php(String text) {
319 return delegate.php(text);
320 }
321
322 /**
323 * Evaluates a <a href="http://camel.apache.org/python.html">Python
324 * expression</a>
325 *
326 * @param text the expression to be evaluated
327 * @return the builder to continue processing the DSL
328 */
329 public T python(String text) {
330 return delegate.python(text);
331 }
332
333 /**
334 * Evaluates a <a href="http://camel.apache.org/ref-language.html">Ref
335 * expression</a>
336 *
337 * @param ref refers to the expression to be evaluated
338 * @return the builder to continue processing the DSL
339 */
340 public T ref(String ref) {
341 return delegate.ref(ref);
342 }
343
344 /**
345 * Evaluates a <a href="http://camel.apache.org/ruby.html">Ruby
346 * expression</a>
347 *
348 * @param text the expression to be evaluated
349 * @return the builder to continue processing the DSL
350 */
351 public T ruby(String text) {
352 return delegate.ruby(text);
353 }
354
355 /**
356 * Evaluates an <a href="http://camel.apache.org/sql.html">SQL
357 * expression</a>
358 *
359 * @param text the expression to be evaluated
360 * @return the builder to continue processing the DSL
361 */
362 public T sql(String text) {
363 return delegate.sql(text);
364 }
365
366 /**
367 * Evaluates a <a href="http://camel.apache.org/spel.html">SpEL
368 * expression</a>
369 *
370 * @param text the expression to be evaluated
371 * @return the builder to continue processing the DSL
372 */
373 public T spel(String text) {
374 return delegate.spel(text);
375 }
376
377 /**
378 * Evaluates a <a href="http://camel.apache.org/simple.html">Simple
379 * expression</a>
380 *
381 * @param text the expression to be evaluated
382 * @return the builder to continue processing the DSL
383 */
384 public T simple(String text) {
385 return delegate.simple(text);
386 }
387
388 /**
389 * Evaluates a <a href="http://camel.apache.org/simple.html">Simple
390 * expression</a>
391 *
392 * @param text the expression to be evaluated
393 * @param resultType the result type
394 * @return the builder to continue processing the DSL
395 */
396 public T simple(String text, Class<?> resultType) {
397 return delegate.simple(text, resultType);
398 }
399
400 /**
401 * Evaluates a token expression on the message body
402 *
403 * @param token the token
404 * @return the builder to continue processing the DSL
405 */
406 public T tokenize(String token) {
407 return delegate.tokenize(token);
408 }
409
410 /**
411 * Evaluates a token expression on the message body
412 *
413 * @param token the token
414 * @param regex whether the token is a regular expression or not
415 * @return the builder to continue processing the DSL
416 */
417 public T tokenize(String token, boolean regex) {
418 return delegate.tokenize(token, regex);
419 }
420
421 /**
422 * Evaluates a token expression on the message body
423 *
424 * @param token the token
425 * @param regex whether the token is a regular expression or not
426 * @param group to group by the given number
427 * @return the builder to continue processing the DSL
428 */
429 public T tokenize(String token, boolean regex, int group) {
430 return delegate.tokenize(token, regex);
431 }
432
433 /**
434 * Evaluates a token expression on the message body
435 *
436 * @param token the token
437 * @param group to group by the given number
438 * @return the builder to continue processing the DSL
439 */
440 public T tokenize(String token, int group) {
441 return delegate.tokenize(token, group);
442 }
443
444 /**
445 * Evaluates a token expression on the given header
446 *
447 * @param token the token
448 * @param headerName name of header to tokenize
449 * @return the builder to continue processing the DSL
450 */
451 public T tokenize(String token, String headerName) {
452 return delegate.tokenize(token, headerName);
453 }
454
455 /**
456 * Evaluates a token expression on the given header
457 *
458 * @param token the token
459 * @param headerName name of header to tokenize
460 * @param regex whether the token is a regular expression or not
461 * @return the builder to continue processing the DSL
462 */
463 public T tokenize(String token, String headerName, boolean regex) {
464 return delegate.tokenize(token, headerName, regex);
465 }
466
467 /**
468 * Evaluates a token pair expression on the message body.
469 * <p/>
470 * Tokens is not included.
471 *
472 * @param startToken the start token
473 * @param endToken the end token
474 * @return the builder to continue processing the DSL
475 */
476 public T tokenizePair(String startToken, String endToken) {
477 return tokenizePair(startToken, endToken, false);
478 }
479
480 /**
481 * Evaluates a token pair expression on the message body
482 *
483 * @param startToken the start token
484 * @param endToken the end token
485 * @param includeTokens whether to include tokens
486 * @return the builder to continue processing the DSL
487 */
488 public T tokenizePair(String startToken, String endToken, boolean includeTokens) {
489 return delegate.tokenizePair(startToken, endToken, includeTokens);
490 }
491
492 /**
493 * Evaluates a XML token expression on the message body with XML content
494 *
495 * @param tagName the the tag name of the child nodes to tokenize
496 * @return the builder to continue processing the DSL
497 */
498 public T tokenizeXML(String tagName) {
499 return tokenizeXML(tagName, null);
500 }
501
502 /**
503 * Evaluates a XML token expression on the message body with XML content
504 *
505 * @param tagName the the tag name of the child nodes to tokenize
506 * @param group to group by the given number
507 * @return the builder to continue processing the DSL
508 */
509 public T tokenizeXML(String tagName, int group) {
510 return tokenizeXML(tagName, null, group);
511 }
512
513 /**
514 * Evaluates a token pair expression on the message body with XML content
515 *
516 * @param tagName the the tag name of the child nodes to tokenize
517 * @param inheritNamespaceTagName parent or root tag name that contains namespace(s) to inherit
518 * @return the builder to continue processing the DSL
519 */
520 public T tokenizeXML(String tagName, String inheritNamespaceTagName) {
521 return tokenizeXML(tagName, inheritNamespaceTagName, 0);
522 }
523
524 /**
525 * Evaluates a token pair expression on the message body with XML content
526 *
527 * @param tagName the the tag name of the child nodes to tokenize
528 * @param inheritNamespaceTagName parent or root tag name that contains namespace(s) to inherit
529 * @param group to group by the given number
530 * @return the builder to continue processing the DSL
531 */
532 public T tokenizeXML(String tagName, String inheritNamespaceTagName, int group) {
533 return delegate.tokenizeXMLPair(tagName, inheritNamespaceTagName, group);
534 }
535
536 /**
537 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
538 * expression</a>
539 *
540 * @param text the expression to be evaluated
541 * @return the builder to continue processing the DSL
542 */
543 public T xpath(String text) {
544 return delegate.xpath(text);
545 }
546
547 /**
548 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
549 * expression</a> with the specified result type
550 *
551 * @param text the expression to be evaluated
552 * @param resultType the return type expected by the expression
553 * @return the builder to continue processing the DSL
554 */
555 public T xpath(String text, Class<?> resultType) {
556 return delegate.xpath(text, resultType);
557 }
558
559 /**
560 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
561 * expression</a> with the specified result type and set of namespace
562 * prefixes and URIs
563 *
564 * @param text the expression to be evaluated
565 * @param resultType the return type expected by the expression
566 * @param namespaces the namespace prefix and URIs to use
567 * @return the builder to continue processing the DSL
568 */
569 public T xpath(String text, Class<?> resultType, Namespaces namespaces) {
570 return delegate.xpath(text, resultType, namespaces);
571 }
572
573 /**
574 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
575 * expression</a> with the specified result type and set of namespace
576 * prefixes and URIs
577 *
578 * @param text the expression to be evaluated
579 * @param resultType the return type expected by the expression
580 * @param namespaces the namespace prefix and URIs to use
581 * @return the builder to continue processing the DSL
582 */
583 public T xpath(String text, Class<?> resultType, Map<String, String> namespaces) {
584 return delegate.xpath(text, resultType, namespaces);
585 }
586
587 /**
588 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
589 * expression</a> with the specified set of namespace prefixes and URIs
590 *
591 * @param text the expression to be evaluated
592 * @param namespaces the namespace prefix and URIs to use
593 * @return the builder to continue processing the DSL
594 */
595 public T xpath(String text, Namespaces namespaces) {
596 return delegate.xpath(text, namespaces);
597 }
598
599 /**
600 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
601 * expression</a> with the specified set of namespace prefixes and URIs
602 *
603 * @param text the expression to be evaluated
604 * @param namespaces the namespace prefix and URIs to use
605 * @return the builder to continue processing the DSL
606 */
607 public T xpath(String text, Map<String, String> namespaces) {
608 return delegate.xpath(text, namespaces);
609 }
610
611 /**
612 * Evaluates an <a
613 * href="http://camel.apache.org/xquery.html">XQuery expression</a>
614 *
615 * @param text the expression to be evaluated
616 * @return the builder to continue processing the DSL
617 */
618 public T xquery(String text) {
619 return delegate.xquery(text);
620 }
621
622 /**
623 * Evaluates an <a
624 * href="http://camel.apache.org/xquery.html">XQuery expression</a>
625 * with the specified result type
626 *
627 * @param text the expression to be evaluated
628 * @param resultType the return type expected by the expression
629 * @return the builder to continue processing the DSL
630 */
631 public T xquery(String text, Class<?> resultType) {
632 return delegate.xquery(text, resultType);
633 }
634
635 /**
636 * Evaluates an <a
637 * href="http://camel.apache.org/xquery.html">XQuery expression</a>
638 * with the specified result type and set of namespace prefixes and URIs
639 *
640 * @param text the expression to be evaluated
641 * @param resultType the return type expected by the expression
642 * @param namespaces the namespace prefix and URIs to use
643 * @return the builder to continue processing the DSL
644 */
645 public T xquery(String text, Class<?> resultType, Namespaces namespaces) {
646 return delegate.xquery(text, resultType, namespaces);
647 }
648
649 /**
650 * Evaluates an <a
651 * href="http://camel.apache.org/xquery.html">XQuery expression</a>
652 * with the specified result type and set of namespace prefixes and URIs
653 *
654 * @param text the expression to be evaluated
655 * @param resultType the return type expected by the expression
656 * @param namespaces the namespace prefix and URIs to use
657 * @return the builder to continue processing the DSL
658 */
659 public T xquery(String text, Class<?> resultType, Map<String, String> namespaces) {
660 return delegate.xquery(text, resultType, namespaces);
661 }
662
663 /**
664 * Evaluates an <a
665 * href="http://camel.apache.org/xquery.html">XQuery expression</a>
666 * with the specified set of namespace prefixes and URIs
667 *
668 * @param text the expression to be evaluated
669 * @param namespaces the namespace prefix and URIs to use
670 * @return the builder to continue processing the DSL
671 */
672 public T xquery(String text, Namespaces namespaces) {
673 return delegate.xquery(text, namespaces);
674 }
675
676 /**
677 * Evaluates an <a
678 * href="http://camel.apache.org/xquery.html">XQuery expression</a>
679 * with the specified set of namespace prefixes and URIs
680 *
681 * @param text the expression to be evaluated
682 * @param namespaces the namespace prefix and URIs to use
683 * @return the builder to continue processing the DSL
684 */
685 public T xquery(String text, Map<String, String> namespaces) {
686 return delegate.xquery(text, namespaces);
687 }
688
689 /**
690 * Evaluates a given language name with the expression text
691 *
692 * @param language the name of the language
693 * @param expression the expression in the given language
694 * @return the builder to continue processing the DSL
695 */
696 public T language(String language, String expression) {
697 return delegate.language(language, expression);
698 }
699
700 // Properties
701 // -------------------------------------------------------------------------
702
703 @Override
704 public Expression getExpressionValue() {
705 return delegate.getExpressionValue();
706 }
707
708 @Override
709 protected void setExpressionValue(Expression expressionValue) {
710 delegate.setExpressionValue(expressionValue);
711 }
712
713 @Override
714 public ExpressionDefinition getExpressionType() {
715 return delegate.getExpressionType();
716 }
717
718 @Override
719 protected void setExpressionType(ExpressionDefinition expressionType) {
720 delegate.setExpressionType(expressionType);
721 }
722 }