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