Author: jstrachan
Date: Tue Oct 14 04:45:14 2008
New Revision: 704481

URL: http://svn.apache.org/viewvc?rev=704481&view=rev
Log:
improved the Guice support to work nicely with GuiceyFruit and provide some 
useful base classes which use the new Guice 2.x features such as nice @Provides 
methods to create custom route builder instances (or collections of them)

Added:
    
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithMatchingRoutes.java
   (with props)
    
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithRouteTypes.java
   (with props)
    
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
   (contents, props changed)
      - copied, changed from r700455, 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
    
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
   (with props)
    
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute2.java
   (contents, props changed)
      - copied, changed from r700455, 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute.java
Modified:
    activemq/camel/trunk/components/camel-guice/pom.xml
    
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
    
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/GuiceCamelContext.java
    
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
    
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java

Modified: activemq/camel/trunk/components/camel-guice/pom.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/pom.xml?rev=704481&r1=704480&r2=704481&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/pom.xml (original)
+++ activemq/camel/trunk/components/camel-guice/pom.xml Tue Oct 14 04:45:14 2008
@@ -38,11 +38,10 @@
   </properties>
 
   <repositories>
-    <!-- TODO remove when there is a 1.1 release from Google! -->
     <repository>
-      <id>open.iona.m2</id>
-      <name>IONA Open Source Community Release Repository</name>
-      <url>http://repo.open.iona.com/maven2</url>
+      <id>guiceyfruit.release</id>
+      <name>GuiceyFruit Release Repository</name>
+      <url>http://guiceyfruit.googlecode.com/svn/repo/releases/</url>
       <snapshots>
         <enabled>false</enabled>
       </snapshots>
@@ -50,6 +49,19 @@
         <enabled>true</enabled>
       </releases>
     </repository>
+
+    <!-- TODO remove with real release when we switch from SNAPSHOT version -->
+    <repository>
+      <id>guiceyfruit.snapshot</id>
+      <name>GuiceyFruit Snapshot Repository</name>
+      <url>http://guiceyfruit.googlecode.com/svn/repo/snapshots/</url>
+      <snapshots>
+        <enabled>true</enabled>
+      </snapshots>
+      <releases>
+        <enabled>false</enabled>
+      </releases>
+    </repository>
   </repositories>
 
   <dependencies>
@@ -59,20 +71,11 @@
       <artifactId>camel-core</artifactId>
     </dependency>
     <dependency>
-      <groupId>com.google.code.guice</groupId>
-      <artifactId>guice</artifactId>
-      <!-- TODO requires release after 1.0 as we need the Multibinder -->
-      <version>1.1.0-fuse</version>
-    </dependency>
-
-    <!-- TODO should be really included by guice!! -->
-    <dependency>
-      <groupId>aopalliance</groupId>
-      <artifactId>aopalliance</artifactId>
-      <version>1.0</version>
+      <groupId>org.guiceyfruit</groupId>
+      <artifactId>guiceyfruit-core</artifactId>
+      <version>2.0-SNAPSHOT</version>
     </dependency>
 
-
     <!-- testing -->
     <dependency>
       <groupId>commons-logging</groupId>

Modified: 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java?rev=704481&r1=704480&r2=704481&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
 (original)
+++ 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
 Tue Oct 14 04:45:14 2008
@@ -16,56 +16,33 @@
  */
 package org.apache.camel.guice;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import com.google.inject.AbstractModule;
