Return-Path: Delivered-To: apmail-activemq-camel-commits-archive@locus.apache.org Received: (qmail 92439 invoked from network); 16 Aug 2007 09:29:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Aug 2007 09:29:53 -0000 Received: (qmail 66279 invoked by uid 500); 16 Aug 2007 09:29:51 -0000 Delivered-To: apmail-activemq-camel-commits-archive@activemq.apache.org Received: (qmail 66263 invoked by uid 500); 16 Aug 2007 09:29:51 -0000 Mailing-List: contact camel-commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: camel-dev@activemq.apache.org Delivered-To: mailing list camel-commits@activemq.apache.org Received: (qmail 66254 invoked by uid 99); 16 Aug 2007 09:29:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Aug 2007 02:29:51 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Aug 2007 09:29:52 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5A04B1A981D; Thu, 16 Aug 2007 02:29:32 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r566604 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/util/ camel-core/src/test/java/org/apache/camel/util/ components/camel-spring/src/main/java/org/apache/camel/spring/ Date: Thu, 16 Aug 2007 09:29:32 -0000 To: camel-commits@activemq.apache.org From: jstrachan@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070816092932.5A04B1A981D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jstrachan Date: Thu Aug 16 02:29:31 2007 New Revision: 566604 URL: http://svn.apache.org/viewvc?view=rev&rev=566604 Log: initial cut of an implementation of CAMEL-108, just needs a test case Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java 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?view=diff&rev=566604&r1=566603&r2=566604 ============================================================================== --- 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 Thu Aug 16 02:29:31 2007 @@ -365,4 +365,15 @@ public static String getDefaultCharacterSet() { return Charset.defaultCharset().name(); } + + /** + * Returns the Java Bean property name of the given method, if it is a setter + */ + public static String getPropertyName(Method method) { + String propertyName = method.getName(); + if (propertyName.startsWith("set") && method.getParameterTypes().length == 1) { + propertyName = propertyName.substring(3, 4).toLowerCase() + propertyName.substring(4); + } + return propertyName; + } } Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java?view=diff&rev=566604&r1=566603&r2=566604 ============================================================================== --- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java (original) +++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java Thu Aug 16 02:29:31 2007 @@ -18,6 +18,8 @@ import junit.framework.TestCase; +import java.lang.reflect.Method; + /** * @version $Revision$ */ @@ -26,5 +28,16 @@ assertEquals(ObjectHelper.removeStartingCharacters("foo", '/'), "foo"); assertEquals(ObjectHelper.removeStartingCharacters("/foo", '/'), "foo"); assertEquals(ObjectHelper.removeStartingCharacters("//foo", '/'), "foo"); + } + + public void testGetPropertyName() throws Exception { + Method method = getClass().getMethod("setCheese", String.class); + assertNotNull("should have found a method!", method); + + String name = ObjectHelper.getPropertyName(method); + assertEquals("Property name", "cheese", name); + } + + public void setCheese(String cheese) { } } Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java?view=diff&rev=566604&r1=566603&r2=566604 ============================================================================== --- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java (original) +++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java Thu Aug 16 02:29:31 2007 @@ -16,6 +16,8 @@ */ package org.apache.camel.spring; +import static org.apache.camel.util.ObjectHelper.isNullOrBlank; + import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -115,7 +117,7 @@ public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { EndpointInject annotation = field.getAnnotation(EndpointInject.class); if (annotation != null) { - ReflectionUtils.setField(field, bean, getEndpointInjectionValue(annotation, field.getType())); + ReflectionUtils.setField(field, bean, getEndpointInjectionValue(annotation, field.getType(), field.getName())); } } }); @@ -139,7 +141,8 @@ if (parameterTypes.length != 1) { LOG.warn("Ignoring badly annotated method for injection due to incorrect number of parameters: " + method); } else { - Object value = getEndpointInjectionValue(annoation, parameterTypes[0]); + String propertyName = ObjectHelper.getPropertyName(method); + Object value = getEndpointInjectionValue(annoation, parameterTypes[0], propertyName); ObjectHelper.invokeMethod(method, bean, value); } } @@ -177,14 +180,15 @@ LOG.info("Creating a consumer for: " + annotation); // lets bind this method to a listener - Endpoint endpoint = getEndpointInjection(annotation.uri(), annotation.name()); + String injectionPointName = method.getName(); + Endpoint endpoint = getEndpointInjection(annotation.uri(), annotation.name(), injectionPointName); if (endpoint != null) { try { Processor processor = createConsumerProcessor(bean, method, endpoint); LOG.info("Created processor: " + processor); Consumer consumer = endpoint.createConsumer(processor); consumer.start(); - addConsumer(consumer); + onConsumerAdded(consumer); } catch (Exception e) { LOG.warn(e); throw new RuntimeCamelException(e); @@ -203,16 +207,15 @@ return answer; } - protected void addConsumer(Consumer consumer) { + protected void onConsumerAdded(Consumer consumer) { LOG.debug("Adding consumer: " + consumer); - // consumers.add(consumer); } /** * Creates the value for the injection point for the given annotation */ - protected Object getEndpointInjectionValue(EndpointInject annotation, Class type) { - Endpoint endpoint = getEndpointInjection(annotation.uri(), annotation.name()); + protected Object getEndpointInjectionValue(EndpointInject annotation, Class type, String injectionPointName) { + Endpoint endpoint = getEndpointInjection(annotation.uri(), annotation.name(), injectionPointName); if (endpoint != null) { if (type.isInstance(endpoint)) { return endpoint; @@ -229,18 +232,17 @@ return null; } - protected Endpoint getEndpointInjection(String uri, String name) { + protected Endpoint getEndpointInjection(String uri, String name, String injectionPointName) { Endpoint endpoint = null; if (isNotNullAndNonEmpty(uri)) { endpoint = camelContext.getEndpoint(uri); } else { - if (isNotNullAndNonEmpty(name)) { - endpoint = (Endpoint)applicationContext.getBean(name); - if (endpoint == null) { - throw new NoSuchBeanDefinitionException(name); - } - } else { - LOG.warn("No uri or name specified on @EndpointInject annotation!"); + if (isNullOrBlank(name)) { + name = injectionPointName; + } + endpoint = (Endpoint) applicationContext.getBean(name); + if (endpoint == null) { + throw new NoSuchBeanDefinitionException(name); } } return endpoint;