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<PojoExchange> createEndpoint(String uri, String
remaining, Map parameters) throws Exception {
- return new PojoEndpoint(uri, this, remaining);
+ protected Endpoint<PojoExchange> 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<PojoExchange> {
- 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<PojoExchange> 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 <a href="http://activemq.apache.org/pojo.html">POJO
Component</a>
+ * which implements the <a href="http://activemq.apache.org/bean.html">Bean
Component</a>
+ * 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