-import com.google.inject.multibindings.Multibinder;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.Routes;
-import org.apache.camel.builder.RouteBuilder;
 
 /**
- * A default Guice module for creating a [EMAIL PROTECTED] CamelContext} and 
registering a list of [EMAIL PROTECTED] RouteBuilder} types to register.
- * <p/>
- * You can drive from this class to overload the [EMAIL PROTECTED] 
#configureRoutes(com.google.inject.multibindings.Multibinder)} method to 
perform custom binding for
- * route builders. Another approach is to create a [EMAIL PROTECTED] 
RouteBuilder} which just initialises all of your individual route builders
+ * A base Guice module for creating a [EMAIL PROTECTED] CamelContext} leaving 
it up to the users module
+ * to bind a Set<Routes> for the routing rules.
+ * <p>
+ * To bind the routes you should create a provider method annotated with 
@Provides and returning Set<Routes> such as
+ * <code><pre>
+ * public class MyModule extends CamelModule {
+ *   &#64;Provides
+ *   Set&lt;Routes&gt; routes(Injector injector) { ... }
+ * }
+ * </pre></code>
+ * If you wish to bind all of the bound [EMAIL PROTECTED] Routes} 
implementations available - maybe with some filter applied - then
+ * please use the [EMAIL PROTECTED] 
org.apache.camel.guice.CamelModuleWithMatchingRoutes}.
+ * <p>
+ * Otherwise if you wish to list all of the classes of the [EMAIL PROTECTED] 
Routes} implementations then use the
+ * [EMAIL PROTECTED] org.apache.camel.guice.CamelModuleWithRouteTypes} module 
instead.
  *
  * @version $Revision$
  */
 public class CamelModule extends AbstractModule {
-    private List<Class<? extends RouteBuilder>> routeClassList;
-
-    protected CamelModule(Class<? extends RouteBuilder>... routeTypes) {
-        routeClassList = new ArrayList<Class<? extends RouteBuilder>>();
-        for (Class<? extends RouteBuilder> routeType : routeTypes) {
-            routeClassList.add(routeType);
-        }
-    }
-
-    protected CamelModule(List<Class<? extends RouteBuilder>> routeClassList) {
-        this.routeClassList = routeClassList;
-    }
 
     protected void configure() {
         
bind(CamelContext.class).to(GuiceCamelContext.class).asEagerSingleton();
-
-        Multibinder<Routes> routesBinder = Multibinder.newSetBinder(binder(), 
Routes.class);
-
-        for (Class<? extends Routes> routeType : routeClassList) {
-            routesBinder.addBinding().to(routeType);
-        }
-
-        configureRoutes(routesBinder);
-    }
-
-    /**
-     * Provides a strategy method configure the routes, typically via [EMAIL 
PROTECTED] RouteBuilder} instances
-     *
-     * @param routesBinder
-     */
-    protected void configureRoutes(Multibinder<Routes> routesBinder) {
     }
 
 }

Added: 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithMatchingRoutes.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithMatchingRoutes.java?rev=704481&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithMatchingRoutes.java
 (added)
+++ 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithMatchingRoutes.java
 Tue Oct 14 04:45:14 2008
@@ -0,0 +1,59 @@
+/**
+ *
+ * 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.guice;
+
+import com.google.inject.Injector;
+import com.google.inject.Provides;
+import com.google.inject.matcher.Matcher;
+import com.google.inject.matcher.Matchers;
+import org.apache.camel.Routes;
+import org.guiceyfruit.Injectors;
+
+import java.util.Set;
+
+/**
+ * A Guice Module which injects the CamelContext with all available 
implementations
+ * of [EMAIL PROTECTED] Routes} which are bound to Guice with an optional 
[EMAIL PROTECTED] Matcher} to filter out the classes required.
+ * <p>
+ * Or if you would like to specify exactly which [EMAIL PROTECTED] Routes} to 
bind then use the [EMAIL PROTECTED] CamelModule} and create a provider
+ * method annotated with @Provides and returning Set<Routes> such as
+ * <code><pre>
+ * public class MyModule extends CamelModule {
+ *   &#64;Provides
+ *   Set&lt;Routes&gt; routes(Injector injector) { ... }
+ * }
+ * </pre></code>
+ *
+ * @version $Revision: 1.1 $
+ */
+public class CamelModuleWithMatchingRoutes extends CamelModule {
+    private final Matcher<Class> matcher;
+
+    public CamelModuleWithMatchingRoutes() {
+        this(Matchers.subclassesOf(Routes.class));
+    }
+
+    public CamelModuleWithMatchingRoutes(Matcher<Class> matcher) {
+        this.matcher = matcher;
+    }
+
+    @Provides
+    Set<Routes> routes(Injector injector) {
+        return Injectors.getInstancesOf(injector, matcher);
+    }
+}
\ No newline at end of file

