You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/11/21 09:49:27 UTC
(camel-kamelets-examples) branch main updated: CAMEL-20134: Added example of inlined java code for creating bean using a builder class.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets-examples.git
The following commit(s) were added to refs/heads/main by this push:
new 216d290 CAMEL-20134: Added example of inlined java code for creating bean using a builder class.
216d290 is described below
commit 216d2907e0142a527567b64d92880a1eed5ab871
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 21 10:49:01 2023 +0100
CAMEL-20134: Added example of inlined java code for creating bean using a builder class.
---
jbang/bean-inlined-code/Customer.java | 36 +++++++++++++++
jbang/bean-inlined-code/CustomerBuilder.java | 34 ++++++++++++++
jbang/bean-inlined-code/README.adoc | 67 ++++++++++++++++++++++++++++
jbang/bean-inlined-code/myapp.camel.yaml | 17 +++++++
4 files changed, 154 insertions(+)
diff --git a/jbang/bean-inlined-code/Customer.java b/jbang/bean-inlined-code/Customer.java
new file mode 100644
index 0000000..0741bbb
--- /dev/null
+++ b/jbang/bean-inlined-code/Customer.java
@@ -0,0 +1,36 @@
+package com.mycompany;
+
+public final class Customer {
+
+ private String name;
+ private String street;
+ private int zip;
+ private boolean gold;
+
+ Customer(String name, String street, int zip, boolean gold) {
+ this.name = name;
+ this.street = street;
+ this.zip = zip;
+ this.gold = gold;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getStreet() {
+ return street;
+ }
+
+ public int getZip() {
+ return zip;
+ }
+
+ public boolean isGold() {
+ return gold;
+ }
+
+ public String summary() {
+ return name + " at " + street + " (" + zip + ") is " + (gold ? "gold" : "silver") + " customer";
+ }
+}
\ No newline at end of file
diff --git a/jbang/bean-inlined-code/CustomerBuilder.java b/jbang/bean-inlined-code/CustomerBuilder.java
new file mode 100644
index 0000000..1e3b3dd
--- /dev/null
+++ b/jbang/bean-inlined-code/CustomerBuilder.java
@@ -0,0 +1,34 @@
+package com.mycompany;
+
+public final class CustomerBuilder {
+
+ private String name;
+ private String street;
+ private int zip;
+ private boolean gold;
+
+ public CustomerBuilder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public CustomerBuilder street(String street) {
+ this.street = street;
+ return this;
+ }
+
+ public CustomerBuilder zip(int zip) {
+ this.zip = zip;
+ return this;
+ }
+
+ public CustomerBuilder gold(boolean gold) {
+ this.gold = gold;
+ return this;
+ }
+
+ public Customer build() {
+ return new Customer(name, street, zip, gold);
+ }
+
+}
\ No newline at end of file
diff --git a/jbang/bean-inlined-code/README.adoc b/jbang/bean-inlined-code/README.adoc
new file mode 100644
index 0000000..bc246a0
--- /dev/null
+++ b/jbang/bean-inlined-code/README.adoc
@@ -0,0 +1,67 @@
+== YAML with inlined Java code
+
+An example, of using YAML DSL with inlined Java code create a bean.
+This shows the full flexibility by allowing to write a little bit of Java code
+directly inlined in YAML DSL to make it possible to create and configure the bean
+anyay you need, with the power of low-code prgramming.
+
+
+=== Install JBang
+
+First install JBang according to https://www.jbang.dev
+
+When JBang is installed then you should be able to run from a shell:
+
+[source,sh]
+----
+$ jbang --version
+----
+
+This will output the version of JBang.
+
+To run this example you can either install Camel on JBang via:
+
+[source,sh]
+----
+$ jbang app install camel@apache/camel
+----
+
+Which allows to run CamelJBang with `camel` as shown below.
+
+=== How to run
+
+Then you can run this example using:
+
+[source,sh]
+----
+$ camel run *
+----
+
+Or run with JBang using the longer command line (without installing camel as app in JBang):
+
+[source,sh]
+----
+$ jbang camel@apache/camel run *
+----
+
+
+=== Live reload
+
+You can run the example in dev mode which allows you to edit the example,
+and hot-reload when the file is saved.
+
+[source,sh]
+----
+$ camel run * --dev
+----
+
+
+=== Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+https://camel.apache.org/community/support/[let us know].
+
+We also love contributors, so
+https://camel.apache.org/community/contributing/[get involved] :-)
+
+The Camel riders!
diff --git a/jbang/bean-inlined-code/myapp.camel.yaml b/jbang/bean-inlined-code/myapp.camel.yaml
new file mode 100644
index 0000000..7507283
--- /dev/null
+++ b/jbang/bean-inlined-code/myapp.camel.yaml
@@ -0,0 +1,17 @@
+- beans:
+ - name: myCustomer
+ type: com.mycompany.Customer
+ scriptLanguage: joor
+ script: |
+ var b = new com.mycompany.CustomerBuilder();
+ b.name('Acme').street('Somestreet 42').zip(90210).gold(true);
+ return b.build();
+- from:
+ uri: "timer:yaml"
+ parameters:
+ period: "5000"
+ steps:
+ - bean:
+ ref: myCustomer
+ method: summary
+ - log: "${body}"