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