Propchange: 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithMatchingRoutes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithRouteTypes.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithRouteTypes.java?rev=704481&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithRouteTypes.java
 (added)
+++ 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithRouteTypes.java
 Tue Oct 14 04:45:14 2008
@@ -0,0 +1,65 @@
+/**
+ *
+ * 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.guice;
+
+import com.google.common.collect.Sets;
+import com.google.inject.Injector;
+import com.google.inject.Provides;
+import org.apache.camel.Routes;
+
+import java.util.Set;
+
+/**
+ * A Guice Module which injects the CamelContext with the specified [EMAIL 
PROTECTED] Routes} types - which are then injected by Guice.
+ * <p>
+ * If you wish to bind all of the bound [EMAIL PROTECTED] Routes} 
implementations available - maybe with some filter applied - then
+ * please use the [EMAIL PROTECTED] 
org.apache.camel.guice.CamelModuleWithMatchingRoutes}.
+ * <p>
+ * Or if you would like to specify exactly which [EMAIL PROTECTED] Routes} to 
bind then use the [EMAIL PROTECTED] CamelModule} and create a provider
+ * method annotated with @Provides and returning Set<Routes> such as
+ * <code><pre>
+ * public class MyModule extends CamelModule {
+ *   &#64;Provides
+ *   Set&lt;Routes&gt; routes(Injector injector) { ... }
+ * }
+ * </pre></code>
+ * 
+ *
+ * @version $Revision: 1.1 $
+ */
+public class CamelModuleWithRouteTypes extends CamelModule {
+    private Set<Class<? extends Routes>> routes;
+
+    public CamelModuleWithRouteTypes(Class<? extends Routes>... routes) {
+        this(Sets.newHashSet(routes));
+    }
+
+    public CamelModuleWithRouteTypes(Set<Class<? extends Routes>> routes) {
+        this.routes = routes;
+    }
+
+    @Provides
+    Set<Routes> routes(Injector injector) {
+        Set<Routes> answer = Sets.newHashSet();
+        for (Class<? extends Routes> type : routes) {
+            Routes route = injector.getInstance(type);
+            answer.add(route);
+        }
+        return answer;
+    }
+}

Propchange: 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModuleWithRouteTypes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/GuiceCamelContext.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/GuiceCamelContext.java?rev=704481&r1=704480&r2=704481&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/GuiceCamelContext.java
 (original)
+++ 
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/GuiceCamelContext.java
 Tue Oct 14 04:45:14 2008
@@ -16,13 +16,8 @@
  */
 package org.apache.camel.guice;
 
-import java.util.List;
-import java.util.Set;
-
-import javax.naming.Context;
-
 import com.google.inject.Inject;
-
+import org.apache.camel.Route;
 import org.apache.camel.Routes;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.builder.ErrorHandlerBuilder;
@@ -36,7 +31,16 @@
 import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.Registry;
 
