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