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.Expression; 022 import org.apache.camel.builder.xml.Namespaces; 023 import org.apache.camel.model.ExpressionNode; 024 import org.apache.camel.model.language.ExpressionDefinition; 025 026 /** 027 * Represents an expression clause within the DSL which when the expression is 028 * complete the clause continues to another part of the DSL 029 * 030 * @version 031 */ 032 public class ExpressionClause<T> extends ExpressionDefinition { 033 private ExpressionClauseSupport<T> delegate; 034 035 public ExpressionClause(T result) { 036 this.delegate = new ExpressionClauseSupport<T>(result); 037 } 038 039 public static <T extends ExpressionNode> ExpressionClause<T> createAndSetExpression(T result) { 040 ExpressionClause<T> clause = new ExpressionClause<T>(result); 041 result.setExpression(clause); 042 return clause; 043 } 044 045 // Helper expressions 046 // ------------------------------------------------------------------------- 047 048 /** 049 * Specify an {@link Expression} instance 050 */ 051 public T expression(Expression expression) { 052 return delegate.expression(expression); 053 } 054 055 /** 056 * Specify the constant expression value 057 */ 058 public T constant(Object value) { 059 return delegate.constant(value); 060 } 061 062 /** 063 * An expression of the exchange 064 */ 065 public T exchange() { 066 return delegate.exchange(); 067 } 068 069 /** 070 * An expression of an inbound message 071 */ 072 public T inMessage() { 073 return delegate.inMessage(); 074 } 075 076 /** 077 * An expression of an inbound message 078 */ 079 public T outMessage() { 080 return delegate.outMessage(); 081 } 082 083 /** 084 * An expression of an inbound message body 085 */ 086 public T body() { 087 return delegate.body(); 088 } 089 090 /** 091 * An expression of an inbound message body converted to the expected type 092 */ 093 public T body(Class<?> expectedType) { 094 return delegate.body(expectedType); 095 } 096 097 /** 098 * An expression of an outbound message body 099 */ 100 public T outBody() { 101 return delegate.outBody(); 102 } 103 104 /** 105 * An expression of an outbound message body converted to the expected type 106 */ 107 public T outBody(Class<?> expectedType) { 108 return delegate.outBody(expectedType); 109 } 110 111 /** 112 * An expression of an inbound message header of the given name 113 */ 114 public T header(String name) { 115 return delegate.header(name); 116 } 117 118 /** 119 * An expression of the inbound headers 120 */ 121 public T headers() { 122 return delegate.headers(); 123 } 124 125 /** 126 * An expression of an outbound message header of the given name 127 */ 128 public T outHeader(String name) { 129 return delegate.outHeader(name); 130 } 131 132 /** 133 * An expression of the outbound headers 134 */ 135 public T outHeaders() { 136 return delegate.outHeaders(); 137 } 138 139 /** 140 * An expression of the inbound message attachments 141 */ 142 public T attachments() { 143 return delegate.attachments(); 144 } 145 146 /** 147 * An expression of an exchange property of the given name 148 */ 149 public T property(String name) { 150 return delegate.property(name); 151 } 152 153 /** 154 * An expression of the exchange properties 155 */ 156 public T properties() { 157 return delegate.properties(); 158 } 159 160 // Languages 161 // ------------------------------------------------------------------------- 162 163 /** 164 * Evaluates an expression using the <a 165 * href="http://camel.apache.org/bean-language.html>bean language</a> 166 * which basically means the bean is invoked to determine the expression 167 * value. 168 * 169 * @param bean the name of the bean looked up the registry 170 * @return the builder to continue processing the DSL 171 */ 172 public T method(String bean) { 173 return delegate.method(bean); 174 } 175 176 /** 177 * Evaluates an expression using the <a 178 * href="http://camel.apache.org/bean-language.html>bean language</a> 179 * which basically means the bean is invoked to determine the expression 180 * value. 181 * 182 * @param instance the instance of the bean 183 * @return the builder to continue processing the DSL 184 */ 185 public T method(Object instance) { 186 return delegate.method(instance); 187 } 188 189 /** 190 * Evaluates an expression using the <a 191 * href="http://camel.apache.org/bean-language.html>bean language</a> 192 * which basically means the bean is invoked to determine the expression 193 * value. 194 * 195 * @param beanType the Class of the bean which we want to invoke 196 * @return the builder to continue processing the DSL 197 */ 198 public T method(Class<?> beanType) { 199 return delegate.method(beanType); 200 } 201 202 /** 203 * Evaluates an expression using the <a 204 * href="http://camel.apache.org/bean-language.html>bean language</a> 205 * which basically means the bean is invoked to determine the expression 206 * value. 207 * 208 * @param bean the name of the bean looked up the registry 209 * @param method the name of the method to invoke on the bean 210 * @return the builder to continue processing the DSL 211 */ 212 public T method(String bean, String method) { 213 return delegate.method(bean, method); 214 } 215 216 /** 217 * Evaluates an expression using the <a 218 * href="http://camel.apache.org/bean-language.html>bean language</a> 219 * which basically means the bean is invoked to determine the expression 220 * value. 221 * 222 * @param instance the instance of the bean 223 * @param method the name of the method to invoke on the bean 224 * @return the builder to continue processing the DSL 225 */ 226 public T method(Object instance, String method) { 227 return delegate.method(instance, method); 228 } 229 230 /** 231 * Evaluates an expression using the <a 232 * href="http://camel.apache.org/bean-language.html>bean language</a> 233 * which basically means the bean is invoked to determine the expression 234 * value. 235 * 236 * @param beanType the Class of the bean which we want to invoke 237 * @param method the name of the method to invoke on the bean 238 * @return the builder to continue processing the DSL 239 */ 240 public T method(Class<?> beanType, String method) { 241 return delegate.method(beanType, method); 242 } 243 244 /** 245 * Evaluates the <a href="http://camel.apache.org/el.html">EL 246 * Language from JSP and JSF</a> using the <a 247 * href="http://camel.apache.org/juel.html">JUEL library</a> 248 * 249 * @param text the expression to be evaluated 250 * @return the builder to continue processing the DSL 251 */ 252 public T el(String text) { 253 return delegate.el(text); 254 } 255 256 /** 257 * Evaluates a <a href="http://camel.apache.org/groovy.html">Groovy 258 * expression</a> 259 * 260 * @param text the expression to be evaluated 261 * @return the builder to continue processing the DSL 262 */ 263 public T groovy(String text) { 264 return delegate.groovy(text); 265 } 266 267 /** 268 * Evaluates a <a 269 * href="http://camel.apache.org/java-script.html">JavaScript 270 * expression</a> 271 * 272 * @param text the expression to be evaluated 273 * @return the builder to continue processing the DSL 274 */ 275 public T javaScript(String text) { 276 return delegate.javaScript(text); 277 } 278 279 /** 280 * Evaluates a <a href="http://commons.apache.org/jxpath/">JXPath expression</a> 281 * 282 * @param text the expression to be evaluated 283 * @return the builder to continue processing the DSL 284 */ 285 public T jxpath(String text) { 286 return delegate.jxpath(text); 287 } 288 289 /** 290 * Evaluates a <a href="http://commons.apache.org/jxpath/">JXPath expression</a> 291 * 292 * @param text the expression to be evaluated 293 * @param lenient to configure whether lenient is in use or not 294 * @return the builder to continue processing the DSL 295 */ 296 public T jxpath(String text, boolean lenient) { 297 return delegate.jxpath(text, lenient); 298 } 299 300 /** 301 * Evaluates an <a href="http://camel.apache.org/ognl.html">OGNL 302 * expression</a> 303 * 304 * @param text the expression to be evaluated 305 * @return the builder to continue processing the DSL 306 */ 307 public T ognl(String text) { 308 return delegate.ognl(text); 309 } 310 311 /** 312 * Evaluates a <a href="http://camel.apache.org/mvel.html">MVEL 313 * expression</a> 314 * 315 * @param text the expression to be evaluated 316 * @return the builder to continue processing the DSL 317 */ 318 public T mvel(String text) { 319 return delegate.mvel(text); 320 } 321 322 /** 323 * Evaluates a <a href="http://camel.apache.org/php.html">PHP 324 * expression</a> 325 * 326 * @param text the expression to be evaluated 327 * @return the builder to continue processing the DSL 328 */ 329 public T php(String text) { 330 return delegate.php(text); 331 } 332 333 /** 334 * Evaluates a <a href="http://camel.apache.org/python.html">Python 335 * expression</a> 336 * 337 * @param text the expression to be evaluated 338 * @return the builder to continue processing the DSL 339 */ 340 public T python(String text) { 341 return delegate.python(text); 342 } 343 344 /** 345 * Evaluates a <a href="http://camel.apache.org/ref-language.html">Ref 346 * expression</a> 347 * 348 * @param ref refers to the expression to be evaluated 349 * @return the builder to continue processing the DSL 350 */ 351 public T ref(String ref) { 352 return delegate.ref(ref); 353 } 354 355 /** 356 * Evaluates a <a href="http://camel.apache.org/ruby.html">Ruby 357 * expression</a> 358 * 359 * @param text the expression to be evaluated 360 * @return the builder to continue processing the DSL 361 */ 362 public T ruby(String text) { 363 return delegate.ruby(text); 364 } 365 366 /** 367 * Evaluates an <a href="http://camel.apache.org/sql.html">SQL 368 * expression</a> 369 * 370 * @param text the expression to be evaluated 371 * @return the builder to continue processing the DSL 372 */ 373 public T sql(String text) { 374 return delegate.sql(text); 375 } 376 377 /** 378 * Evaluates a <a href="http://camel.apache.org/spel.html">SpEL 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 spel(String text) { 385 return delegate.spel(text); 386 } 387 388 /** 389 * Evaluates a <a href="http://camel.apache.org/simple.html">Simple 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 simple(String text) { 396 return delegate.simple(text); 397 } 398 399 /** 400 * Evaluates a <a href="http://camel.apache.org/simple.html">Simple 401 * expression</a> 402 * 403 * @param text the expression to be evaluated 404 * @param resultType the result type 405 * @return the builder to continue processing the DSL 406 */ 407 public T simple(String text, Class<?> resultType) { 408 return delegate.simple(text, resultType); 409 } 410 411 /** 412 * Evaluates a token expression on the message body 413 * 414 * @param token the token 415 * @return the builder to continue processing the DSL 416 */ 417 public T tokenize(String token) { 418 return delegate.tokenize(token); 419 } 420 421 /** 422 * Evaluates a token expression on the message body 423 * 424 * @param token the token 425 * @param regex whether the token is a regular expression or not 426 * @return the builder to continue processing the DSL 427 */ 428 public T tokenize(String token, boolean regex) { 429 return delegate.tokenize(token, regex); 430 } 431 432 /** 433 * Evaluates a token expression on the message body 434 * 435 * @param token the token 436 * @param regex whether the token is a regular expression or not 437 * @param group to group by the given number 438 * @return the builder to continue processing the DSL 439 */ 440 public T tokenize(String token, boolean regex, int group) { 441 return delegate.tokenize(token, regex); 442 } 443 444 /** 445 * Evaluates a token expression on the message body 446 * 447 * @param token the token 448 * @param group to group by the given number 449 * @return the builder to continue processing the DSL 450 */ 451 public T tokenize(String token, int group) { 452 return delegate.tokenize(token, group); 453 } 454 455 /** 456 * Evaluates a token expression on the given header 457 * 458 * @param token the token 459 * @param headerName name of header to tokenize 460 * @return the builder to continue processing the DSL 461 */ 462 public T tokenize(String token, String headerName) { 463 return delegate.tokenize(token, headerName); 464 } 465 466 /** 467 * Evaluates a token expression on the given header 468 * 469 * @param token the token 470 * @param headerName name of header to tokenize 471 * @param regex whether the token is a regular expression or not 472 * @return the builder to continue processing the DSL 473 */ 474 public T tokenize(String token, String headerName, boolean regex) { 475 return delegate.tokenize(token, headerName, regex); 476 } 477 478 /** 479 * Evaluates a token pair expression on the message body. 480 * <p/> 481 * Tokens is not included. 482 * 483 * @param startToken the start token 484 * @param endToken the end token 485 * @return the builder to continue processing the DSL 486 */ 487 public T tokenizePair(String startToken, String endToken) { 488 return tokenizePair(startToken, endToken, false); 489 } 490 491 /** 492 * Evaluates a token pair expression on the message body 493 * 494 * @param startToken the start token 495 * @param endToken the end token 496 * @param includeTokens whether to include tokens 497 * @return the builder to continue processing the DSL 498 */ 499 public T tokenizePair(String startToken, String endToken, boolean includeTokens) { 500 return delegate.tokenizePair(startToken, endToken, includeTokens); 501 } 502 503 /** 504 * Evaluates a XML token expression on the message body with XML content 505 * 506 * @param tagName the the tag name of the child nodes to tokenize 507 * @return the builder to continue processing the DSL 508 */ 509 public T tokenizeXML(String tagName) { 510 return tokenizeXML(tagName, null); 511 } 512 513 /** 514 * Evaluates a XML token expression on the message body with XML content 515 * 516 * @param tagName the the tag name of the child nodes to tokenize 517 * @param group to group by the given number 518 * @return the builder to continue processing the DSL 519 */ 520 public T tokenizeXML(String tagName, int group) { 521 return tokenizeXML(tagName, null, group); 522 } 523 524 /** 525 * Evaluates a token pair expression on the message body with XML content 526 * 527 * @param tagName the the tag name of the child nodes to tokenize 528 * @param inheritNamespaceTagName parent or root tag name that contains namespace(s) to inherit 529 * @return the builder to continue processing the DSL 530 */ 531 public T tokenizeXML(String tagName, String inheritNamespaceTagName) { 532 return tokenizeXML(tagName, inheritNamespaceTagName, 0); 533 } 534 535 /** 536 * Evaluates a token pair expression on the message body with XML content 537 * 538 * @param tagName the the tag name of the child nodes to tokenize 539 * @param inheritNamespaceTagName parent or root tag name that contains namespace(s) to inherit 540 * @param group to group by the given number 541 * @return the builder to continue processing the DSL 542 */ 543 public T tokenizeXML(String tagName, String inheritNamespaceTagName, int group) { 544 return delegate.tokenizeXMLPair(tagName, inheritNamespaceTagName, group); 545 } 546 547 /** 548 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 549 * expression</a> 550 * 551 * @param text the expression to be evaluated 552 * @return the builder to continue processing the DSL 553 */ 554 public T xpath(String text) { 555 return delegate.xpath(text); 556 } 557 558 /** 559 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 560 * expression</a> with the specified result type 561 * 562 * @param text the expression to be evaluated 563 * @param resultType the return type expected by the expression 564 * @return the builder to continue processing the DSL 565 */ 566 public T xpath(String text, Class<?> resultType) { 567 return delegate.xpath(text, resultType); 568 } 569 570 /** 571 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 572 * expression</a> with the specified result type and set of namespace 573 * prefixes and URIs 574 * 575 * @param text the expression to be evaluated 576 * @param resultType the return type expected by the expression 577 * @param namespaces the namespace prefix and URIs to use 578 * @return the builder to continue processing the DSL 579 */ 580 public T xpath(String text, Class<?> resultType, Namespaces namespaces) { 581 return delegate.xpath(text, resultType, namespaces); 582 } 583 584 /** 585 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 586 * expression</a> with the specified result type and set of namespace 587 * prefixes and URIs 588 * 589 * @param text the expression to be evaluated 590 * @param resultType the return type expected by the expression 591 * @param namespaces the namespace prefix and URIs to use 592 * @return the builder to continue processing the DSL 593 */ 594 public T xpath(String text, Class<?> resultType, Map<String, String> namespaces) { 595 return delegate.xpath(text, resultType, namespaces); 596 } 597 598 /** 599 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 600 * expression</a> with the specified set of namespace prefixes and URIs 601 * 602 * @param text the expression to be evaluated 603 * @param namespaces the namespace prefix and URIs to use 604 * @return the builder to continue processing the DSL 605 */ 606 public T xpath(String text, Namespaces namespaces) { 607 return delegate.xpath(text, namespaces); 608 } 609 610 /** 611 * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath 612 * expression</a> with the specified set of namespace prefixes and URIs 613 * 614 * @param text the expression to be evaluated 615 * @param namespaces the namespace prefix and URIs to use 616 * @return the builder to continue processing the DSL 617 */ 618 public T xpath(String text, Map<String, String> namespaces) { 619 return delegate.xpath(text, namespaces); 620 } 621 622 /** 623 * Evaluates an <a 624 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 625 * 626 * @param text the expression to be evaluated 627 * @return the builder to continue processing the DSL 628 */ 629 public T xquery(String text) { 630 return delegate.xquery(text); 631 } 632 633 /** 634 * Evaluates an <a 635 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 636 * with the specified result type 637 * 638 * @param text the expression to be evaluated 639 * @param resultType the return type expected by the expression 640 * @return the builder to continue processing the DSL 641 */ 642 public T xquery(String text, Class<?> resultType) { 643 return delegate.xquery(text, resultType); 644 } 645 646 /** 647 * Evaluates an <a 648 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 649 * with the specified result type and set of namespace prefixes and URIs 650 * 651 * @param text the expression to be evaluated 652 * @param resultType the return type expected by the expression 653 * @param namespaces the namespace prefix and URIs to use 654 * @return the builder to continue processing the DSL 655 */ 656 public T xquery(String text, Class<?> resultType, Namespaces namespaces) { 657 return delegate.xquery(text, resultType, namespaces); 658 } 659 660 /** 661 * Evaluates an <a 662 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 663 * with the specified result type and set of namespace prefixes and URIs 664 * 665 * @param text the expression to be evaluated 666 * @param resultType the return type expected by the expression 667 * @param namespaces the namespace prefix and URIs to use 668 * @return the builder to continue processing the DSL 669 */ 670 public T xquery(String text, Class<?> resultType, Map<String, String> namespaces) { 671 return delegate.xquery(text, resultType, namespaces); 672 } 673 674 /** 675 * Evaluates an <a 676 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 677 * with the specified set of namespace prefixes and URIs 678 * 679 * @param text the expression to be evaluated 680 * @param namespaces the namespace prefix and URIs to use 681 * @return the builder to continue processing the DSL 682 */ 683 public T xquery(String text, Namespaces namespaces) { 684 return delegate.xquery(text, namespaces); 685 } 686 687 /** 688 * Evaluates an <a 689 * href="http://camel.apache.org/xquery.html">XQuery expression</a> 690 * with the specified set of namespace prefixes and URIs 691 * 692 * @param text the expression to be evaluated 693 * @param namespaces the namespace prefix and URIs to use 694 * @return the builder to continue processing the DSL 695 */ 696 public T xquery(String text, Map<String, String> namespaces) { 697 return delegate.xquery(text, namespaces); 698 } 699 700 /** 701 * Evaluates a given language name with the expression text 702 * 703 * @param language the name of the language 704 * @param expression the expression in the given language 705 * @return the builder to continue processing the DSL 706 */ 707 public T language(String language, String expression) { 708 return delegate.language(language, expression); 709 } 710 711 // Properties 712 // ------------------------------------------------------------------------- 713 714 @Override 715 public Expression getExpressionValue() { 716 return delegate.getExpressionValue(); 717 } 718 719 @Override 720 protected void setExpressionValue(Expression expressionValue) { 721 delegate.setExpressionValue(expressionValue); 722 } 723 724 @Override 725 public ExpressionDefinition getExpressionType() { 726 return delegate.getExpressionType(); 727 } 728 729 @Override 730 protected void setExpressionType(ExpressionDefinition expressionType) { 731 delegate.setExpressionType(expressionType); 732 } 733 }