camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r554322 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ components/camel-spring/src/main/java/org/apache/camel/spring/
Date Sun, 08 Jul 2007 06:10:05 GMT
Author: jstrachan
Date: Sat Jul  7 23:10:04 2007
New Revision: 554322

URL: http://svn.apache.org/viewvc?view=rev&rev=554322
Log:
added an initial implementation of CAMEL-68

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContextAware.java
Modified:
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContextAware.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContextAware.java?view=auto&rev=554322
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContextAware.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContextAware.java
Sat Jul  7 23:10:04 2007
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+/**
+ * An interface to represent an object which wishes to be injected with
+ * a {@link CamelContext} such as when working with Spring or Guice
+ *
+ * @version $Revision: $
+ */
+public interface CamelContextAware {
+
+    /**
+     * Injects the {@link CamelContext}
+     *
+     * @param camelContext
+     */
+    public void setCamelContext(CamelContext camelContext);
+}

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=554322&r1=554321&r2=554322
==============================================================================
--- 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
Sat Jul  7 23:10:04 2007
@@ -18,7 +18,17 @@
 package org.apache.camel.spring;
 
 import org.aopalliance.intercept.MethodInvocation;
-import org.apache.camel.*;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.CamelTemplate;
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.MessageDriven;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.spring.util.BeanInfo;
 import org.apache.camel.spring.util.DefaultMethodInvocationStrategy;
 import org.apache.camel.spring.util.MethodInvocationStrategy;
@@ -55,6 +65,15 @@
     public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
{
         injectFields(bean);
         injectMethods(bean);
+        if (bean instanceof CamelContextAware) {
+            CamelContextAware contextAware = (CamelContextAware) bean;
+            if (camelContext == null) {
+                log.warn("No CamelContext defined yet so cannot inject into: " + bean);
+            }
+            else {
+                contextAware.setCamelContext(camelContext);
+            }
+        }
         return bean;
     }
 

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?view=diff&rev=554322&r1=554321&r2=554322
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Sat Jul  7 23:10:04 2007
@@ -17,7 +17,11 @@
  */
 package org.apache.camel.spring;
 
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.FactoryBean;
 import org.springframework.beans.factory.InitializingBean;
@@ -37,6 +41,8 @@
  * @version $Revision$
  */
 public class CamelContextFactoryBean implements FactoryBean, InitializingBean, DisposableBean,
ApplicationContextAware, ApplicationListener {
+    private static final Log log = LogFactory.getLog(CamelContextFactoryBean.class);
+
     private SpringCamelContext context;
     private RouteBuilder routeBuilder;
     private List<RouteBuilder> additionalBuilders = new ArrayList<RouteBuilder>();
@@ -76,7 +82,7 @@
             context.onApplicationEvent(event);
         }
     }
-
+    
     // Properties
     //-------------------------------------------------------------------------
     public SpringCamelContext getContext() throws Exception {



Mime
View raw message