+import javax.naming.Context;
+import java.util.List;
+import java.util.Set;
+
 /**
+ * The default CamelContext implementation for working with Guice.
+ *
+ * It is recommended you use this implementation with the
+ * <a href="http://code.google.com/p/guiceyfruit/wiki/GuiceyJndi";>Guicey JNDI 
Provider</a>
+ * 
  * @version $Revision$
  */
 public class GuiceCamelContext extends DefaultCamelContext {
@@ -56,6 +60,12 @@
 
     @Override
     @Inject(optional = true)
+    public void setRoutes(List<Route> routes) {
+        super.setRoutes(routes);
+    }
+
+    @Override
+    @Inject(optional = true)
     public void setRegistry(Registry registry) {
         super.setRegistry(registry);
     }

Modified: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java?rev=704481&r1=704480&r2=704481&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
 Tue Oct 14 04:45:14 2008
@@ -16,11 +16,9 @@
  */
 package org.apache.camel.guice;
 
-import junit.framework.TestCase;
-
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-
+import junit.framework.TestCase;
 import org.apache.camel.CamelContext;
 
 
@@ -32,7 +30,7 @@
 public class ConciseGuiceRouteTest extends TestCase {
 
     public void testGuice() throws Exception {
-        Injector injector = Guice.createInjector(new 
CamelModule(MyRouteInstaller.class, MyHardcodeRoute.class));
+        Injector injector = Guice.createInjector(new 
CamelModuleWithRouteTypes(MyRouteInstaller.class, MyHardcodeRoute.class));
         CamelContext camelContext = injector.getInstance(CamelContext.class);
         camelContext.start();
         Thread.sleep(1000);

Copied: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
 (from r700455, 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java)
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java?p2=activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java&p1=activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java&r1=700455&r2=704481&rev=704481&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
 Tue Oct 14 04:45:14 2008
@@ -16,48 +16,79 @@
  */
 package org.apache.camel.guice;
 
-import junit.framework.TestCase;
-
+import com.google.common.collect.Sets;
+import com.google.inject.AbstractModule;
+import com.google.inject.Binding;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.multibindings.Multibinder;
-
+import com.google.inject.Key;
+import com.google.inject.Provides;
+import com.google.inject.matcher.Matcher;
+import com.google.inject.matcher.Matchers;
+import com.google.inject.name.Named;
+import com.google.inject.name.Names;
+import junit.framework.TestCase;
 import org.apache.camel.CamelContext;
-import org.apache.camel.Routes;
+import org.apache.camel.builder.RouteBuilder;
+import org.guiceyfruit.Injectors;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * Lets use a custom CamelModule to perform explicit binding of route builders
  *
  * @version $Revision$
  */
-public class TraditionalGuiceRouteTest extends TestCase {
+public class GuiceRouteWithNamedKeysTest extends TestCase {
 
-    public static class MyModule extends CamelModule {
+    public static class MyModule extends CamelModuleWithMatchingRoutes {
 
-        /**
-         * Lets add the routes
-         */
-        @Override
-        protected void configureRoutes(Multibinder<Routes> binder) {
-            // use traditional Guice approach to configure routes
-            binder.addBinding().to(MyHardcodeRoute.class);
-            binder.addBinding().to(MyRouteInstaller.class);
-
-            // TODO allow injection by @Named("foo") endpoints? Let the 
CamelContext provide it??
+        @Provides
+        @Named("foo")
+        protected MyConfigurableRoute2 createRoute1() {
+            return new MyConfigurableRoute2("direct:a", "direct:b");
         }
-
-        // TODO demo binding endpoints?
-        //bind(Endpoint.class).annotatedWith(Names.name("")).
-
     }
 
 
     public void testGuice() throws Exception {
         Injector injector = Guice.createInjector(new MyModule());
+
+        MyConfigurableRoute2 instance = 
injector.getInstance(Key.get(MyConfigurableRoute2.class, Names.named("foo")));
+        assertNotNull("should have found a key for 'foo'", instance);
+
+        System.out.println("Found instance: " + instance);
+
+        //List<Binding<RouteBuilder>> list = 
injector.findBindingsByType(TypeLiteral.get(RouteBuilder.class));
+        Collection<RouteBuilder> list = Injectors.getInstancesOf(injector, 
RouteBuilder.class);
+        System.out.println("RouteBuilder List: " + list);
+
+        assertEquals("route builder list: " + list, 1, list.size());
+
+        list = Injectors.getInstancesOf(injector, 
Matchers.subclassesOf(RouteBuilder.class));
+        System.out.println("RouteBuilder List: " + list);
+
+        assertEquals("route builder list: " + list, 1, list.size());
+/*
+
+        list = Injectors.getInstancesOf(injector, 
Matchers.subclassesOf(RouteBuilder.class).and(Matchers.annotatedWith(Names.named("foo"))));
+        System.out.println("RouteBuilder List: " + list);
+
+        assertEquals("route builder list: " + list, 1, list.size());
+
+        list = Injectors.getInstancesOf(injector, 
Matchers.subclassesOf(RouteBuilder.class).and(Matchers.annotatedWith(Names.named("bar"))));
+        System.out.println("RouteBuilder List: " + list);
+
+        assertEquals("route builder list: " + list, 0, list.size());
+*/
+
         CamelContext camelContext = injector.getInstance(CamelContext.class);
         camelContext.start();
         Thread.sleep(1000);
         camelContext.stop();
     }
 
-}
+
+}
\ No newline at end of file

Propchange: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java?rev=704481&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
 Tue Oct 14 04:45:14 2008
@@ -0,0 +1,52 @@
+/**
+ * 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.guice;
+
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+
+/**
+ * @version $Revision: 689344 $
+ */
+public class GuiceTest extends TestCase {
+
+    public static class Cheese {
+        private final CamelContext camelContext;
+
+        @Inject
+        public Cheese(CamelContext camelContext) {
+            this.camelContext = camelContext;
+        }
+
+        public CamelContext getCamelContext() {
+            return camelContext;
+        }
+    }
+
+    public void testGuice() throws Exception {
+        Injector injector = Guice.createInjector(new 
CamelModuleWithMatchingRoutes());
+
+        Cheese cheese = injector.getInstance(Cheese.class);
+        assertNotNull("Should have cheese", cheese);
+        assertNotNull("Should have camelContext", cheese.getCamelContext());
+        System.out.println("Got " + cheese);
+    }
+
+}
\ No newline at end of file

Propchange: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute2.java
 (from r700455, 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute.java)
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute2.java?p2=activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute2.java&p1=activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute.java&r1=700455&r2=704481&rev=704481&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute.java
 (original)
+++ 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute2.java
 Tue Oct 14 04:45:14 2008
@@ -18,7 +18,6 @@
 
 import com.google.inject.Inject;
 import com.google.inject.name.Named;
-import org.apache.camel.Endpoint;
 import org.apache.camel.builder.RouteBuilder;
 
 /**
@@ -26,12 +25,12 @@
  *
  * @version $Revision$
  */
-public class MyConfigurableRoute extends RouteBuilder {
-    protected Endpoint foo;
-    protected Endpoint bar;
+public class MyConfigurableRoute2 extends RouteBuilder {
+    protected String foo;
+    protected String bar;
 
     @Inject
-    public MyConfigurableRoute(@Named("bar") Endpoint bar, @Named("foo") 
Endpoint foo) {
+    public MyConfigurableRoute2(@Named("bar") String bar, @Named("foo") String 
foo) {
         this.bar = bar;
         this.foo = foo;
     }
@@ -39,4 +38,9 @@
     public void configure() throws Exception {
         from(foo).to(bar);
     }
-}
+
+    @Override
+    public String toString() {
+        return "MyConfigurableRoute2[foo: " + foo + "; bar: " + bar + "]";
+    }
+}
\ No newline at end of file

Propchange: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute2.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute2.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java?rev=704481&r1=704480&r2=704481&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
 Tue Oct 14 04:45:14 2008
@@ -16,14 +16,10 @@
  */
 package org.apache.camel.guice;
 
-import junit.framework.TestCase;
-
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.multibindings.Multibinder;
-
+import junit.framework.TestCase;
 import org.apache.camel.CamelContext;
-import org.apache.camel.Routes;
 
 /**
  * Lets use a custom CamelModule to perform explicit binding of route builders
@@ -32,23 +28,12 @@
  */
 public class TraditionalGuiceRouteTest extends TestCase {
 
-    public static class MyModule extends CamelModule {
-
-        /**
-         * Lets add the routes
-         */
-        @Override
-        protected void configureRoutes(Multibinder<Routes> binder) {
-            // use traditional Guice approach to configure routes
-            binder.addBinding().to(MyHardcodeRoute.class);
-            binder.addBinding().to(MyRouteInstaller.class);
+    public static class MyModule extends CamelModuleWithRouteTypes {
 
-            // TODO allow injection by @Named("foo") endpoints? Let the 
CamelContext provide it??
+        public MyModule() {
+            super(MyHardcodeRoute.class, MyRouteInstaller.class);
         }
 
-        // TODO demo binding endpoints?
-        //bind(Endpoint.class).annotatedWith(Names.name("")).
-
     }
 
 


Reply via email to