camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r583144 - in /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel: component/bean/BeanInfo.java component/bean/BeanProcessor.java util/CamelContextHelper.java util/ObjectHelper.java
Date Tue, 09 Oct 2007 12:42:29 GMT
Author: jstrachan
Date: Tue Oct  9 05:42:29 2007
New Revision: 583144

URL: http://svn.apache.org/viewvc?rev=583144&view=rev
Log:
added hook to allow a Type Converter to be used to customize the processing of a bean for
CAMEL-167

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=583144&r1=583143&r2=583144&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
Tue Oct  9 05:42:29 2007
@@ -66,6 +66,10 @@
         return type;
     }
 
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
     public MethodInvocation createInvocation(Method method, Object pojo, Exchange exchange)
         throws RuntimeCamelException {
         MethodInfo methodInfo = introspect(type, method);

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java?rev=583144&r1=583143&r2=583144&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
Tue Oct  9 05:42:29 2007
@@ -16,26 +16,29 @@
  */
 package org.apache.camel.component.bean;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
+import org.apache.camel.impl.ServiceSupport;
 import org.apache.camel.spi.Registry;
+import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.ObjectHelper;
 import static org.apache.camel.util.ObjectHelper.isNullOrBlank;
+import org.apache.camel.util.ServiceHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
 /**
  * A {@link Processor} which converts the inbound exchange to a method
  * invocation on a POJO
  * 
  * @version $Revision: $
  */
-public class BeanProcessor implements Processor {
+public class BeanProcessor extends ServiceSupport implements Processor {
     public static final String METHOD_NAME = "org.apache.camel.MethodName";
     private static final Log LOG = LogFactory.getLog(BeanProcessor.class);
 
@@ -43,10 +46,12 @@
     private final BeanInfo beanInfo;
     private Method method;
     private String methodName;
+    private final Processor processor;
 
     public BeanProcessor(Object pojo, BeanInfo beanInfo) {
         this.pojo = pojo;
         this.beanInfo = beanInfo;
+        this.processor = CamelContextHelper.convertTo(beanInfo.getCamelContext(), Processor.class,
pojo);
     }
 
     public BeanProcessor(Object pojo, CamelContext camelContext, ParameterMappingStrategy
parameterMappingStrategy) {
@@ -76,6 +81,12 @@
         if (LOG.isDebugEnabled()) {
             LOG.debug(">>>> invoking method for: " + exchange);
         }
+
+        // do we have a custom adapter for this POJO to a Processor
+        if (processor != null) {
+            processor.process(exchange);
+            return;
+        }
         Message in = exchange.getIn();
         BeanInvocation beanInvoke = in.getBody(BeanInvocation.class);
         if (beanInvoke != null) {
@@ -137,5 +148,15 @@
 
     public void setMethodName(String methodName) {
         this.methodName = methodName;
+    }
+
+    // Implementation methods
+    //-------------------------------------------------------------------------
+    protected void doStart() throws Exception {
+        ServiceHelper.startService(processor);
+    }
+
+    protected void doStop() throws Exception {
+        ServiceHelper.stopService(processor);
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java?rev=583144&r1=583143&r2=583144&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
Tue Oct  9 05:42:29 2007
@@ -19,6 +19,7 @@
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.NoSuchEndpointException;
+import org.apache.camel.spi.Injector;
 import static org.apache.camel.util.ObjectHelper.notNull;
 
 /**
@@ -70,5 +71,13 @@
             throw new IllegalArgumentException("Value " + value + " converted to " + type.getName()
+ " cannot be null");
         }
         return answer;
+    }
+
+    /**
+     * Creates a new instance of the given type using the {@link Injector} on the given
+     * {@link CamelContext}
+     */
+    public static <T> T newInstance(CamelContext context, Class<T> beanType)
{
+        return context.getInjector().newInstance(beanType);
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=583144&r1=583143&r2=583144&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Tue Oct  9 05:42:29 2007
@@ -102,7 +102,7 @@
 
     public static void notNull(Object value, String name) {
         if (value == null) {
-            throw new IllegalArgumentException("No " + name + " specified");
+            throw new IllegalArgumentException(name + " must be specified");
         }
     }
 



Mime
View raw message