You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/10/09 14:41:16 UTC

svn commit: r583143 - in /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model: BeanRef.java ProcessorType.java

Author: jstrachan
Date: Tue Oct  9 05:41:16 2007
New Revision: 583143

URL: http://svn.apache.org/viewvc?rev=583143&view=rev
Log:
allow a bean to be specified by its Class rather than an instance

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanRef.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanRef.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanRef.java?rev=583143&r1=583142&r2=583143&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanRef.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanRef.java Tue Oct  9 05:41:16 2007
@@ -16,16 +16,18 @@
  */
 package org.apache.camel.model;
 
-import org.apache.camel.Processor;
-import org.apache.camel.component.bean.BeanProcessor;
-import org.apache.camel.impl.RouteContext;
-
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 
+import org.apache.camel.Processor;
+import org.apache.camel.component.bean.BeanProcessor;
+import org.apache.camel.impl.RouteContext;
+import org.apache.camel.util.CamelContextHelper;
+import org.apache.camel.util.ObjectHelper;
+
 /**
  * @version $Revision: 1.1 $
  */
@@ -36,6 +38,8 @@
     private String ref;
     @XmlAttribute(required = false)
     private String method;
+    @XmlAttribute(required = false)
+    private Class beanType;
     @XmlTransient
     private Object bean;
 
@@ -76,10 +80,25 @@
         this.bean = bean;
     }
 
+    public Class getBeanType() {
+        return beanType;
+    }
+
+    public void setBeanType(Class beanType) {
+        this.beanType = beanType;
+    }
+
     @Override
     public Processor createProcessor(RouteContext routeContext) {
         if (bean == null) {
-            bean = routeContext.lookup(getRef(), Object.class);
+            String reference = getRef();
+            if (reference != null) {
+                bean = routeContext.lookup(reference, Object.class);
+            }
+            else {
+                ObjectHelper.notNull(beanType, "bean, ref or beanType");
+                bean = CamelContextHelper.newInstance(routeContext.getCamelContext(), beanType);
+            }
         }
         BeanProcessor answer = new BeanProcessor(bean, routeContext.getCamelContext());
         if (method != null) {
@@ -99,6 +118,9 @@
         }
         else if (bean != null) {
             return bean.toString();
+        }
+        else if (beanType != null) {
+            return beanType.getName();
         }
         else {
             return "";

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?rev=583143&r1=583142&r2=583143&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java Tue Oct  9 05:41:16 2007
@@ -585,6 +585,29 @@
     }
 
     /**
+     * Adds a bean by type which is invoked which could be a final destination, or could
+     * be a transformation in a pipeline
+     */
+    public Type bean(Class beanType) {
+        BeanRef answer = new BeanRef();
+        answer.setBeanType(beanType);
+        addOutput(answer);
+        return (Type) this;
+    }
+
+    /**
+     * Adds a bean type and method which is invoked which could be a final
+     * destination, or could be a transformation in a pipeline
+     */
+    public Type bean(Class beanType, String method) {
+        BeanRef answer = new BeanRef();
+        answer.setBeanType(beanType);
+        answer.setMethod(method);
+        addOutput(answer);
+        return (Type) this;
+    }
+
+    /**
      * Adds a bean which is invoked which could be a final destination, or could
      * be a transformation in a pipeline
      */