This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 81ec7c1 CAMEL-15704: camel-csimple - Compiled simple language. 81ec7c1 is described below commit 81ec7c19a8c2910fd3e82304d8868fe7362dce18 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Dec 3 11:24:33 2020 +0100 CAMEL-15704: camel-csimple - Compiled simple language. --- .../modules/languages/pages/csimple-language.adoc | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/core/camel-core-languages/src/main/docs/modules/languages/pages/csimple-language.adoc b/core/camel-core-languages/src/main/docs/modules/languages/pages/csimple-language.adoc index 3c2bffd..8087fe0 100644 --- a/core/camel-core-languages/src/main/docs/modules/languages/pages/csimple-language.adoc +++ b/core/camel-core-languages/src/main/docs/modules/languages/pages/csimple-language.adoc @@ -30,6 +30,51 @@ In other words the simple language is using _duck typing_ (if it looks like a du and csimple is using Java type (typesafety). If there is a type error then simple will report this at runtime, and with csimple there will be a Java compilation error. +=== Additional CSimple functions + +The csimple language includes some additional functions to support common use-cases working with `Collection`, `Map` or array types. +The following functions _bodyAsIndex_, _headerAsIndex_, and _exchangePropertyAsIndex_ is used for these use-cases as they are typed. + +[width="100%",cols="10%,10%,80%",options="header",] +|======================================================================= +|Function |Type |Description + +|bodyAsIndex(_type_, _index_) |Type | To be used for collecting the body from an existing `Collection`, `Map` or array (lookup by the index) +and then converting the body to the given type determined by its classname. The converted body can be null. + +|mandatoryBodyAsIndex(_type_, _index_) |Type | To be used for collecting the body from an existing `Collection`, `Map` or array (lookup by the index) +and then converting the body to the given type determined by its classname. Expects the body to be not null. + +|headerAsIndex(_key_, _type_, _index_) |Type | To be used for collecting a header from an existing `Collection`, `Map` or array (lookup by the index) +and then converting the header value to the given type determined by its classname. The converted header can be null. + +|mandatoryHeaderAsIndex(_key_, _type_, _index_) |Type | To be used for collecting a header from an existing `Collection`, `Map` or array (lookup by the index) +and then converting the header value to the given type determined by its classname. Expects the header to be not null. + +|exchangePropertyAsIndex(_key_, _type_, _index_) |Type | To be used for collecting an exchange property from an existing `Collection`, `Map` or array (lookup by the index) +and then converting the exchange property to the given type determined by its classname. The converted exchange property can be null. + +|mandatoryExchangePropertyAsIndex(_key_, _type_, _index_) |Type | To be used for collecting an exchange property from an existing `Collection`, `Map` or array (lookup by the index) +and then converting the exchange property to the given type determined by its classname. Expects the exchange property to be not null. + +|======================================================================= + +For example given the following simple expression: + +==== +Hello ${body[0].name} +==== + +This script has no type information, and the simple language will resolve this at runtime, by introspecting the message body +and if it's a collection based then lookup the first element, and then invoke a method named `getName` via reflection. + +In csimple (compiled) we want to pre compile this and therefore the end user must provide type information with the _bodyAsIndex_ function: + +==== +Hello ${bodyAsIndex(com.foo.MyUser, 0).name} +==== + + == Compilation The csimple language is parsed into regular Java source code and compiled together with all the other source code, or it can be compiled once during bootstrap via the `camel-csimple-joor` module.