Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 64112 invoked from network); 17 May 2007 13:44:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 May 2007 13:44:07 -0000 Received: (qmail 43330 invoked by uid 500); 17 May 2007 13:44:13 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 43314 invoked by uid 500); 17 May 2007 13:44:13 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 43305 invoked by uid 99); 17 May 2007 13:44:13 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 May 2007 06:44:13 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME 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, 17 May 2007 06:44:06 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 502241A9838; Thu, 17 May 2007 06:43:46 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r538919 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/component/pojo/ camel-spring/src/main/java/org/apache/camel/spring/ camel-spring/src/main/java/org/apache/camel/spring/component/ camel-spring/src/main/resources/... Date: Thu, 17 May 2007 13:43:45 -0000 To: commits@activemq.apache.org From: jstrachan@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070517134346.502241A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jstrachan Date: Thu May 17 06:43:44 2007 New Revision: 538919 URL: http://svn.apache.org/viewvc?view=rev&rev=538919 Log: minor refactor of the POJO component so we can easily make a bean component for working with spring Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/NoPojoAvailableException.java (with props) activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/component/ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/component/BeanComponent.java (with props) activemq/camel/trunk/camel-spring/src/main/resources/META-INF/services/org/apache/camel/component/ activemq/camel/trunk/camel-spring/src/main/resources/META-INF/services/org/apache/camel/component/bean Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/NoPojoAvailableException.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/NoPojoAvailableException.java?view=auto&rev=538919 ============================================================================== --- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/NoPojoAvailableException.java (added) +++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/NoPojoAvailableException.java Thu May 17 06:43:44 2007 @@ -0,0 +1,36 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.pojo; + +import org.apache.camel.CamelException; + +/** + * @version $Revision: 1.1 $ + */ +public class NoPojoAvailableException extends CamelException { + private final PojoEndpoint endpoint; + + public NoPojoAvailableException(PojoEndpoint endpoint) { + super("No POJO available for endpoint: " + endpoint); + this.endpoint = endpoint; + } + + public PojoEndpoint getEndpoint() { + return endpoint; + } +} Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/NoPojoAvailableException.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java?view=diff&rev=538919&r1=538918&r2=538919 ============================================================================== --- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java (original) +++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java Thu May 17 06:43:44 2007 @@ -25,6 +25,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Producer; +import org.apache.camel.spi.Provider; import org.apache.camel.impl.DefaultComponent; /** @@ -49,8 +50,9 @@ } @Override - protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { - return new PojoEndpoint(uri, this, remaining); + protected Endpoint createEndpoint(String uri, final String remaining, Map parameters) throws Exception { + Object pojo = getService(remaining); + return new PojoEndpoint(uri, this, pojo); } /** Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java?view=diff&rev=538919&r1=538918&r2=538919 ============================================================================== --- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java (original) +++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java Thu May 17 06:43:44 2007 @@ -16,16 +16,17 @@ */ package org.apache.camel.component.pojo; -import java.lang.reflect.InvocationTargetException; - import org.apache.camel.Consumer; +import org.apache.camel.Exchange; import org.apache.camel.NoSuchEndpointException; import org.apache.camel.Processor; import org.apache.camel.Producer; -import org.apache.camel.Exchange; +import org.apache.camel.Component; import org.apache.camel.impl.DefaultEndpoint; import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.impl.DefaultExchange; +import org.apache.camel.spi.Provider; + +import java.lang.reflect.InvocationTargetException; /** * Represents a pojo endpoint that uses reflection @@ -34,20 +35,19 @@ * @version $Revision: 519973 $ */ public class PojoEndpoint extends DefaultEndpoint { - private final PojoComponent component; - private final String pojoId; + private Object pojo; - public PojoEndpoint(String uri, PojoComponent component, String pojoId) { + public PojoEndpoint(String uri, Component component, Object pojo) { super(uri, component); - this.pojoId = pojoId; - this.component = component; + this.pojo = pojo; } public Producer createProducer() throws Exception { - final Object pojo = component.getService(pojoId); - if( pojo == null ) - throw new NoSuchEndpointException(getEndpointUri()); - + final Object pojo = getPojo(); + if (pojo == null) { + throw new NoPojoAvailableException(this); + } + return new DefaultProducer(this) { public void process(Exchange exchange) { PojoExchange pojoExchange = toExchangeType(exchange); @@ -63,9 +63,10 @@ /** * This causes us to invoke the endpoint Pojo using reflection. - * @param pojo + * + * @param pojo */ - static public void invoke(Object pojo, PojoExchange exchange) { + public static void invoke(Object pojo, PojoExchange exchange) { PojoInvocation invocation = exchange.getInvocation(); try { Object response = invocation.getMethod().invoke(pojo, invocation.getArgs()); @@ -86,16 +87,15 @@ return new PojoExchange(getContext()); } - public PojoComponent getComponent() { - return component; - } - - public String getPojoId() { - return pojoId; - } - - public boolean isSingleton() { - return true; - } + public boolean isSingleton() { + return true; + } + + public Object getPojo() { + return pojo; + } + public void setPojo(Object pojo) { + this.pojo = pojo; + } } Modified: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java?view=diff&rev=538919&r1=538918&r2=538919 ============================================================================== --- activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java (original) +++ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java Thu May 17 06:43:44 2007 @@ -23,6 +23,7 @@ import org.apache.camel.CamelContext; import org.apache.camel.spring.spi.SpringComponentResolver; import org.apache.camel.spring.spi.SpringInjector; +import org.apache.camel.spring.component.BeanComponent; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.BeansException; @@ -46,7 +47,7 @@ } public SpringCamelContext(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; + setApplicationContext(applicationContext); } public static SpringCamelContext springCamelContext(ApplicationContext applicationContext) throws Exception { @@ -57,6 +58,7 @@ } SpringCamelContext answer = new SpringCamelContext(); answer.setApplicationContext(applicationContext); + answer.afterPropertiesSet(); return answer; } @@ -81,6 +83,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; + addComponent("bean", new BeanComponent(applicationContext)); } @Override Added: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/component/BeanComponent.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/component/BeanComponent.java?view=auto&rev=538919 ============================================================================== --- activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/component/BeanComponent.java (added) +++ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/component/BeanComponent.java Thu May 17 06:43:44 2007 @@ -0,0 +1,64 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.component; + +import org.apache.camel.Endpoint; +import org.apache.camel.component.pojo.PojoEndpoint; +import org.apache.camel.impl.DefaultComponent; +import static org.apache.camel.util.ObjectHelper.notNull; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; + +import java.util.Map; + +/** + * An alternative to the POJO Component + * which implements the Bean Component + * which will look up the URI in the Spring ApplicationContext and use that to handle message dispatching. + * + * @version $Revision: 1.1 $ + */ +public class BeanComponent extends DefaultComponent implements ApplicationContextAware { + private ApplicationContext applicationContext; + + public BeanComponent() { + } + + public BeanComponent(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + public ApplicationContext getApplicationContext() { + return applicationContext; + } + + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { + notNull(applicationContext, "applicationContext"); + Object object = applicationContext.getBean(remaining); + if (object != null) { + return new PojoEndpoint(uri, this, object); + } + return null; + } + +} Propchange: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/component/BeanComponent.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/camel/trunk/camel-spring/src/main/resources/META-INF/services/org/apache/camel/component/bean URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/resources/META-INF/services/org/apache/camel/component/bean?view=auto&rev=538919 ============================================================================== --- activemq/camel/trunk/camel-spring/src/main/resources/META-INF/services/org/apache/camel/component/bean (added) +++ activemq/camel/trunk/camel-spring/src/main/resources/META-INF/services/org/apache/camel/component/bean Thu May 17 06:43:44 2007 @@ -0,0 +1 @@ +class=org.apache.camel.spring.component.BeanComponent \ No newline at end of file