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 expression(new JsonPathExpression(text)); 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 resultType the return type expected by the expression 345 * @return the builder to continue processing the DSL 346 */ 347 public T jsonpath(String text, Class<?> resultType) { 348 JsonPathExpression expression = new JsonPathExpression(text); 349 expression.setResultType(resultType); 350 setExpressionType(expression); 351 return result; 352 } 353 354 /** 355 * Evaluates a <a href="http://commons.apache.org/jxpath/">JXPath expression</a> 356 * 357 * @param text the expression to be evaluated 358 * @return the builder to continue processing the DSL 359 */ 360 public T jxpath(String text) { 361 return jxpath(text, false); 362 } 363 364 /** 365 * Evaluates a <a href="http://commons.apache.org/jxpath/">JXPath expression</a> 366 * 367 * @param text the expression to be evaluated 368 * @param lenient to configure whether lenient is in use or not 369 * @return the builder to continue processing the DSL 370 */ 371 public T jxpath(String text, boolean lenient) { 372 JXPathExpression answer = new JXPathExpression(text); 373 answer.setLenient(lenient); 374 return expression(answer); 375 } 376 377 /** 378 * Evaluates an <a href="http://camel.apache.org/ognl.html">OGNL 379 * expression</a> 380 * 381 * @param text the expression to be evaluated 382 * @return the builder to continue processing the DSL 383 */ 384 public T ognl(String text) { 385 return expression(new OgnlExpression(text)); 386 } 387 388 /** 389 * Evaluates a <a href="http://camel.apache.org/mvel.html">MVEL 390 * expression</a> 391 * 392 * @param text the expression to be evaluated 393 * @return the builder to continue processing the DSL 394 */ 395 public T mvel(String text) { 396 return expression(new MvelExpression(text)); 397 } 398 399 /** 400 * Evaluates a <a href="http://camel.apache.org/php.html">PHP 401 * expression</a> 402 * 403 * @param text the expression to be evaluated 404 * @return the builder to continue processing the DSL 405 */ 406 public T php(String text) { 407 return expression(new PhpExpression(text)); 408 } 409 410 /** 411 * Evaluates a <a href="http://camel.apache.org/python.html">Python 412 * expression</a> 413 * 414 * @param text the expression to be evaluated 415 * @return the builder to continue processing the DSL 416 */ 417 public T python(String text) { 418 return expression(new PythonExpression(text)); 419 } 420 421 /** 422 * Evaluates a {@link Expression} by looking up existing {@link Expression} 423 * from the {@link org.apache.camel.spi.Registry} 424 * 425 * @param ref refers to the expression to be evaluated 426 * @return the builder to continue processing the DSL 427 */ 428 public T ref(String ref) { 429 return expression(new RefExpression(ref)); 430 } 431 432 /** 433 * Evaluates a <a href="http://camel.apache.org/ruby.html">Ruby 434 * expression</a> 435 * 436 * @param text the expression to be evaluated 437 * @return the builder to continue processing the DSL 438 */ 439 public T ruby(String text) { 440 return expression(new RubyExpression(text)); 441 } 442 443 /** 444 * Evaluates an <a href="http://camel.apache.org/spel.html">SpEL 445 * expression</a> 446 * 447 * @param text the expression to be evaluated 448 * @return the builder to continue processing the DSL 449 */ 450 public T spel(String text) { 451 return expression(new SpELExpression(text)); 452 } 453 454 /** 455 * Evaluates an <a href="http://camel.apache.org/sql.html">SQL 456 * expression</a> 457 * 458 * @param text the expression to be evaluated 459 * @return the builder to continue processing the DSL 460 */ 461 public T sql(String text) { 462 return expression(new SqlExpression(text)); 463 } 464 465 /** 466 * Evaluates a <a href="http://camel.apache.org/simple.html">Simple 467 * expression</a> 468 * 469 * @param text the expression to be evaluated 470 * @return the builder to continue processing the DSL 471 */ 472 public T simple(String text) { 473 return expression(new SimpleExpression(text)); 474 } 475 476 /** 477 * Evaluates a <a href="http://camel.apache.org/simple.html">Simple 478 * expression</a> 479 * 480 * @param text the expression to be evaluated 481 * @param resultType the result type 482 * @return the builder to continue processing the DSL 483 */ 484 public T simple(String text, Class<?> resultType) { 485 SimpleExpression expression = new SimpleExpression(text); 486 expression.setResultType(resultType); 487 setExpressionType(expression); 488 return result; 489 } 490 491 /** 492 * Evaluates an <a href="http://camel.apache.org/hl7.html">HL7 Terser 493 * expression</a> 494 * 495 * @param text the expression to be evaluated 496 * @return the builder to continue processing the DSL 497 */ 498 public T terser(String text) { 499 return expression(new TerserExpression(text)); 500 } 501 502 /** 503 * Evaluates a token expression on the message body 504 * 505 * @param token the token 506 * @return the builder to continue processing the DSL 507 */ 508 public T tokenize(String token) { 509 return tokenize(token, null, false); 510 } 511 512 /** 513 * Evaluates a token expression on the message body 514 * 515 * @param token the token 516 * @param group to group by the given number 517 * @return the builder to continue processing the DSL 518 */ 519 public T tokenize(String token, int group) { 520 return tokenize(token, null, false, group); 521 } 522 523 /** 524 * Evaluates a token expression on the message body 525 * 526 * @param token the token 527 * @param regex whether the token is a regular expression or not 528 * @return the builder to continue processing the DSL 529 */ 530 public T tokenize(String token, boolean regex) { 531 return tokenize(token, null, regex); 532 } 533 534 /** 535 * Evaluates a token expression on the message body 536 * 537 * @param token the token 538 * @param regex whether the token is a regular expression or not 539 * @param group to group by the given number 540 * @return the builder to continue processing the DSL 541 */ 542 public T tokenize(String token, boolean regex, int group) { 543 return tokenize(token, null, regex, group); 544 } 545 546 /** 547 * Evaluates a token expression on the given header 548 * 549 * @param token the token 550 * @param headerName name of header to tokenize 551 * @return the builder to continue processing the DSL 552 */ 553 public T tokenize(String token, String headerName) { 554 return tokenize(token, headerName, false); 555 } 556 557 /** 558 * Evaluates a token expression on the given header 559 * 560 * @param token the token 561 * @param headerName name of header to tokenize 562 * @param regex whether the token is a regular expression or not 563 * @return the builder to continue processing the DSL 564 */ 565 public T tokenize(String token, String headerName, boolean regex) { 566 TokenizerExpression expression = new TokenizerExpression(); 567 expression.setToken(token); 568 expression.setHeaderName(headerName); 569 expression.setRegex(regex); 570 setExpressionType(expression); 571 return result; 572 } 573 574 /** 575 * Evaluates a token expression on the given header 576 * 577 * @param token the token 578 * @param headerName name of header to tokenize 579 * @param regex whether the token is a regular expression or not 580 * @param group to group by number of parts 581 * @return the builder to continue processing the DSL 582 */ 583 public T tokenize(String token, String headerName, boolean regex, int group) { 584 TokenizerExpression expression = new TokenizerExpression(); 585 expression.setToken(token); 586 expression.setHeaderName(headerName); 587 expression.setRegex(regex); 588 expression.setGroup(group); 589 setExpressionType(expression); 590 return result; 591 } 592 593 /** 594 * Evaluates a token pair expression on the message body 595 * 596 * @param startToken the start token 597 * @param endToken the end token 598 * @param includeTokens whether to include tokens 599 * @return the builder to continue processing the DSL 600 */ 601 public T tokenizePair(String startToken, String endToken, boolean includeTokens) { 602 TokenizerExpression expression = new TokenizerExpression(); 603 expression.setToken(startToken); 604 expression.setEndToken(endToken); 605 expression.setIncludeTokens(includeTokens); 606 setExpressionType(expression); 607 return result; 608 } 609 610 /** 611 * Evaluates a token pair expression on the message body with XML content 612 * 613 * @param tagName the the tag name of the child nodes to tokenize 614 * @param inheritNamespaceTagName optional parent or root tag name that contains namespace(s) to inherit 615 * @param group to group by the given number 616 * @return the builder to continue processing the DSL 617 */ 618 public T tokenizeXMLPair(String tagName, String inheritNamespaceTagName, int group) { 619 TokenizerExpression expression = new TokenizerExpression(); 620 expression.setToken(tagName); 621 expression.setInheritNamespaceTagName(inheritNamespaceTagName); 622 expression.setXml(true); 623 if (group > 0) { 624 expression.setGroup(group); 625 } 626 setExpressionType(expression); 627 return result; 628 } 629 630 /** 631 * Evaluates an XML token expression on the message body with XML content 632 * 633 * @param path the xpath like path notation specifying the child nodes to tokenize 634 * @param mode one of 'i', 'w', or 'u' to inject the namespaces to the token, to 635 * wrap the token with its ancestor contet, or to unwrap to its element child 636 * @param namespaces the namespace map to the namespace bindings 637 * @param group to group by the given number 638 * @return the builder to continue processing the DSL 639 */ 640 public T xtokenize(String path, char mode, Namespaces namespaces, int group) { 641 XMLTokenizerExpression expression = new XMLTokenizerExpression(path); 642 expression.setMode(Character.toString(mode)); 643 expression.setNamespaces(namespaces.getNamespaces()); 644 645 if (group > 0) { 646 expression.setGroup(group); 647 } 648 setExpressionType(expression); 649 return result; 650 } 651 652 /** 653 * Evaluates an <a href="http://camel.apache.org/vtdxml.html">XPath 654 * expression using the VTD-XML library</a> 655 * 656 * @param text the expression to be evaluated 657 * @return the builder to continue processing the DSL 658 */ 659 public T vtdxml(String text) { 660 return expression(new VtdXmlExpression(text)); 661 } 662 663 /** 664 * Evaluates an <a href="http://camel.apache.org/vtdxml.html">XPath 665 * expression using the VTD-XML library</a> 666 * with the specified set of namespace prefixes and URIs 667 * 668 * @param text the expression to be evaluated 669 * @param namespaces the namespace prefix and URIs to use 670 * @return the builder to continue processing the DSL 671 */ 672 public T vtdxml(String text, Namespaces namespaces) { 673 return vtdxml(text, namespaces.getNamespaces()); 674 } 675 676 /** 677 * Evaluates an <a href="http://camel.apache.org/vtdxml.html">XPath 678 * expression using the VTD-XML library</a> 679 * with the specified set of namespace prefixes and URIs 680 * 681 * @param text the expression to be evaluated 682 * @param namespaces the namespace prefix and URIs to use 683 * @return the builder to continue processing the DSL 684 */ 685 public T vtdxml(String text, Map<String, String> namespaces) { 686 VtdXmlExpression expression = new VtdXmlExpression(text); 687 expression.setNamespaces(namespaces); 688 setExpressionType(expression); 689 return result; 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 expression(new XPathExpression(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 XPathExpression expression = new XPathExpression(text); 713 expression.setHeaderName(headerName); 714 return expression(expression); 715 } 716 717 /** 718 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 719 * expression</a> with the specified result type 720 * 721 * @param text the expression to be evaluated 722 * @param resultType the return type expected by the expression 723 * @return the builder to continue processing the DSL 724 */ 725 public T xpath(String text, Class<?> resultType) { 726 XPathExpression expression = new XPathExpression(text); 727 expression.setResultType(resultType); 728 setExpressionType(expression); 729 return result; 730 } 731 732 733 /** 734 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 735 * expression</a> with the specified result type on the supplied 736 * header name's contents 737 * 738 * @param text the expression to be evaluated 739 * @param resultType the return type expected by the expression 740 * @param headerName the name of the header to apply the expression to 741 * @return the builder to continue processing the DSL 742 */ 743 public T xpath(String text, Class<?> resultType, String headerName) { 744 XPathExpression expression = new XPathExpression(text); 745 expression.setHeaderName(headerName); 746 setExpressionType(expression); 747 return result; 748 } 749 750 751 /** 752 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 753 * expression</a> with the specified result type and set of namespace 754 * prefixes and URIs 755 * 756 * @param text the expression to be evaluated 757 * @param resultType the return type expected by the expression 758 * @param namespaces the namespace prefix and URIs to use 759 * @return the builder to continue processing the DSL 760 */ 761 public T xpath(String text, Class<?> resultType, Namespaces namespaces) { 762 return xpath(text, resultType, namespaces.getNamespaces()); 763 } 764 765 /** 766 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 767 * expression</a> with the specified result type and set of namespace 768 * prefixes and URIs on the supplied header name's contents 769 * 770 * @param text the expression to be evaluated 771 * @param resultType the return type expected by the expression 772 * @param namespaces the namespace prefix and URIs to use 773 * @param headerName the name of the header to apply the expression to 774 * @return the builder to continue processing the DSL 775 */ 776 public T xpath(String text, Class<?> resultType, Namespaces namespaces, String headerName) { 777 XPathExpression expression = new XPathExpression(text); 778 expression.setResultType(resultType); 779 expression.setNamespaces(namespaces.getNamespaces()); 780 expression.setHeaderName(headerName); 781 setExpressionType(expression); 782 return result; 783 } 784 785 786 /** 787 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 788 * expression</a> with the specified result type and set of namespace 789 * prefixes and URIs 790 * 791 * @param text the expression to be evaluated 792 * @param resultType the return type expected by the expression 793 * @param namespaces the namespace prefix and URIs to use 794 * @return the builder to continue processing the DSL 795 */ 796 public T xpath(String text, Class<?> resultType, Map<String, String> namespaces) { 797 XPathExpression expression = new XPathExpression(text); 798 expression.setResultType(resultType); 799 expression.setNamespaces(namespaces); 800 setExpressionType(expression); 801 return result; 802 } 803 804 /** 805 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 806 * expression</a> with the specified set of namespace prefixes and URIs 807 * 808 * @param text the expression to be evaluated 809 * @param namespaces the namespace prefix and URIs to use 810 * @return the builder to continue processing the DSL 811 */ 812 public T xpath(String text, Namespaces namespaces) { 813 return xpath(text, namespaces.getNamespaces()); 814 } 815 816 /** 817 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 818 * expression</a> with the specified set of namespace prefixes and URIs 819 * 820 * @param text the expression to be evaluated 821 * @param namespaces the namespace prefix and URIs to use 822 * @return the builder to continue processing the DSL 823 */ 824 public T xpath(String text, Map<String, String> namespaces) { 825 XPathExpression expression = new XPathExpression(text); 826 expression.setNamespaces(namespaces); 827 setExpressionType(expression); 828 return result; 829 } 830 831 /** 832 * Evaluates an <a 833 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 834 * 835 * @param text the expression to be evaluated 836 * @return the builder to continue processing the DSL 837 */ 838 public T xquery(String text) { 839 return expression(new XQueryExpression(text)); 840 } 841 842 /** 843 * Evaluates an <a href="http://camel.apache.org/xquery.html">XQuery 844 * expression</a> 845 * 846 * @param text the expression to be evaluated 847 * @param headerName the name of the header to apply the expression to 848 * @return the builder to continue processing the DSL 849 */ 850 public T xquery(String text, String headerName) { 851 XQueryExpression expression = new XQueryExpression(text); 852 expression.setHeaderName(headerName); 853 return expression(expression); 854 } 855 856 /** 857 * Evaluates an <a 858 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 859 * with the specified result type 860 * 861 * @param text the expression to be evaluated 862 * @param resultType the return type expected by the expression 863 * @return the builder to continue processing the DSL 864 */ 865 public T xquery(String text, Class<?> resultType) { 866 XQueryExpression expression = new XQueryExpression(text); 867 expression.setResultType(resultType); 868 setExpressionType(expression); 869 return result; 870 } 871 872 873 /** 874 * Evaluates an <a 875 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 876 * with the specified result type 877 * 878 * @param text the expression to be evaluated 879 * @param resultType the return type expected by the expression 880 * @param headerName the name of the header to apply the expression to 881 * @return the builder to continue processing the DSL 882 */ 883 public T xquery(String text, Class<?> resultType, String headerName) { 884 XQueryExpression expression = new XQueryExpression(text); 885 expression.setHeaderName(headerName); 886 setExpressionType(expression); 887 return result; 888 } 889 890 /** 891 * Evaluates an <a 892 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 893 * with the specified result type and set of namespace prefixes and URIs 894 * 895 * @param text the expression to be evaluated 896 * @param resultType the return type expected by the expression 897 * @param namespaces the namespace prefix and URIs to use 898 * @return the builder to continue processing the DSL 899 */ 900 public T xquery(String text, Class<?> resultType, Namespaces namespaces) { 901 return xquery(text, resultType, namespaces.getNamespaces()); 902 } 903 904 /** 905 * Evaluates an <a 906 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 907 * with the specified result type and set of namespace prefixes and URIs 908 * 909 * @param text the expression to be evaluated 910 * @param resultType the return type expected by the expression 911 * @param namespaces the namespace prefix and URIs to use 912 * @param headerName the name of the header to apply the expression to 913 * @return the builder to continue processing the DSL 914 */ 915 public T xquery(String text, Class<?> resultType, Namespaces namespaces, String headerName) { 916 XQueryExpression expression = new XQueryExpression(text); 917 expression.setResultType(resultType); 918 expression.setNamespaces(namespaces.getNamespaces()); 919 expression.setHeaderName(headerName); 920 setExpressionType(expression); 921 return result; 922 } 923 924 925 926 /** 927 * Evaluates an <a 928 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 929 * with the specified result type and set of namespace prefixes and URIs 930 * 931 * @param text the expression to be evaluated 932 * @param resultType the return type expected by the expression 933 * @param namespaces the namespace prefix and URIs to use 934 * @return the builder to continue processing the DSL 935 */ 936 public T xquery(String text, Class<?> resultType, Map<String, String> namespaces) { 937 XQueryExpression expression = new XQueryExpression(text); 938 expression.setResultType(resultType); 939 expression.setNamespaces(namespaces); 940 setExpressionType(expression); 941 return result; 942 } 943 944 /** 945 * Evaluates an <a 946 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 947 * with the specified set of namespace prefixes and URIs 948 * 949 * @param text the expression to be evaluated 950 * @param namespaces the namespace prefix and URIs to use 951 * @return the builder to continue processing the DSL 952 */ 953 public T xquery(String text, Namespaces namespaces) { 954 return xquery(text, namespaces.getNamespaces()); 955 } 956 957 /** 958 * Evaluates an <a 959 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 960 * with the specified set of namespace prefixes and URIs 961 * 962 * @param text the expression to be evaluated 963 * @param namespaces the namespace prefix and URIs to use 964 * @return the builder to continue processing the DSL 965 */ 966 public T xquery(String text, Map<String, String> namespaces) { 967 XQueryExpression expression = new XQueryExpression(text); 968 expression.setNamespaces(namespaces); 969 setExpressionType(expression); 970 return result; 971 } 972 973 /** 974 * Evaluates a given language name with the expression text 975 * 976 * @param language the name of the language 977 * @param expression the expression in the given language 978 * @return the builder to continue processing the DSL 979 */ 980 public T language(String language, String expression) { 981 LanguageExpression exp = new LanguageExpression(language, expression); 982 setExpressionType(exp); 983 return result; 984 } 985 986 // Properties 987 // ------------------------------------------------------------------------- 988 989 public Expression getExpressionValue() { 990 return expressionValue; 991 } 992 993 public void setExpressionValue(Expression expressionValue) { 994 this.expressionValue = expressionValue; 995 } 996 997 public ExpressionDefinition getExpressionType() { 998 return expressionType; 999 } 1000 1001 public void setExpressionType(ExpressionDefinition expressionType) { 1002 this.expressionType = expressionType; 1003 } 1004 1005 protected Expression createExpression(CamelContext camelContext) { 1006 if (getExpressionValue() == null) { 1007 if (getExpressionType() != null) { 1008 setExpressionValue(getExpressionType().createExpression(camelContext)); 1009 } else { 1010 throw new IllegalStateException("No expression value configured"); 1011 } 1012 } 1013 return getExpressionValue(); 1014 } 1015 1016 protected void configureExpression(CamelContext camelContext, Expression expression) { 1017 } 1018 1019}