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 2016/06/04 09:05:59 UTC

[2/2] camel git commit: CAMEL-10021: Class component - Should allow to call static method on class without ctr

CAMEL-10021: Class component - Should allow to call static method on class without ctr


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d71cd39c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d71cd39c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d71cd39c

Branch: refs/heads/camel-2.17.x
Commit: d71cd39ce31e962f9c4010d5ce40d74dc3001a92
Parents: a38f925
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Jun 4 10:28:27 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jun 4 11:05:48 2016 +0200

----------------------------------------------------------------------
 .../component/beanclass/ClassComponent.java     | 22 +++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d71cd39c/camel-core/src/main/java/org/apache/camel/component/beanclass/ClassComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/beanclass/ClassComponent.java b/camel-core/src/main/java/org/apache/camel/component/beanclass/ClassComponent.java
index 5372c0f..64c6f03 100644
--- a/camel-core/src/main/java/org/apache/camel/component/beanclass/ClassComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/beanclass/ClassComponent.java
@@ -22,6 +22,7 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.component.bean.BeanComponent;
 import org.apache.camel.component.bean.BeanHolder;
 import org.apache.camel.component.bean.ConstantBeanHolder;
+import org.apache.camel.component.bean.ConstantTypeBeanHolder;
 import org.apache.camel.util.IntrospectionSupport;
 
 /**
@@ -44,19 +45,30 @@ public class ClassComponent extends BeanComponent {
         // bean name is the FQN
         String name = endpoint.getBeanName();
         Class<?> clazz = getCamelContext().getClassResolver().resolveMandatoryClass(name);
-        // create bean
-        Object bean = getCamelContext().getInjector().newInstance(clazz);
 
         // the bean.xxx options is for the bean
         Map<String, Object> options = IntrospectionSupport.extractProperties(parameters, "bean.");
         endpoint.setParameters(options);
 
-        // now set additional properties on it
-        setProperties(bean, options);
+        BeanHolder holder;
+
+        // if there is options then we need to create a bean instance
+        if (!options.isEmpty()) {
+            // create bean
+            Object bean = getCamelContext().getInjector().newInstance(clazz);
+
+            // now set additional properties on it
+            setProperties(bean, options);
+
+            holder = new ConstantBeanHolder(bean, getCamelContext());
+        } else {
+            // otherwise refer to the type
+            holder = new ConstantTypeBeanHolder(clazz, getCamelContext());
+        }
+
         validateParameters(uri, options, null);
 
         // and register the bean as a holder on the endpoint
-        BeanHolder holder = new ConstantBeanHolder(bean, getCamelContext());
         endpoint.setBeanHolder(holder);
 
         return endpoint;