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-examples.git


The following commit(s) were added to refs/heads/master by this push:
     new 738c67f  Tiny example with source code generated configurer
738c67f is described below

commit 738c67f327d176ab345576c47608368d8296ceae
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon Apr 13 09:53:49 2020 +0200

    Tiny example with source code generated configurer
---
 examples/camel-example-main-tiny/pom.xml           | 42 ++++++++++++++++----
 examples/camel-example-main-tiny/readme.adoc       |  6 +--
 .../org/apache/camel/example/MyBeanConfigurer.java | 45 ++++++++++++++++++++++
 .../services/org/apache/camel/configurer/MyBean    |  2 +
 .../org/apache/camel/example/MyApplication.java    |  3 --
 .../main/java/org/apache/camel/example/MyBean.java | 14 ++++---
 .../org/apache/camel/example/MyConfiguration.java  | 37 ------------------
 .../org/apache/camel/example/MyRouteBuilder.java   |  2 +-
 .../src/main/resources/application.properties      |  5 ++-
 9 files changed, 95 insertions(+), 61 deletions(-)

diff --git a/examples/camel-example-main-tiny/pom.xml 
b/examples/camel-example-main-tiny/pom.xml
index dacd76b..b5f331e 100644
--- a/examples/camel-example-main-tiny/pom.xml
+++ b/examples/camel-example-main-tiny/pom.xml
@@ -93,16 +93,44 @@
 
     <build>
         <plugins>
-            <!-- Run 'mvn camel-main:generate' -->
-            <!-- generate autowire.properties file that can automatic detect 
resources
-                 from the classpath to make convention over configuration for 
Camel components -->
+            <!-- generate source code for configurer classes, which avoids 
reflection -->
             <plugin>
                 <groupId>org.apache.camel</groupId>
-                <artifactId>camel-main-maven-plugin</artifactId>
+                <artifactId>camel-package-maven-plugin</artifactId>
                 <version>${camel.version}</version>
-                <configuration>
-                    <logClasspath>false</logClasspath>
-                </configuration>
+                <executions>
+                    <execution>
+                        <id>generate</id>
+                        <goals>
+                            <goal>generate-component</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <!-- include source code generated to maven sources paths -->
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>3.1.0</version>
+                <executions>
+                    <execution>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                            <goal>add-resource</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>src/generated/java</source>
+                            </sources>
+                            <resources>
+                                <resource>
+                                    
<directory>src/generated/resources</directory>
+                                </resource>
+                            </resources>
+                        </configuration>
+                    </execution>
+                </executions>
             </plugin>
         </plugins>
     </build>
diff --git a/examples/camel-example-main-tiny/readme.adoc 
b/examples/camel-example-main-tiny/readme.adoc
index f6f7ce7..dd99121 100644
--- a/examples/camel-example-main-tiny/readme.adoc
+++ b/examples/camel-example-main-tiny/readme.adoc
@@ -5,11 +5,7 @@ on the classpath as possible. For more details see the 
`pom.xml` file.
 
 This example shows how to run Camel standalone via the built-in Main class.
 
-The example also demonstrates how you can configure the Camel application
-via Camel built-in dependency-injection that supports binding via the
-`@BindToRegistry`, `@BeanInject` and `@PropertyInject` annotations.
-
-Also notice how you can configure Camel in the `application.properties` file.
+Notice how you can configure Camel in the `application.properties` file.
 
 === How to run
 
diff --git 
a/examples/camel-example-main-tiny/src/generated/java/org/apache/camel/example/MyBeanConfigurer.java
 
b/examples/camel-example-main-tiny/src/generated/java/org/apache/camel/example/MyBeanConfigurer.java
new file mode 100644
index 0000000..73d4b8e
--- /dev/null
+++ 
b/examples/camel-example-main-tiny/src/generated/java/org/apache/camel/example/MyBeanConfigurer.java
@@ -0,0 +1,45 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.example;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.example.MyBean;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class MyBeanConfigurer extends 
org.apache.camel.support.component.PropertyConfigurerSupport implements 
GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+    @Override
+    public boolean configure(CamelContext camelContext, Object obj, String 
name, Object value, boolean ignoreCase) {
+        org.apache.camel.example.MyBean target = 
(org.apache.camel.example.MyBean) obj;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "hi":
+        case "Hi": target.setHi(property(camelContext, java.lang.String.class, 
value)); return true;
+        default: return false;
+        }
+    }
+
+    @Override
+    public Map<String, Object> getAllOptions(Object target) {
+        Map<String, Object> answer = new CaseInsensitiveMap();
+        answer.put("Hi", java.lang.String.class);
+        return answer;
+    }
+
+    @Override
+    public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+        org.apache.camel.example.MyBean target = 
(org.apache.camel.example.MyBean) obj;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "hi":
+        case "Hi": return target.getHi();
+        default: return null;
+        }
+    }
+}
+
diff --git 
a/examples/camel-example-main-tiny/src/generated/resources/META-INF/services/org/apache/camel/configurer/MyBean
 
