activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r525560 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/spi/ camel-spring/src/main/java/org/apache/camel/spring/
Date Wed, 04 Apr 2007 17:22:33 GMT
Author: jstrachan
Date: Wed Apr  4 10:22:32 2007
New Revision: 525560

URL: http://svn.apache.org/viewvc?view=rev&rev=525560
Log:
added a spring ComponentResolver so that components can be used directly from the spring context

Added:
    activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ComponentResolver.java
    activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=525560&r1=525559&r2=525560
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Wed Apr  4 10:22:32 2007
@@ -50,7 +50,7 @@
     private TypeConverter typeConverter;
     private ExchangeConverter exchangeConverter;
     private Injector injector;
-    private ComponentResolver componentResolver = new DefaultComponentResolver();
+    private ComponentResolver componentResolver;
 
     /**
      * Adds a component to the container.
@@ -139,7 +139,7 @@
                         }
                     }
                     if (answer == null) {
-                        Component component = componentResolver.resolveComponent(uri, this);
+                        Component component = getComponentResolver().resolveComponent(uri,
this);
                         if (component != null) {
                             ServiceHelper.startServices(component);
                             answer = component.resolveEndpoint(uri);
@@ -238,6 +238,17 @@
         this.injector = injector;
     }
 
+    public ComponentResolver getComponentResolver() {
+        if (componentResolver == null) {
+            componentResolver = createComponentResolver();
+        }
+        return componentResolver;
+    }
+
+    public void setComponentResolver(ComponentResolver componentResolver) {
+        this.componentResolver = componentResolver;
+    }
+
     // Implementation methods
     //-----------------------------------------------------------------------
 
@@ -302,4 +313,12 @@
             throw new RuntimeCamelException(e);
         }
     }
+
+    /**
+     * Lazily create a default implementation
+     */
+    protected ComponentResolver createComponentResolver() {
+        return new DefaultComponentResolver();
+    }
+
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ComponentResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ComponentResolver.java?view=diff&rev=525560&r1=525559&r2=525560
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ComponentResolver.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ComponentResolver.java
Wed Apr  4 10:22:32 2007
@@ -37,5 +37,5 @@
      * @param context the context to load the component if it can be resolved
      * @return the component which is added to the context or null if it can not be resolved
      */
-    Component<E> resolveComponent(String uri, CamelContext context);
+    Component<E> resolveComponent(String uri, CamelContext context) throws Exception;
 }

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=525560&r1=525559&r2=525560
==============================================================================
--- 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
Wed Apr  4 10:22:32 2007
@@ -18,7 +18,9 @@
 package org.apache.camel.spring;
 
 import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultComponentResolver;
 import org.apache.camel.spi.Injector;
+import org.apache.camel.spi.ComponentResolver;
 import org.apache.camel.CamelContext;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.DisposableBean;
@@ -59,5 +61,11 @@
     @Override
     protected Injector createInjector() {
         return new SpringInjector(getApplicationContext());
+    }
+
+    @Override
+    protected ComponentResolver createComponentResolver() {
+        ComponentResolver defaultResolver = super.createComponentResolver();
+        return new SpringComponentResolver(getApplicationContext(), defaultResolver);
     }
 }

Added: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java?view=auto&rev=525560
==============================================================================
--- activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java
(added)
+++ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java
Wed Apr  4 10:22:32 2007
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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;
+
+import static org.apache.camel.util.ObjectHelper.notNull;
+import org.apache.camel.spi.ComponentResolver;
+import org.apache.camel.Component;
+import org.apache.camel.CamelContext;
+import org.apache.camel.util.ObjectHelper;
+import org.springframework.context.ApplicationContext;
+
+import java.net.URI;
+
+/**
+ * An implementation of {@link ComponentResolver} which tries to find a Camel {@link Component}
+ * in the Spring {@link ApplicationContext} first; if its not there it defaults to the auto-discovery
mechanism.
+ *
+ * @version $Revision$
+ */
+public class SpringComponentResolver implements ComponentResolver {
+    private final ApplicationContext applicationContext;
+    private final ComponentResolver nextResolver;
+
+    public SpringComponentResolver(ApplicationContext applicationContext, ComponentResolver
nextResolver) {
+        notNull(applicationContext, "applicationContext");
+        this.applicationContext = applicationContext;
+        this.nextResolver = nextResolver;
+    }
+
+    public Component resolveComponent(String uri, CamelContext context) throws Exception
{
+        String scheme = new URI(uri).getScheme();
+        Object bean = applicationContext.getBean(scheme);
+        if (bean != null) {
+            if (bean instanceof Component) {
+                return (Component) bean;
+            }
+            else {
+                throw new IllegalArgumentException("Bean with name: " + bean + " in spring
context is not a Component: " + bean);
+            }
+        }
+        if (nextResolver == null) {
+            return null;
+        }
+        return nextResolver.resolveComponent(uri, context);
+    }
+}

Propchange: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message