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 */
017package org.apache.camel.builder;
018
019import java.util.Map;
020import java.util.function.BiFunction;
021import java.util.function.Function;
022
023import org.apache.camel.Exchange;
024import org.apache.camel.Expression;
025import org.apache.camel.ExpressionFactory;
026import org.apache.camel.Message;
027import org.apache.camel.Predicate;
028import org.apache.camel.support.ExpressionAdapter;
029import org.apache.camel.support.ExpressionToPredicateAdapter;
030import org.apache.camel.support.builder.Namespaces;
031
032/**
033 * Represents an expression clause within the DSL which when the expression is
034 * complete the clause continues to another part of the DSL
035 */
036public class ExpressionClause<T> implements Expression, Predicate {
037    private ExpressionClauseSupport<T> delegate;
038
039    public ExpressionClause(T result) {
040        this.delegate = new ExpressionClauseSupport<>(result);
041    }
042
043    // Helper expressions
044    // -------------------------------------------------------------------------
045
046    /**
047     * Specify an {@link Expression} instance
048     */
049    public T expression(Expression expression) {
050        return delegate.expression(expression);
051    }
052
053    /**
054     * Specify the constant expression value. <b>Important:</b> this is a fixed
055     * constant value that is only set once during starting up the route, do not
056     * use this if you want dynamic values during routing.
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     * A functional expression of the exchange
071     */
072    public T exchange(final Function<Exchange, Object> function) {
073        return delegate.expression(new ExpressionAdapter() {
074            public Object evaluate(Exchange exchange) {
075                return function.apply(exchange);
076            }
077        });
078    }
079
080    /**
081     * An expression of an inbound message
082     */
083    public T message() {
084        return inMessage();
085    }
086
087    /**
088     * A functional expression of an inbound message
089     */
090    public T message(final Function<Message, Object> function) {
091        return inMessage(function);
092    }
093
094    /**
095     * An expression of an inbound message
096     */
097    public T inMessage() {
098        return delegate.inMessage();
099    }
100
101    /**
102     * A functional expression of an inbound message
103     */
104    public T inMessage(final Function<Message, Object> function) {
105        return delegate.expression(new ExpressionAdapter() {
106            public Object evaluate(Exchange exchange) {
107                return function.apply(exchange.getIn());
108            }
109        });
110    }
111
112    /**
113     * An expression of an inbound message body
114     */
115    public T body() {
116        return delegate.body();
117    }
118
119    /**
120     * A functional expression of an inbound message body
121     */
122    public T body(final Function<Object, Object> function) {
123        return delegate.expression(new ExpressionAdapter() {
124            public Object evaluate(Exchange exchange) {
125                return function.apply(exchange.getIn().getBody());
126            }
127        });
128    }
129
130    /**
131     * A functional expression of an inbound message body and headers
132     */
133    public T body(final BiFunction<Object, Map<String, Object>, Object> function) {
134        return delegate.expression(new ExpressionAdapter() {
135            public Object evaluate(Exchange exchange) {
136                return function.apply(exchange.getIn().getBody(), exchange.getIn().getHeaders());
137            }
138        });
139    }
140
141    /**
142     * An expression of an inbound message body converted to the expected type
143     */
144    public T body(Class<?> expectedType) {
145        return delegate.body(expectedType);
146    }
147
148    /**
149     * A functional expression of an inbound message body converted to the
150     * expected type
151     */
152    public <B> T body(Class<B> expectedType, final Function<B, Object> function) {
153        return delegate.expression(new ExpressionAdapter() {
154            public Object evaluate(Exchange exchange) {
155                return function.apply(exchange.getIn().getBody(expectedType));
156            }
157        });
158    }
159
160    /**
161     * A functional expression of an inbound message body converted to the
162     * expected type and headers
163     */
164    public <B> T body(Class<B> expectedType, final BiFunction<B, Map<String, Object>, Object> function) {
165        return delegate.expression(new ExpressionAdapter() {
166            public Object evaluate(Exchange exchange) {
167                return function.apply(exchange.getIn().getBody(expectedType), exchange.getIn().getHeaders());
168            }
169        });
170    }
171
172    /**
173     * An expression of an inbound message header of the given name
174     */
175    public T header(String name) {
176        return delegate.header(name);
177    }
178
179    /**
180     * An expression of the inbound headers
181     */
182    public T headers() {
183        return delegate.headers();
184    }
185
186    /**
187     * An expression of an exchange property of the given name
188     */
189    public T exchangeProperty(String name) {
190        return delegate.exchangeProperty(name);
191    }
192
193    /**
194     * An expression of the exchange properties
195     */
196    public T exchangeProperties() {
197        return delegate.exchangeProperties();
198    }
199
200    // Languages
201    // -------------------------------------------------------------------------
202
203    /**
204     * Evaluates an expression using the
205     * <a href="http://camel.apache.org/bean-language.html">bean language</a>
206     * which basically means the bean is invoked to determine the expression
207     * value.
208     *
209     * @param bean the name of the bean looked up the registry
210     * @return the builder to continue processing the DSL
211     */
212    public T method(String bean) {
213        return delegate.method(bean);
214    }
215
216    /**
217     * Evaluates an expression using the
218     * <a 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     * @return the builder to continue processing the DSL
224     */
225    public T method(Object instance) {
226        return delegate.method(instance);
227    }
228
229    /**
230     * Evaluates an expression using the
231     * <a href="http://camel.apache.org/bean-language.html">bean language</a>
232     * which basically means the bean is invoked to determine the expression
233     * value.
234     *
235     * @param beanType the Class of the bean which we want to invoke
236     * @return the builder to continue processing the DSL
237     */
238    public T method(Class<?> beanType) {
239        return delegate.method(beanType);
240    }
241
242    /**
243     * Evaluates an expression using the
244     * <a href="http://camel.apache.org/bean-language.html">bean language</a>
245     * which basically means the bean is invoked to determine the expression
246     * value.
247     *
248     * @param bean the name of the bean looked up the registry
249     * @param method the name of the method to invoke on the bean
250     * @return the builder to continue processing the DSL
251     */
252    public T method(String bean, String method) {
253        return delegate.method(bean, method);
254    }
255
256    /**
257     * Evaluates an expression using the
258     * <a href="http://camel.apache.org/bean-language.html">bean language</a>
259     * which basically means the bean is invoked to determine the expression
260     * value.
261     *
262     * @param instance the instance of the bean
263     * @param method the name of the method to invoke on the bean
264     * @return the builder to continue processing the DSL
265     */
266    public T method(Object instance, String method) {
267        return delegate.method(instance, method);
268    }
269
270    /**
271     * Evaluates an expression using the
272     * <a href="http://camel.apache.org/bean-language.html">bean language</a>
273     * which basically means the bean is invoked to determine the expression
274     * value.
275     *
276     * @param beanType the Class of the bean which we want to invoke
277     * @param method the name of the method to invoke on the bean
278     * @return the builder to continue processing the DSL
279     */
280    public T method(Class<?> beanType, String method) {
281        return delegate.method(beanType, method);
282    }
283
284    /**
285     * Evaluates a <a href="http://camel.apache.org/groovy.html">Groovy
286     * expression</a>
287     *
288     * @param text the expression to be evaluated
289     * @return the builder to continue processing the DSL
290     */
291    public T groovy(String text) {
292        return delegate.groovy(text);
293    }
294
295    /**
296     * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path
297     * expression</a>
298     *
299     * @param text the expression to be evaluated
300     * @return the builder to continue processing the DSL
301     */
302    public T jsonpath(String text) {
303        return delegate.jsonpath(text);
304    }
305
306    /**
307     * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path
308     * expression</a>
309     *
310     * @param text the expression to be evaluated
311     * @param suppressExceptions whether to suppress exceptions such as
312     *            PathNotFoundException
313     * @return the builder to continue processing the DSL
314     */
315    public T jsonpath(String text, boolean suppressExceptions) {
316        return delegate.jsonpath(text, suppressExceptions);
317    }
318
319    /**
320     * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path
321     * expression</a>
322     *
323     * @param text the expression to be evaluated
324     * @param resultType the return type expected by the expression
325     * @return the builder to continue processing the DSL
326     */
327    public T jsonpath(String text, Class<?> resultType) {
328        return delegate.jsonpath(text, resultType);
329    }
330
331    /**
332     * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path
333     * expression</a>
334     *
335     * @param text the expression to be evaluated
336     * @param suppressExceptions whether to suppress exceptions such as
337     *            PathNotFoundException
338     * @param resultType the return type expected by the expression
339     * @return the builder to continue processing the DSL
340     */
341    public T jsonpath(String text, boolean suppressExceptions, Class<?> resultType) {
342        return delegate.jsonpath(text, suppressExceptions, resultType);
343    }
344
345    /**
346     * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path
347     * expression</a>
348     *
349     * @param text the expression to be evaluated
350     * @param suppressExceptions whether to suppress exceptions such as
351     *            PathNotFoundException
352     * @param resultType the return type expected by the expression
353     * @param headerName the name of the header to apply the expression to
354     * @return the builder to continue processing the DSL
355     */
356    public T jsonpath(String text, boolean suppressExceptions, Class<?> resultType, String headerName) {
357        return delegate.jsonpath(text, suppressExceptions, true, resultType, headerName);
358    }
359
360    /**
361     * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path
362     * expression</a> with writeAsString enabled.
363     *
364     * @param text the expression to be evaluated
365     * @return the builder to continue processing the DSL
366     */
367    public T jsonpathWriteAsString(String text) {
368        return delegate.jsonpathWriteAsString(text);
369    }
370
371    /**
372     * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path
373     * expression</a> with writeAsString enabled.
374     *
375     * @param text the expression to be evaluated
376     * @param suppressExceptions whether to suppress exceptions such as
377     *            PathNotFoundException
378     * @return the builder to continue processing the DSL
379     */
380    public T jsonpathWriteAsString(String text, boolean suppressExceptions) {
381        return delegate.jsonpathWriteAsString(text, suppressExceptions);
382    }
383
384    /**
385     * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path
386     * expression</a> with writeAsString enabled.
387     *
388     * @param text the expression to be evaluated
389     * @param suppressExceptions whether to suppress exceptions such as
390     *            PathNotFoundException
391     * @param headerName the name of the header to apply the expression to
392     * @return the builder to continue processing the DSL
393     */
394    public T jsonpathWriteAsString(String text, boolean suppressExceptions, String headerName) {
395        return delegate.jsonpathWriteAsString(text, suppressExceptions, true, headerName);
396    }
397
398    /**
399     * Evaluates an <a href="http://camel.apache.org/ognl.html">OGNL
400     * expression</a>
401     *
402     * @param text the expression to be evaluated
403     * @return the builder to continue processing the DSL
404     */
405    public T ognl(String text) {
406        return delegate.ognl(text);
407    }
408
409    /**
410     * Evaluates a <a href="http://camel.apache.org/mvel.html">MVEL
411     * expression</a>
412     *
413     * @param text the expression to be evaluated
414     * @return the builder to continue processing the DSL
415     */
416    public T mvel(String text) {
417        return delegate.mvel(text);
418    }
419
420    /**
421     * Evaluates a <a href="http://camel.apache.org/ref-language.html">Ref
422     * expression</a>
423     *
424     * @param ref refers to the expression to be evaluated
425     * @return the builder to continue processing the DSL
426     */
427    public T ref(String ref) {
428        return delegate.ref(ref);
429    }
430
431    /**
432     * Evaluates a <a href="http://camel.apache.org/spel.html">SpEL
433     * expression</a>
434     *
435     * @param text the expression to be evaluated
436     * @return the builder to continue processing the DSL
437     */
438    public T spel(String text) {
439        return delegate.spel(text);
440    }
441
442    /**
443     * Evaluates a <a href="http://camel.apache.org/simple.html">Simple
444     * expression</a>
445     *
446     * @param text the expression to be evaluated
447     * @return the builder to continue processing the DSL
448     */
449    public T simple(String text) {
450        return delegate.simple(text);
451    }
452
453    /**
454     * Evaluates a <a href="http://camel.apache.org/simple.html">Simple
455     * expression</a>
456     *
457     * @param text the expression to be evaluated
458     * @param resultType the result type
459     * @return the builder to continue processing the DSL
460     */
461    public T simple(String text, Class<?> resultType) {
462        return delegate.simple(text, resultType);
463    }
464
465    /**
466     * Evaluates a token expression on the message body
467     *
468     * @param token the token
469     * @return the builder to continue processing the DSL
470     */
471    public T tokenize(String token) {
472        return delegate.tokenize(token);
473    }
474
475    /**
476     * Evaluates a token expression on the message body
477     *
478     * @param token the token
479     * @param regex whether the token is a regular expression or not
480     * @return the builder to continue processing the DSL
481     */
482    public T tokenize(String token, boolean regex) {
483        return tokenize(token, regex, false);
484    }
485
486    /**
487     * Evaluates a token expression on the message body
488     *
489     * @param token the token
490     * @param regex whether the token is a regular expression or not
491     * @param skipFirst whether to skip the first element
492     * @return the builder to continue processing the DSL
493     */
494    public T tokenize(String token, boolean regex, boolean skipFirst) {
495        return delegate.tokenize(token, null, regex, skipFirst);
496    }
497
498    /**
499     * Evaluates a token expression on the message body
500     *
501     * @param token the token
502     * @param regex whether the token is a regular expression or not
503     * @param group to group by the given number
504     * @return the builder to continue processing the DSL
505     */
506    public T tokenize(String token, boolean regex, int group) {
507        return tokenize(token, regex, group, false);
508    }
509
510    /**
511     * Evaluates a token expression on the message body
512     *
513     * @param token the token
514     * @param regex whether the token is a regular expression or not
515     * @param group to group by the given number
516     * @return the builder to continue processing the DSL
517     */
518    public T tokenize(String token, boolean regex, String group) {
519        return tokenize(token, regex, group, false);
520    }
521
522    /**
523     * Evaluates a token expression on the message body
524     *
525     * @param token the token
526     * @param regex whether the token is a regular expression or not
527     * @param group to group by the given number
528     * @param skipFirst whether to skip the first element
529     * @return the builder to continue processing the DSL
530     */
531    public T tokenize(String token, boolean regex, int group, boolean skipFirst) {
532        return delegate.tokenize(token, null, regex, group, skipFirst);
533    }
534
535    /**
536     * Evaluates a token expression on the message body
537     *
538     * @param token the token
539     * @param regex whether the token is a regular expression or not
540     * @param group to group by the given number
541     * @param skipFirst whether to skip the first element
542     * @return the builder to continue processing the DSL
543     */
544    public T tokenize(String token, boolean regex, String group, boolean skipFirst) {
545        return delegate.tokenize(token, null, regex, group, skipFirst);
546    }
547
548    /**
549     * Evaluates a token expression on the message body
550     *
551     * @param token the token
552     * @param regex whether the token is a regular expression or not
553     * @param group to group by the given number
554     * @param skipFirst whether to skip the first element
555     * @return the builder to continue processing the DSL
556     */
557    public T tokenize(String token, boolean regex, int group, String groupDelimiter, boolean skipFirst) {
558        return delegate.tokenize(token, null, regex, "" + group, groupDelimiter, skipFirst);
559    }
560
561    /**
562     * Evaluates a token expression on the message body
563     *
564     * @param token the token
565     * @param group to group by the given number
566     * @return the builder to continue processing the DSL
567     */
568    public T tokenize(String token, int group) {
569        return delegate.tokenize(token, group);
570    }
571
572    /**
573     * Evaluates a token expression on the message body
574     *
575     * @param token the token
576     * @param group to group by the given number
577     * @param skipFirst whether to skip the first element
578     * @return the builder to continue processing the DSL
579     */
580    public T tokenize(String token, int group, boolean skipFirst) {
581        return delegate.tokenize(token, group, skipFirst);
582    }
583
584    /**
585     * Evaluates a token expression on the given header
586     *
587     * @param token the token
588     * @param headerName name of header to tokenize
589     * @return the builder to continue processing the DSL
590     */
591    public T tokenize(String token, String headerName) {
592        return delegate.tokenize(token, headerName);
593    }
594
595    /**
596     * Evaluates a token expression on the given header
597     *
598     * @param token the token
599     * @param headerName name of header to tokenize
600     * @param regex whether the token is a regular expression or not
601     * @return the builder to continue processing the DSL
602     */
603    public T tokenize(String token, String headerName, boolean regex) {
604        return delegate.tokenize(token, headerName, regex);
605    }
606
607    /**
608     * Evaluates a token pair expression on the message body.
609     * <p/>
610     * Tokens is not included.
611     *
612     * @param startToken the start token
613     * @param endToken the end token
614     * @return the builder to continue processing the DSL
615     */
616    public T tokenizePair(String startToken, String endToken) {
617        return tokenizePair(startToken, endToken, false);
618    }
619
620    /**
621     * Evaluates a token pair expression on the message body
622     *
623     * @param startToken the start token
624     * @param endToken the end token
625     * @param includeTokens whether to include tokens
626     * @return the builder to continue processing the DSL
627     */
628    public T tokenizePair(String startToken, String endToken, boolean includeTokens) {
629        return delegate.tokenizePair(startToken, endToken, includeTokens);
630    }
631
632    /**
633     * Evaluates a XML token expression on the message body with XML content
634     *
635     * @param tagName the tag name of the child nodes to tokenize
636     * @return the builder to continue processing the DSL
637     */
638    public T tokenizeXML(String tagName) {
639        return tokenizeXML(tagName, null);
640    }
641
642    /**
643     * Evaluates a XML token expression on the message body with XML content
644     *
645     * @param tagName the tag name of the child nodes to tokenize
646     * @param group to group by the given number
647     * @return the builder to continue processing the DSL
648     */
649    public T tokenizeXML(String tagName, int group) {
650        return tokenizeXML(tagName, null, group);
651    }
652
653    /**
654     * Evaluates a token pair expression on the message body with XML content
655     *
656     * @param tagName the tag name of the child nodes to tokenize
657     * @param inheritNamespaceTagName parent or root tag name that contains
658     *            namespace(s) to inherit
659     * @return the builder to continue processing the DSL
660     */
661    public T tokenizeXML(String tagName, String inheritNamespaceTagName) {
662        return tokenizeXML(tagName, inheritNamespaceTagName, 0);
663    }
664
665    /**
666     * Evaluates a token pair expression on the message body with XML content
667     *
668     * @param tagName the tag name of the child nodes to tokenize
669     * @param inheritNamespaceTagName parent or root tag name that contains
670     *            namespace(s) to inherit
671     * @param group to group by the given number
672     * @return the builder to continue processing the DSL
673     */
674    public T tokenizeXML(String tagName, String inheritNamespaceTagName, int group) {
675        return delegate.tokenizeXMLPair(tagName, inheritNamespaceTagName, group);
676    }
677
678    public T xtokenize(String path, Namespaces namespaces) {
679        return xtokenize(path, 'i', namespaces);
680    }
681
682    public T xtokenize(String path, char mode, Namespaces namespaces) {
683        return xtokenize(path, mode, namespaces, 0);
684    }
685
686    public T xtokenize(String path, char mode, Namespaces namespaces, int group) {
687        return delegate.xtokenize(path, mode, namespaces, group);
688    }
689
690    /**
691     * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
692     * expression</a>
693     *
694     * @param text the expression to be evaluated
695     * @return the builder to continue processing the DSL
696     */
697    public T xpath(String text) {
698        return delegate.xpath(text);
699    }
700
701    /**
702     * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
703     * expression</a> on the supplied header name's contents
704     *
705     * @param text the expression to be evaluated
706     * @param headerName the name of the header to apply the expression to
707     * @return the builder to continue processing the DSL
708     */
709    public T xpath(String text, String headerName) {
710        return delegate.xpath(text, headerName);
711    }
712
713    /**
714     * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
715     * expression</a> with the specified result type
716     *
717     * @param text the expression to be evaluated
718     * @param resultType the return type expected by the expression
719     * @return the builder to continue processing the DSL
720     */
721    public T xpath(String text, Class<?> resultType) {
722        return delegate.xpath(text, resultType);
723    }
724
725    /**
726     * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
727     * expression</a> with the specified result type on the supplied header
728     * name's contents
729     *
730     * @param text the expression to be evaluated
731     * @param resultType the return type expected by the expression
732     * @param headerName the name of the header to apply the expression to
733     * @return the builder to continue processing the DSL
734     */
735    public T xpath(String text, Class<?> resultType, String headerName) {
736        return delegate.xpath(text, resultType, headerName);
737    }
738
739    /**
740     * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
741     * expression</a> with the specified result type and set of namespace
742     * prefixes and URIs
743     *
744     * @param text the expression to be evaluated
745     * @param resultType the return type expected by the expression
746     * @param namespaces the namespace prefix and URIs to use
747     * @return the builder to continue processing the DSL
748     */
749    public T xpath(String text, Class<?> resultType, Namespaces namespaces) {
750        return delegate.xpath(text, resultType, namespaces);
751    }
752
753    /**
754     * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
755     * expression</a> with the specified result type and set of namespace
756     * prefixes and URIs on the supplied header name's contents
757     *
758     * @param text the expression to be evaluated
759     * @param resultType the return type expected by the expression
760     * @param headerName the name of the header to apply the expression to
761     * @param namespaces the namespace prefix and URIs to use
762     * @return the builder to continue processing the DSL
763     */
764    public T xpath(String text, Class<?> resultType, Namespaces namespaces, String headerName) {
765        return delegate.xpath(text, resultType, namespaces, headerName);
766    }
767
768    /**
769     * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
770     * expression</a> with the specified result type and set of namespace
771     * prefixes and URIs
772     *
773     * @param text the expression to be evaluated
774     * @param resultType the return type expected by the expression
775     * @param namespaces the namespace prefix and URIs to use
776     * @return the builder to continue processing the DSL
777     */
778    public T xpath(String text, Class<?> resultType, Map<String, String> namespaces) {
779        return delegate.xpath(text, resultType, namespaces);
780    }
781
782    /**
783     * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
784     * expression</a> with the specified set of namespace prefixes and URIs
785     *
786     * @param text the expression to be evaluated
787     * @param namespaces the namespace prefix and URIs to use
788     * @return the builder to continue processing the DSL
789     */
790    public T xpath(String text, Namespaces namespaces) {
791        return delegate.xpath(text, namespaces);
792    }
793
794    /**
795     * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
796     * expression</a> with the specified set of namespace prefixes and URIs
797     *
798     * @param text the expression to be evaluated
799     * @param namespaces the namespace prefix and URIs to use
800     * @return the builder to continue processing the DSL
801     */
802    public T xpath(String text, Map<String, String> namespaces) {
803        return delegate.xpath(text, namespaces);
804    }
805
806    /**
807     * Evaluates an <a href="http://camel.apache.org/xquery.html">XQuery
808     * expression</a>
809     *
810     * @param text the expression to be evaluated
811     * @return the builder to continue processing the DSL
812     */
813    public T xquery(String text) {
814        return delegate.xquery(text);
815    }
816
817    /**
818     * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
819     * expression</a> on the supplied header name's contents
820     *
821     * @param text the expression to be evaluated
822     * @param headerName the name of the header to apply the expression to
823     * @return the builder to continue processing the DSL
824     */
825    public T xquery(String text, String headerName) {
826        return delegate.xquery(text, headerName);
827    }
828
829    /**
830     * Evaluates an <a href="http://camel.apache.org/xquery.html">XQuery
831     * expression</a> with the specified result type
832     *
833     * @param text the expression to be evaluated
834     * @param resultType the return type expected by the expression
835     * @return the builder to continue processing the DSL
836     */
837    public T xquery(String text, Class<?> resultType) {
838        return delegate.xquery(text, resultType);
839    }
840
841    /**
842     * Evaluates an <a href="http://camel.apache.org/xquery.html">XQuery
843     * expression</a> with the specified result type
844     *
845     * @param text the expression to be evaluated
846     * @param resultType the return type expected by the expression
847     * @param headerName the name of the header to apply the expression to
848     * @return the builder to continue processing the DSL
849     */
850    public T xquery(String text, Class<?> resultType, String headerName) {
851        return delegate.xquery(text, resultType, headerName);
852    }
853
854    /**
855     * Evaluates an <a href="http://camel.apache.org/xquery.html">XQuery
856     * expression</a> with the specified result type and set of namespace
857     * prefixes and URIs
858     *
859     * @param text the expression to be evaluated
860     * @param resultType the return type expected by the expression
861     * @param namespaces the namespace prefix and URIs to use
862     * @return the builder to continue processing the DSL
863     */
864    public T xquery(String text, Class<?> resultType, Namespaces namespaces) {
865        return delegate.xquery(text, resultType, namespaces);
866    }
867
868    /**
869     * Evaluates an <a href="http://camel.apache.org/xquery.html">XQuery
870     * expression</a> with the specified result type
871     *
872     * @param text the expression to be evaluated
873     * @param resultType the return type expected by the expression
874     * @param headerName the name of the header to apply the expression to
875     * @param namespaces the namespace prefix and URIs to use
876     * @return the builder to continue processing the DSL
877     */
878    public T xquery(String text, Class<?> resultType, Namespaces namespaces, String headerName) {
879        return delegate.xquery(text, resultType, namespaces, headerName);
880    }
881
882    /**
883     * Evaluates an <a href="http://camel.apache.org/xquery.html">XQuery
884     * expression</a> with the specified result type and set of namespace
885     * prefixes and URIs
886     *
887     * @param text the expression to be evaluated
888     * @param resultType the return type expected by the expression
889     * @param namespaces the namespace prefix and URIs to use
890     * @return the builder to continue processing the DSL
891     */
892    public T xquery(String text, Class<?> resultType, Map<String, String> namespaces) {
893        return delegate.xquery(text, resultType, namespaces);
894    }
895
896    /**
897     * Evaluates an <a href="http://camel.apache.org/xquery.html">XQuery
898     * expression</a> with the specified set of namespace prefixes and URIs
899     *
900     * @param text the expression to be evaluated
901     * @param namespaces the namespace prefix and URIs to use
902     * @return the builder to continue processing the DSL
903     */
904    public T xquery(String text, Namespaces namespaces) {
905        return delegate.xquery(text, namespaces);
906    }
907
908    /**
909     * Evaluates an <a href="http://camel.apache.org/xquery.html">XQuery
910     * expression</a> with the specified set of namespace prefixes and URIs
911     *
912     * @param text the expression to be evaluated
913     * @param namespaces the namespace prefix and URIs to use
914     * @return the builder to continue processing the DSL
915     */
916    public T xquery(String text, Map<String, String> namespaces) {
917        return delegate.xquery(text, namespaces);
918    }
919
920    /**
921     * Evaluates a given language name with the expression text
922     *
923     * @param language the name of the language
924     * @param expression the expression in the given language
925     * @return the builder to continue processing the DSL
926     */
927    public T language(String language, String expression) {
928        return delegate.language(language, expression);
929    }
930
931    // Properties
932    // -------------------------------------------------------------------------
933
934    public Expression getExpressionValue() {
935        return delegate.getExpressionValue();
936    }
937
938    public ExpressionFactory getExpressionType() {
939        return delegate.getExpressionType();
940    }
941
942    @Override
943    public <T> T evaluate(Exchange exchange, Class<T> type) {
944        if (getExpressionValue() != null) {
945            return getExpressionValue().evaluate(exchange, type);
946        } else {
947            Expression exp = delegate.getExpressionType().createExpression(exchange.getContext());
948            return exp.evaluate(exchange, type);
949        }
950    }
951
952    @Override
953    public boolean matches(Exchange exchange) {
954        if (getExpressionValue() != null) {
955            return new ExpressionToPredicateAdapter(getExpressionValue()).matches(exchange);
956        } else {
957            Expression exp = delegate.getExpressionType().createExpression(exchange.getContext());
958            return new ExpressionToPredicateAdapter(exp).matches(exchange);
959        }
960    }
961}