b/examples/camel-example-main-tiny/src/generated/resources/META-INF/services/org/apache/camel/configurer/MyBean
new file mode 100644
index 0000000..24d3637
--- /dev/null
+++ 
b/examples/camel-example-main-tiny/src/generated/resources/META-INF/services/org/apache/camel/configurer/MyBean
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.example.MyBeanConfigurer
diff --git 
a/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyApplication.java
 
b/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyApplication.java
index c6214d0..8c1cc6a 100644
--- 
a/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyApplication.java
+++ 
b/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyApplication.java
@@ -29,9 +29,6 @@ public final class MyApplication {
     public static void main(String[] args) throws Exception {
         // use Camels Main class
         Main main = new Main();
-        // lets use a configuration class (you can specify multiple classes)
-        // (properties are automatic loaded from application.properties)
-        main.addConfigurationClass(MyConfiguration.class);
         // and add the routes (you can specify multiple classes)
         main.addRouteBuilder(MyRouteBuilder.class);
         // now keep the application running until the JVM is terminated (ctrl 
+ c or sigterm)
diff --git 
a/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyBean.java
 
b/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyBean.java
index 1e1bdb8..348a0a6 100644
--- 
a/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyBean.java
+++ 
b/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyBean.java
@@ -16,21 +16,23 @@
  */
 package org.apache.camel.example;
 
+import org.apache.camel.spi.Configurer;
+
+@Configurer
 public class MyBean {
 
     private String hi;
-    private String bye;
 
-    public MyBean(String hi, String bye) {
+    public String getHi() {
+        return hi;
+    }
+
+    public void setHi(String hi) {
         this.hi = hi;
-        this.bye = bye;
     }
 
     public String hello() {
         return hi + " how are you?";
     }
 
-    public String bye() {
-        return bye + " World";
-    }
 }
diff --git 
a/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyConfiguration.java
 
b/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyConfiguration.java
deleted file mode 100644
index 9c26fdd..0000000
--- 
a/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyConfiguration.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.example;
-
-import org.apache.camel.BindToRegistry;
-import org.apache.camel.PropertyInject;
-
-/**
- * Class to configure the Camel application.
- */
-public class MyConfiguration {
-
-    @BindToRegistry
-    public MyBean myBean(@PropertyInject("hi") String hi, 
@PropertyInject("bye") String bye) {
-        // this will create an instance of this bean with the name of the 
method (eg myBean)
-        return new MyBean(hi, bye);
-    }
-
-    public void configure() {
-        // this method is optional and can be removed if no additional 
configuration is needed.
-    }
-
-}
diff --git 
a/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyRouteBuilder.java
 
b/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyRouteBuilder.java
index 26971ba..185c9df 100644
--- 
a/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyRouteBuilder.java
+++ 
b/examples/camel-example-main-tiny/src/main/java/org/apache/camel/example/MyRouteBuilder.java
@@ -23,7 +23,7 @@ public class MyRouteBuilder extends RouteBuilder {
     @Override
     public void configure() throws Exception {
         from("timer:foo?period={{myPeriod}}")
-            .bean("myBean", "hello")
+            .bean("mybean", "hello")
             .log("${body}");
     }
 }
diff --git 
a/examples/camel-example-main-tiny/src/main/resources/application.properties 
b/examples/camel-example-main-tiny/src/main/resources/application.properties
index a58bbe6..61379fc 100644
--- a/examples/camel-example-main-tiny/src/main/resources/application.properties
+++ b/examples/camel-example-main-tiny/src/main/resources/application.properties
@@ -48,6 +48,7 @@ camel.main.file-configurations=src/main/data/*.properties
 # properties used in the route
 myPeriod = 1000
 
-# application properties
-hi = Hello
+# configure beans
+camel.beans.mybean = #class:org.apache.camel.example.MyBean
+camel.beans.mybean.hi = Hello
 

Reply via email to