camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1295579 - in /camel/trunk/camel-core/src/main/java/org/apache/camel/model: BeanDefinition.java ProcessorDefinition.java
Date Thu, 01 Mar 2012 14:20:20 GMT
Author: davsclaus
Date: Thu Mar  1 14:20:19 2012
New Revision: 1295579

URL: http://svn.apache.org/viewvc?rev=1295579&view=rev
Log:
CAMEL-5056: @deprecated not used fluent builders on bean def. Allow to set bean type by class.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanDefinition.java?rev=1295579&r1=1295578&r2=1295579&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanDefinition.java Thu Mar
 1 14:20:19 2012
@@ -30,7 +30,6 @@ import org.apache.camel.component.bean.C
 import org.apache.camel.component.bean.ConstantTypeBeanHolder;
 import org.apache.camel.component.bean.MethodNotFoundException;
 import org.apache.camel.component.bean.RegistryBean;
-import org.apache.camel.spi.Required;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.ObjectHelper;
@@ -50,6 +49,8 @@ public class BeanDefinition extends NoOu
     @XmlAttribute
     private String beanType;
     @XmlTransient
+    private Class<?> beanClass;
+    @XmlTransient
     private Object bean;
 
     public BeanDefinition() {
@@ -78,6 +79,8 @@ public class BeanDefinition extends NoOu
             return "ref:" + ref + methodText;
         } else if (bean != null) {
             return bean.toString();
+        } else if (beanClass != null) {
+            return beanClass.getName();
         } else if (beanType != null) {
             return beanType;
         } else {
@@ -99,7 +102,6 @@ public class BeanDefinition extends NoOu
         return ref;
     }
 
-    @Required
     public void setRef(String ref) {
         this.ref = ref;
     }
@@ -124,6 +126,10 @@ public class BeanDefinition extends NoOu
         this.beanType = beanType;
     }
 
+    public void setBeanType(Class<?> beanType) {
+        this.beanClass = beanType;
+    }
+
     // Fluent API
     //-------------------------------------------------------------------------
     /**
@@ -131,7 +137,9 @@ public class BeanDefinition extends NoOu
      *
      * @param ref  the bean's id in the registry
      * @return the builder
+     * @deprecated not in use, will be removed in next Camel release
      */
+    @Deprecated
     public BeanDefinition ref(String ref) {
         setRef(ref);
         return this;
@@ -142,7 +150,9 @@ public class BeanDefinition extends NoOu
      *
      * @param method  the bean's method name which wants camel to call
      * @return the builder
+     * @deprecated not in use, will be removed in next Camel release
      */
+    @Deprecated
     public BeanDefinition method(String method) {
         setMethod(method);
         return this;
@@ -153,7 +163,9 @@ public class BeanDefinition extends NoOu
      *
      * @param bean the instance of the bean
      * @return the builder
+     * @deprecated not in use, will be removed in next Camel release
      */
+    @Deprecated
     public BeanDefinition bean(Object bean) {
         setBean(bean);
         return this;
@@ -164,9 +176,11 @@ public class BeanDefinition extends NoOu
      *
      * @param beanType the Class of the bean
      * @return the builder
+     * @deprecated not in use, will be removed in next Camel release
      */
+    @Deprecated
     public BeanDefinition beanType(Class<?> beanType) {
-        setBean(beanType);
+        setBeanType(beanType);
         return this;
     }
 
@@ -183,12 +197,22 @@ public class BeanDefinition extends NoOu
             answer = new BeanProcessor(beanHolder);
         } else {
             if (bean == null) {
-                ObjectHelper.notNull(beanType, "bean, ref or beanType", this);
-                try {
-                    clazz = routeContext.getCamelContext().getClassResolver().resolveMandatoryClass(beanType);
-                } catch (ClassNotFoundException e) {
-                    throw ObjectHelper.wrapRuntimeCamelException(e);
+                
+                if (beanType == null && beanClass == null) {
+                    throw new IllegalArgumentException("bean, ref or beanType must be provided");
                 }
+
+                // the clazz is either from beanType or beanClass
+                if (beanType != null) {
+                    try {
+                        clazz = routeContext.getCamelContext().getClassResolver().resolveMandatoryClass(beanType);
+                    } catch (ClassNotFoundException e) {
+                        throw ObjectHelper.wrapRuntimeCamelException(e);
+                    }
+                } else {
+                    clazz = beanClass;
+                }
+
                 // create a bean if there is a default public no-arg constructor
                 if (ObjectHelper.hasDefaultPublicNoArgConstructor(clazz)) {
                     bean = CamelContextHelper.newInstance(routeContext.getCamelContext(),
clazz);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=1295579&r1=1295578&r2=1295579&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Thu
Mar  1 14:20:19 2012
@@ -2411,7 +2411,7 @@ public abstract class ProcessorDefinitio
     @SuppressWarnings("unchecked")
     public Type bean(Class<?> beanType) {
         BeanDefinition answer = new BeanDefinition();
-        answer.setBeanType(beanType.getName());
+        answer.setBeanType(beanType);
         addOutput(answer);
         return (Type) this;
     }
@@ -2427,7 +2427,7 @@ public abstract class ProcessorDefinitio
     @SuppressWarnings("unchecked")
     public Type bean(Class<?> beanType, String method) {
         BeanDefinition answer = new BeanDefinition();
-        answer.setBeanType(beanType.getName());
+        answer.setBeanType(beanType);
         answer.setMethod(method);
         addOutput(answer);
         return (Type) this;



Mime
View raw message