[jboss-cvs] JBossAS SVN: r65479 - in projects/microcontainer/trunk: build and 16 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Sep 19 15:02:47 EDT 2007


Author: alesj
Date: 2007-09-19 15:02:47 -0400 (Wed, 19 Sep 2007)
New Revision: 65479

Added:
   projects/microcontainer/trunk/guice-int/
   projects/microcontainer/trunk/guice-int/pom.xml
   projects/microcontainer/trunk/guice-int/src/
   projects/microcontainer/trunk/guice-int/src/main/
   projects/microcontainer/trunk/guice-int/src/main/org/
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/AllGuiceObject.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceBinder.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceInjectorFactory.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceListener.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceObject.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/InstanceBinder.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/KernelGuiceObject.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/KernelInstanceBinder.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/ListenerGuiceObject.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/NameControllerContextBindFilter.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/BinderHolder.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/ControllerContextBindFilter.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/GuiceIntegration.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/InjectableMicrocontainerProvider.java
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/MicrocontainerProvider.java
   projects/microcontainer/trunk/guice-int/src/resources/
   projects/microcontainer/trunk/guice-int/src/tests/
   projects/microcontainer/trunk/guice-int/src/tests/org/
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/Prototype.java
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/Singleton.java
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceIntegrationTestCase.java
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceObjectsTestCase.java
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceTestSuite.java
Modified:
   projects/microcontainer/trunk/build/pom.xml
   projects/microcontainer/trunk/osgi-int/pom-jdk14.xml
   projects/microcontainer/trunk/osgi-int/pom.xml
   projects/microcontainer/trunk/pom.xml
Log:
Initial Microcontainer + Guice integration.

Modified: projects/microcontainer/trunk/build/pom.xml
===================================================================
--- projects/microcontainer/trunk/build/pom.xml	2007-09-19 18:33:21 UTC (rev 65478)
+++ projects/microcontainer/trunk/build/pom.xml	2007-09-19 19:02:47 UTC (rev 65479)
@@ -49,6 +49,7 @@
     <version.apache-xerces.xml-apis>2.7.1</version.apache-xerces.xml-apis>
     <version.jboss.drools>4.0.1</version.jboss.drools>
     <version.jboss.jbpm>3.1.1</version.jboss.jbpm>
+    <version.google.guice>1.0</version.google.guice>
   </properties>
 
   <build>
@@ -310,6 +311,11 @@
       </dependency>
       <dependency>
         <groupId>org.jboss.microcontainer</groupId>
+        <artifactId>jboss-guice-int</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.jboss.microcontainer</groupId>
         <artifactId>jboss-osgi-int</artifactId>
         <version>${project.version}</version>
       </dependency>
@@ -440,6 +446,11 @@
         <version>${version.jboss.drools}</version>
       </dependency>
       <dependency>
+        <groupId>com.google.code.guice</groupId>
+        <artifactId>guice</artifactId>
+        <version>${version.google.guice}</version>
+      </dependency>
+      <dependency>
         <groupId>jboss</groupId>
         <artifactId>jbpm</artifactId>
         <version>${version.jboss.jbpm}</version>

Added: projects/microcontainer/trunk/guice-int/pom.xml
===================================================================
--- projects/microcontainer/trunk/guice-int/pom.xml	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/pom.xml	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,43 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.jboss.microcontainer</groupId>
+    <artifactId>jboss-microcontainer</artifactId>
+    <version>2.0.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jboss-guice-int</artifactId>
+  <packaging>jar</packaging>
+  <name>JBoss Microcontainer Guice Int</name>
+  <url>http://www.jboss.com/products/jbossmc</url>
+  <description>JBoss Microcontainer Guice Int</description>
+  <build>
+    <resources>
+      <resource>
+        <directory>src/resources/main</directory>
+      </resource>
+    </resources>
+    <testResources>
+      <testResource>
+        <directory>src/resources/tests</directory>
+      </testResource>
+    </testResources>
+  </build>
+  <!-- Do not add version information here, use ../build/pom.xml instead -->
+  <dependencies>
+    <!-- Global dependencies -->
+    <dependency>
+      <groupId>com.google.code.guice</groupId>
+      <artifactId>guice</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-kernel</artifactId>
+    </dependency>
+    <!-- Test dependencies -->
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-test</artifactId>
+    </dependency>
+  </dependencies>
+</project>

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/AllGuiceObject.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/AllGuiceObject.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/AllGuiceObject.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.plugins;
+
+import com.google.inject.Binder;
+import org.jboss.kernel.Kernel;
+
+/**
+ * Bind all current contexts.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+class AllGuiceObject implements GuiceObject
+{
+   public static GuiceObject getInstance()
+   {
+      return ALL;
+   }
+
+   public String geName()
+   {
+      return "Guice_All";
+   }
+
+   public Object createObject(Kernel kernel, Binder binder)
+   {
+      return new GuiceBinder(kernel, binder);
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceBinder.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceBinder.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceBinder.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,66 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.plugins;
+
+import com.google.inject.Binder;
+import com.google.inject.spi.SourceProviders;
+import org.jboss.kernel.Kernel;
+import org.jboss.guice.spi.GuiceIntegration;
+import org.jboss.guice.spi.ControllerContextBindFilter;
+
+/**
+ * Microcontainer + Guice binder.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GuiceBinder extends GuiceIntegration
+{
+   static
+   {
+      SourceProviders.skip(GuiceBinder.class);
+   }
+
+   private ControllerContextBindFilter filter;
+
+   public GuiceBinder(Kernel kernel, Binder binder)
+   {
+      super(kernel, binder);
+   }
+
+   public void start()
+   {
+      if (filter == null)
+         bindAll(getBinder(), getController());
+      else
+         bindAll(getBinder(), getController(), filter);
+   }
+
+   public void stop()
+   {
+      // todo - unbind all
+   }
+
+   public void setFilter(ControllerContextBindFilter filter)
+   {
+      this.filter = filter;
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceInjectorFactory.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceInjectorFactory.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceInjectorFactory.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,173 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.plugins;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Binding;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.Provider;
+import com.google.inject.TypeLiteral;
+import com.google.inject.spi.SourceProviders;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+
+/**
+ * Guice Injector factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GuiceInjectorFactory implements Injector
+{
+   static
+   {
+      SourceProviders.skip(GuiceInjectorFactory.class);
+   }
+
+   private Kernel kernel;
+   private Injector injector;
+   private Set<String> objects;
+
+   private GuiceInjectorFactory(Kernel kernel, Injector injector, Set<String> objects)
+   {
+      this.kernel = kernel;
+      this.injector = injector;
+      this.objects = objects;
+   }
+
+   /**
+    * Create injector.
+    * Install all Guice objects.
+    *
+    * @param kernel the kernel
+    * @param guiceObjects guice objects
+    * @return injector instance
+    */
+   public static Injector createInjector(final Kernel kernel, final GuiceObject... guiceObjects)
+   {
+      if (kernel == null)
+         throw new IllegalArgumentException("Null kernel.");
+
+      final Set<String> objects = new HashSet<String>();
+      Injector injector = Guice.createInjector(new AbstractModule()
+      {
+         protected void configure()
+         {
+            KernelController controller = kernel.getController();
+            List<Throwable> errors = null;
+            for(GuiceObject gObject : guiceObjects)
+            {
+               try
+               {
+                  String name = gObject.geName();
+                  Object target = gObject.createObject(kernel, binder());
+                  if (target == null)
+                     throw new IllegalArgumentException("Null target.");
+
+                  String beanClassName = target.getClass().getName();
+                  AbstractBeanMetaData beanMetaData = new AbstractBeanMetaData(name, beanClassName);
+                  KernelControllerContext context = controller.install(beanMetaData, target);
+                  objects.add(name);
+                  controller.change(context, ControllerState.INSTALLED);
+               }
+               catch (Throwable t)
+               {
+                  if (errors == null)
+                     errors = new ArrayList<Throwable>();
+                  errors.add(t);
+               }
+            }
+            if (errors != null)
+               throw new Error("Exception during Guice Objects installation: " + errors);
+         }
+      });
+      return new GuiceInjectorFactory(kernel, injector, objects);
+   }
+
+   /**
+    * Uninstall Guice objects.
+    */
+   public void destroy()
+   {
+      KernelController controller = kernel.getController();
+      for(String name : objects)
+      {
+         if (controller.getInstalledContext(name) != null)
+            controller.uninstall(name);
+      }
+      objects.clear();
+      objects = null;
+      kernel = null;
+   }
+
+   // injector delegate
+
+   public void injectMembers(Object o)
+   {
+      injector.injectMembers(o);
+   }
+
+   public Map<Key<?>, Binding<?>> getBindings()
+   {
+      return injector.getBindings();
+   }
+
+   public <T> Binding<T> getBinding(Key<T> key)
+   {
+      return injector.getBinding(key);
+   }
+
+   public <T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type)
+   {
+      return injector.findBindingsByType(type);
+   }
+
+   public <T> Provider<T> getProvider(Key<T> key)
+   {
+      return injector.getProvider(key);
+   }
+
+   public <T> Provider<T> getProvider(Class<T> type)
+   {
+      return injector.getProvider(type);
+   }
+
+   public <T> T getInstance(Key<T> key)
+   {
+      return injector.getInstance(key);
+   }
+
+   public <T> T getInstance(Class<T> type)
+   {
+      return injector.getInstance(type);
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceListener.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceListener.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceListener.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,91 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.plugins;
+
+import com.google.inject.Binder;
+import com.google.inject.spi.SourceProviders;
+import org.jboss.guice.spi.ControllerContextBindFilter;
+import org.jboss.guice.spi.GuiceIntegration;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.event.KernelEvent;
+import org.jboss.kernel.spi.event.KernelEventListener;
+import org.jboss.kernel.spi.registry.KernelRegistry;
+import org.jboss.kernel.spi.registry.KernelRegistryEntry;
+
+/**
+ * Microcontainer listener that binds newly added
+ * controller context to binder.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GuiceListener extends GuiceIntegration implements KernelEventListener
+{
+   static
+   {
+      SourceProviders.skip(GuiceListener.class);
+   }
+
+   private KernelRegistry registry;
+   private ControllerContextBindFilter filter;
+
+   public GuiceListener(Kernel kernel, Binder binder)
+   {
+      super(kernel, binder);
+      this.registry = kernel.getRegistry();
+   }
+
+   public void start() throws Throwable
+   {
+      registry.registerListener(this, null, null);
+   }
+
+   public void stop() throws Throwable
+   {
+      registry.unregisterListener(this, null, null);
+   }
+
+   public void onEvent(KernelEvent event, Object handback)
+   {
+      Object name = event.getContext();
+      String type = event.getType();
+      if (KernelRegistry.KERNEL_REGISTRY_REGISTERED.equals(type))
+      {
+         Object source = event.getSource();
+         if (source instanceof KernelRegistry)
+         {
+            KernelRegistry registry = (KernelRegistry)source;
+            KernelRegistryEntry entry = registry.getEntry(name);
+            if (filter == null || filter.bind(entry))
+               bindContext(getBinder(), getController(), entry);
+         }
+      }
+      else if (KernelRegistry.KERNEL_REGISTRY_UNREGISTERED.equals(type))
+      {
+         // todo - can we unbind from binder?
+      }
+   }
+
+   public void setFilter(ControllerContextBindFilter filter)
+   {
+      this.filter = filter;
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceObject.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceObject.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/GuiceObject.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.plugins;
+
+import com.google.inject.Binder;
+import org.jboss.kernel.Kernel;
+
+/**
+ * Guice Objects.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface GuiceObject
+{
+   static final GuiceObject ALL = new AllGuiceObject();
+   static final GuiceObject KERNEL = new KernelGuiceObject();
+//   static final GuiceObject LISTENER = new ListenerGuiceObject();
+
+   /**
+    * Get the name.
+    *
+    * @return the name
+    */
+   String geName();
+
+   /**
+    * Create new MC-Guice object.
+    *
+    * @param kernel the kernel
+    * @param binder the binder
+    * @return new MC-Guice object instance
+    */
+   Object createObject(Kernel kernel, Binder binder);
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/InstanceBinder.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/InstanceBinder.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/InstanceBinder.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,78 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.plugins;
+
+import java.util.Map;
+
+import com.google.inject.Binder;
+import com.google.inject.spi.SourceProviders;
+import org.jboss.guice.spi.BinderHolder;
+
+/**
+ * Microcontainer + Guice instance binder.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class InstanceBinder extends BinderHolder
+{
+   static
+   {
+      SourceProviders.skip(InstanceBinder.class);
+   }
+
+   private Map<Class, Object> bindings;
+
+   public InstanceBinder(Binder binder)
+   {
+      super(binder);
+   }
+
+   @SuppressWarnings("unchecked")
+   public void start()
+   {
+      if (bindings != null && bindings.isEmpty() == false)
+      {
+         for(Map.Entry<Class, Object> entry : bindings.entrySet())
+         {
+            Object value = entry.getValue();
+            if (value == null)
+               throw new IllegalArgumentException("Null value in map: " + bindings);
+            Class clazz = entry.getKey();
+            if (clazz == null)
+               clazz = value.getClass();
+            if (clazz.isAssignableFrom(value.getClass()) == false)
+               throw new IllegalArgumentException("Value " + value + " doesn't implement class " + clazz);
+            getBinder().bind(clazz).toInstance(value);
+         }
+      }
+   }
+
+   public void stop()
+   {
+      // todo - unbind all
+   }
+
+   public void setBindings(Map<Class, Object> bindings)
+   {
+      this.bindings = bindings;
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/KernelGuiceObject.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/KernelGuiceObject.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/KernelGuiceObject.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.plugins;
+
+import com.google.inject.Binder;
+import org.jboss.kernel.Kernel;
+
+/**
+ * Bind Kernel instances.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+class KernelGuiceObject implements GuiceObject
+{
+   public static GuiceObject getInstance()
+   {
+      return KERNEL;
+   }
+
+   public String geName()
+   {
+      return "Guice_Kernel";
+   }
+
+   public Object createObject(Kernel kernel, Binder binder)
+   {
+      return new KernelInstanceBinder(binder);
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/KernelInstanceBinder.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/KernelInstanceBinder.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/KernelInstanceBinder.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,84 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.plugins;
+
+import java.util.Map;
+
+import com.google.inject.Binder;
+import com.google.inject.spi.SourceProviders;
+import org.jboss.beans.metadata.plugins.annotations.EntryValue;
+import org.jboss.beans.metadata.plugins.annotations.Inject;
+import org.jboss.beans.metadata.plugins.annotations.MapValue;
+import org.jboss.beans.metadata.plugins.annotations.StringValue;
+import org.jboss.beans.metadata.plugins.annotations.Value;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
+
+/**
+ * Kernel instance binder.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class KernelInstanceBinder extends InstanceBinder
+{
+   static
+   {
+      SourceProviders.skip(KernelInstanceBinder.class);
+   }
+
+   public KernelInstanceBinder(Binder binder)
+   {
+      super(binder);
+   }
+
+   @MapValue(
+         value = {
+                  @EntryValue(
+                        key = @Value(type = "java.lang.Class", string = @StringValue(value="org.jboss.dependency.spi.Controller", type = "java.lang.Class")),
+                        value = @Value(inject = @Inject(bean = KernelConstants.KERNEL_CONTROLLER_NAME))
+                  ),
+                  @EntryValue(
+                        key = @Value(type = "java.lang.Class", string = @StringValue(value="org.jboss.kernel.Kernel", type = "java.lang.Class")),
+                        value = @Value(inject = @Inject(bean = KernelConstants.KERNEL_NAME))
+                  ),
+                  @EntryValue(
+                        key = @Value(type = "java.lang.Class", string = @StringValue(value="org.jboss.kernel.spi.dependency.KernelController", type = "java.lang.Class")),
+                        value = @Value(inject = @Inject(bean = KernelConstants.KERNEL_CONTROLLER_NAME))
+                  ),
+                  @EntryValue(
+                        key = @Value(type = "java.lang.Class", string = @StringValue(value="org.jboss.kernel.spi.registry.KernelBus", type = "java.lang.Class")),
+                        value = @Value(inject = @Inject(bean = KernelConstants.KERNEL_BUS_NAME))
+                  ),
+                  @EntryValue(
+                        key = @Value(type = "java.lang.Class", string = @StringValue(value="org.jboss.kernel.spi.registry.KernelRegistry", type = "java.lang.Class")),
+                        value = @Value(inject = @Inject(bean = KernelConstants.KERNEL_REGISTRY_NAME))
+                  ),
+                  @EntryValue(
+                        key = @Value(type = "java.lang.Class", string = @StringValue(value="org.jboss.kernel.spi.config.KernelConfigurator", type = "java.lang.Class")),
+                        value = @Value(inject = @Inject(bean = KernelConstants.KERNEL_CONFIGURATOR_NAME))
+                  )
+               }
+   )
+   public void setBindings(Map<Class, Object> bindings)
+   {
+      super.setBindings(bindings);
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/ListenerGuiceObject.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/ListenerGuiceObject.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/ListenerGuiceObject.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.plugins;
+
+import com.google.inject.Binder;
+import org.jboss.kernel.Kernel;
+
+/**
+ * Create Guice listener.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+class ListenerGuiceObject implements GuiceObject
+{
+/*
+   public static  GuiceObject getInstance()
+   {
+      return LISTENER;
+   }
+*/
+
+   public String geName()
+   {
+      return "Guice_Listener";
+   }
+
+   public Object createObject(Kernel kernel, Binder binder)
+   {
+      return new GuiceListener(kernel, binder);
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/NameControllerContextBindFilter.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/NameControllerContextBindFilter.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/plugins/NameControllerContextBindFilter.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,47 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.plugins;
+
+import org.jboss.guice.spi.ControllerContextBindFilter;
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * Name controller context bind filter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class NameControllerContextBindFilter implements ControllerContextBindFilter
+{
+   public boolean bind(ControllerContext context)
+   {
+      return context != null && bind(context.getName());
+   }
+
+   /**
+    * Should we bind param context
+    * with param name to Guice.
+    *
+    * @param name the context's name
+    * @return true if we should bind context, false otherwise
+    */
+   protected abstract boolean bind(Object name);
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/BinderHolder.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/BinderHolder.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/BinderHolder.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.spi;
+
+import com.google.inject.Binder;
+
+/**
+ * Binder ref holder.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class BinderHolder
+{
+   private Binder binder;
+
+   protected BinderHolder(Binder binder)
+   {
+      if (binder == null)
+         throw new IllegalArgumentException("Null binder.");
+      this.binder = binder;
+   }
+
+   /**
+    * Get the binder.
+    *
+    * @return the binder
+    */
+   protected Binder getBinder()
+   {
+      return binder;
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/ControllerContextBindFilter.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/ControllerContextBindFilter.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/ControllerContextBindFilter.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.spi;
+
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * Controller context bind filter,
+ * choose which conetxt;s get bind to Guice.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface ControllerContextBindFilter
+{
+   /**
+    * Should we bind param context to Guice.
+    *
+    * @param context the context to check
+    * @return true if we should bind context, false otherwise
+    */
+   boolean bind(ControllerContext context);
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/GuiceIntegration.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/GuiceIntegration.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/GuiceIntegration.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,198 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.spi;
+
+import java.util.Set;
+
+import com.google.inject.Binder;
+import com.google.inject.Provider;
+import com.google.inject.name.Names;
+import com.google.inject.spi.SourceProviders;
+import org.jboss.beans.metadata.plugins.factory.GenericBeanFactory;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.config.Configurator;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.reflect.spi.ClassInfo;
+
+/**
+ * Microcontainer + Guice integration.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class GuiceIntegration extends BinderHolder
+{
+   static
+   {
+      SourceProviders.skip(GuiceIntegration.class);
+   }
+
+   private static final ControllerContextBindFilter ALL = new ControllerContextBindFilter()
+   {
+      public boolean bind(ControllerContext context)
+      {
+         return true;
+      }
+   };
+
+   private KernelController controller;
+
+   protected GuiceIntegration(Kernel kernel, Binder binder)
+   {
+      super(binder);
+      if (kernel == null)
+         throw new IllegalArgumentException("Null kernel.");
+      this.controller = kernel.getController();
+   }
+
+   /**
+    * Get the kernel controller.
+    *
+    * @return the kernel controller
+    */
+   protected KernelController getController()
+   {
+      return controller;
+   }
+
+   /**
+    * Creates a provider which looks up objects from Microcontainer using the given name.
+    * Expects a binding to {@link org.jboss.dependency.spi.Controller}. Example usage:
+    * <p/>
+    * <pre>
+    * bind(DataSource.class).toProvider(fromMicrocontainer(DataSource.class, "dataSource"));
+    * </pre>
+    *
+    * @param type the class type
+    * @param name the bean name
+    * @return Provider instance
+    */
+   public static <T> Provider<T> fromMicrocontainer(Class<T> type, String name)
+   {
+      return new InjectableMicrocontainerProvider<T>(type, name);
+   }
+
+   /**
+    * Binds all Microcontainer beans from the given factory by name. For a MC bean
+    * named "foo", this method creates a binding to the bean's type and
+    * {@code @Named("foo")}.
+    *
+    * @param binder     the binder
+    * @param controller the controller
+    * @see com.google.inject.name.Named
+    * @see com.google.inject.name.Names#named(String)
+    */
+   public static void bindAll(Binder binder, Controller controller)
+   {
+      bindAll(binder, controller, ALL);
+   }
+
+   /**
+    * Binds all Microcontainer beans from the given factory by name. For a MC bean
+    * named "foo", this method creates a binding to the bean's type and
+    * {@code @Named("foo")}.
+    *
+    * @param binder     the binder
+    * @param controller the controller
+    * @param filter the filter
+    * @see com.google.inject.name.Named
+    * @see com.google.inject.name.Names#named(String)
+    */
+   public static void bindAll(Binder binder, Controller controller, ControllerContextBindFilter filter)
+   {
+      Set<ControllerContext> installedContexts = controller.getContextsByState(ControllerState.INSTALLED);
+      if (installedContexts != null && installedContexts.isEmpty() == false)
+      {
+         for (ControllerContext context : installedContexts)
+         {
+            if (filter.bind(context))
+               bindContext(binder, controller, context);
+         }
+      }
+   }
+
+   /**
+    * Bind controller context.
+    *
+    * @param binder     the binder
+    * @param controller the controller
+    * @param context    the context
+    */
+   protected static void bindContext(Binder binder, Controller controller, ControllerContext context)
+   {
+      Class<?> targetClass = null;
+      Object target = context.getTarget();
+      if (target != null)
+      {
+         targetClass = target.getClass();
+         // is target bean factory
+         if (GenericBeanFactory.class.isAssignableFrom(targetClass))
+         {
+            GenericBeanFactory gbf = (GenericBeanFactory)target;
+            String bean = gbf.getBean();
+            if (bean != null && controller instanceof KernelController)
+            {
+               try
+               {
+                  ClassLoader classLoader = Configurator.getClassLoader(gbf.getClassLoader());
+                  KernelController kernelController = (KernelController)controller;
+                  KernelConfigurator configurator = kernelController.getKernel().getConfigurator();
+                  ClassInfo info = configurator.getClassInfo(bean, classLoader);
+                  targetClass = info.getType();
+               }
+               catch (Throwable t)
+               {
+                  throw new RuntimeException(t);
+               }
+            }
+         }
+      }
+      if (targetClass != null)
+      {
+         bindBean(binder, controller, context.getName().toString(), targetClass);
+         Set<Object> aliases = context.getAliases();
+         if (aliases != null && aliases.isEmpty() == false)
+         {
+            for (Object alias : aliases)
+               bindBean(binder, controller, alias.toString(), targetClass);
+         }
+      }
+   }
+
+   /**
+    * Bind bean.
+    *
+    * @param binder     the binder
+    * @param controller the controller
+    * @param name       the name
+    * @param type       the type
+    */
+   static <T> void bindBean(Binder binder, Controller controller, String name, Class<T> type)
+   {
+      MicrocontainerProvider<T> provider = new MicrocontainerProvider<T>(type, name);
+      provider.initialize(controller);
+      binder.bind(type).annotatedWith(Names.named(name)).toProvider(provider);
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/InjectableMicrocontainerProvider.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/InjectableMicrocontainerProvider.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/InjectableMicrocontainerProvider.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.spi;
+
+import com.google.inject.Inject;
+import org.jboss.dependency.spi.Controller;
+
+/**
+ * Injectable Microcontainer provider.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+class InjectableMicrocontainerProvider<T> extends MicrocontainerProvider<T>
+{
+   public InjectableMicrocontainerProvider(Class<T> type, String name)
+   {
+      super(type, name);
+   }
+
+   @Inject
+   @Override
+   void initialize(Controller controller)
+   {
+      super.initialize(controller);
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/MicrocontainerProvider.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/MicrocontainerProvider.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/MicrocontainerProvider.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,79 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.guice.spi;
+
+import com.google.inject.Provider;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.beans.metadata.spi.factory.BeanFactory;
+
+/**
+ * Microcontainer provider.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+class MicrocontainerProvider<T> implements Provider<T>
+{
+   private Class<T> type;
+   private String name;
+   private Controller controller;
+
+   protected MicrocontainerProvider(Class<T> type, String name)
+   {
+      if (type == null)
+         throw new IllegalArgumentException("Null type.");
+      this.type = type;
+      if (name == null)
+         throw new IllegalArgumentException("Null name.");
+      this.name = name;
+   }
+
+   void initialize(Controller controller)
+   {
+      this.controller = controller;
+   }
+
+   public T get()
+   {
+      if (controller == null)
+         throw new IllegalArgumentException("Null controller, missing initialization.");
+
+      ControllerContext context = controller.getInstalledContext(name);
+      if (context != null)
+      {
+         Object target = context.getTarget();
+         if (target instanceof BeanFactory)
+         {
+            try
+            {
+               target = ((BeanFactory)target).createBean();
+            }
+            catch (Throwable t)
+            {
+               throw new RuntimeException(t);
+            }
+         }
+         return type.cast(target);
+      }
+      return null;
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/Prototype.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/Prototype.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/Prototype.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,29 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.guice.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class Prototype
+{
+}

Added: projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/Singleton.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/Singleton.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/Singleton.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,29 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.guice.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class Singleton
+{
+}

Added: projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceIntegrationTestCase.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceIntegrationTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceIntegrationTestCase.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,138 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.guice.test;
+
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+import org.jboss.test.guice.support.Singleton;
+import org.jboss.test.guice.support.Prototype;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.guice.spi.GuiceIntegration;
+import junit.framework.Test;
+import com.google.inject.Injector;
+import com.google.inject.Guice;
+import com.google.inject.AbstractModule;
+import com.google.inject.Key;
+import com.google.inject.name.Names;
+
+/**
+ * Guice integration test case.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GuiceIntegrationTestCase extends MicrocontainerTest
+{
+   public GuiceIntegrationTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Setup the test
+    *
+    * @return the test
+    */
+   public static Test suite()
+   {
+      return suite(GuiceIntegrationTestCase.class);
+   }
+
+   protected KernelController getController()
+   {
+      BasicBootstrap bootstrap = new BasicBootstrap();
+      bootstrap.run();
+      return bootstrap.getKernel().getController();
+   }
+
+   protected void installBeans(KernelController controller)
+         throws Throwable
+   {
+      BeanMetaData singleton = new AbstractBeanMetaData("singleton", Singleton.class.getName());
+      controller.install(singleton);
+
+      BeanMetaData prototype = new GenericBeanFactoryMetaData("prototype", Prototype.class.getName());
+      controller.install(prototype);
+   }
+
+   public void testBindFromMicrocontainer() throws Throwable
+   {
+      final KernelController controller = getController();
+      try
+      {
+         installBeans(controller);
+
+         Injector injector = Guice.createInjector(new AbstractModule()
+         {
+            protected void configure()
+            {
+               bind(Controller.class).toInstance(controller);
+               bind(Singleton.class).toProvider(GuiceIntegration.fromMicrocontainer(Singleton.class, "singleton"));
+               bind(Prototype.class).toProvider(GuiceIntegration.fromMicrocontainer(Prototype.class, "prototype"));
+            }
+         });
+
+         assertNotNull(injector.getInstance(Singleton.class));
+         assertSame(injector.getInstance(Singleton.class), injector.getInstance(Singleton.class));
+
+         assertNotNull(injector.getInstance(Prototype.class));
+         assertNotSame(injector.getInstance(Prototype.class), injector.getInstance(Prototype.class));
+      }
+      finally
+      {
+         controller.shutdown();
+      }
+   }
+
+   public void testBindAll() throws Throwable
+   {
+      final KernelController controller = getController();
+      try
+      {
+         installBeans(controller);
+
+         Injector injector = Guice.createInjector(new AbstractModule()
+         {
+            protected void configure()
+            {
+               GuiceIntegration.bindAll(binder(), controller);
+            }
+         });
+
+         Key<Singleton> singletonKey = Key.get(Singleton.class, Names.named("singleton"));
+         Key<Prototype> prototypeKey = Key.get(Prototype.class, Names.named("prototype"));
+
+         assertNotNull(injector.getInstance(singletonKey));
+         assertSame(injector.getInstance(singletonKey), injector.getInstance(singletonKey));
+
+         assertNotNull(injector.getInstance(prototypeKey));
+         assertNotSame(injector.getInstance(prototypeKey), injector.getInstance(prototypeKey));
+      }
+      finally
+      {
+         controller.shutdown();
+      }
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceObjectsTestCase.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceObjectsTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceObjectsTestCase.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,165 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.guice.test;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+import org.jboss.test.guice.support.Prototype;
+import org.jboss.test.guice.support.Singleton;
+import org.jboss.guice.plugins.GuiceInjectorFactory;
+import org.jboss.guice.plugins.GuiceObject;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractArrayMetaData;
+import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
+import org.jboss.beans.metadata.plugins.factory.GenericBeanFactoryMetaData;
+import org.jboss.dependency.spi.ControllerContext;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.name.Names;
+
+/**
+ * Guice test case via installed objects.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GuiceObjectsTestCase extends MicrocontainerTest
+{
+   public GuiceObjectsTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Setup the test
+    *
+    * @return the test
+    */
+   public static Test suite()
+   {
+      return suite(GuiceObjectsTestCase.class);
+   }
+
+   private KernelController getController()
+   {
+      BasicBootstrap bootstrap = new BasicBootstrap();
+      bootstrap.run();
+      return bootstrap.getKernel().getController();
+   }
+
+/*
+   // TODO - resolved when Guice Issue 49 is implemented 
+   public void testBindFromListener() throws Throwable
+   {
+      final KernelController controller = getController();
+      try
+      {
+         AbstractBeanMetaData injectorBean = new AbstractBeanMetaData("injector", GuiceInjectorFactory.class.getName());
+         AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
+         constructor.setFactoryClass(GuiceInjectorFactory.class.getName());
+         constructor.setFactoryMethod("createInjector");
+         List<ParameterMetaData> parameters = new ArrayList<ParameterMetaData>();
+         parameters.add(new AbstractParameterMetaData(new AbstractDependencyValueMetaData(KernelConstants.KERNEL_NAME)));
+         AbstractArrayMetaData array = new AbstractArrayMetaData();
+         array.add(new AbstractValueMetaData(GuiceObject.LISTENER));
+         array.add(new AbstractValueMetaData(GuiceObject.KERNEL));
+         parameters.add(new AbstractParameterMetaData(array));
+         constructor.setParameters(parameters);
+         injectorBean.setConstructor(constructor);
+         controller.install(injectorBean);
+
+         BeanMetaData singleton = new AbstractBeanMetaData("singleton", Singleton.class.getName());
+         controller.install(singleton);
+
+         BeanMetaData prototype = new GenericBeanFactoryMetaData("prototype", Prototype.class.getName());
+         controller.install(prototype);
+
+         ControllerContext injectorContext = controller.getInstalledContext("injector");
+         assertNotNull(injectorContext);
+         Injector injector = (Injector)injectorContext.getTarget();
+
+         assertNotNull(injector.getInstance(Singleton.class));
+         assertSame(injector.getInstance(Singleton.class), injector.getInstance(Singleton.class));
+
+         assertNotNull(injector.getInstance(Prototype.class));
+         assertNotSame(injector.getInstance(Prototype.class), injector.getInstance(Prototype.class));
+      }
+      finally
+      {
+         controller.shutdown();
+      }
+   }
+*/
+
+   public void testBindAll() throws Throwable
+   {
+      final KernelController controller = getController();
+      try
+      {
+         BeanMetaData singleton = new AbstractBeanMetaData("singleton", Singleton.class.getName());
+         controller.install(singleton);
+
+         BeanMetaData prototype = new GenericBeanFactoryMetaData("prototype", Prototype.class.getName());
+         controller.install(prototype);
+
+         AbstractBeanMetaData injectorBean = new AbstractBeanMetaData("injector", GuiceInjectorFactory.class.getName());
+         AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
+         constructor.setFactoryClass(GuiceInjectorFactory.class.getName());
+         constructor.setFactoryMethod("createInjector");
+         List<ParameterMetaData> parameters = new ArrayList<ParameterMetaData>();
+         parameters.add(new AbstractParameterMetaData(new AbstractDependencyValueMetaData(KernelConstants.KERNEL_NAME)));
+         AbstractArrayMetaData array = new AbstractArrayMetaData();
+         array.add(new AbstractValueMetaData(GuiceObject.ALL));
+         parameters.add(new AbstractParameterMetaData(array));
+         constructor.setParameters(parameters);
+         injectorBean.setConstructor(constructor);
+         controller.install(injectorBean);
+
+         Key<Singleton> singletonKey = Key.get(Singleton.class, Names.named("singleton"));
+         Key<Prototype> prototypeKey = Key.get(Prototype.class, Names.named("prototype"));
+
+         ControllerContext injectorContext = controller.getInstalledContext("injector");
+         assertNotNull(injectorContext);
+         Injector injector = (Injector)injectorContext.getTarget();
+
+         assertNotNull(injector.getInstance(singletonKey));
+         assertSame(injector.getInstance(singletonKey), injector.getInstance(singletonKey));
+
+         assertNotNull(injector.getInstance(prototypeKey));
+         assertNotSame(injector.getInstance(prototypeKey), injector.getInstance(prototypeKey));
+      }
+      finally
+      {
+         controller.shutdown();
+      }
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceTestSuite.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceTestSuite.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceTestSuite.java	2007-09-19 19:02:47 UTC (rev 65479)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.guice.test;
+
+import junit.textui.TestRunner;
+import junit.framework.TestSuite;
+import junit.framework.Test;
+
+/**
+ * Guice test suite.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GuiceTestSuite extends TestSuite
+{
+
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Guice Tests");
+
+      suite.addTest(GuiceIntegrationTestCase.suite());
+      suite.addTest(GuiceObjectsTestCase.suite());
+
+      return suite;
+   }
+
+}

Modified: projects/microcontainer/trunk/osgi-int/pom-jdk14.xml
===================================================================
--- projects/microcontainer/trunk/osgi-int/pom-jdk14.xml	2007-09-19 18:33:21 UTC (rev 65478)
+++ projects/microcontainer/trunk/osgi-int/pom-jdk14.xml	2007-09-19 19:02:47 UTC (rev 65479)
@@ -19,7 +19,7 @@
   <modelVersion>4.0.0</modelVersion>
   <artifactId>jboss-osgi-int-jdk14</artifactId>
   <packaging>jar</packaging>
-  <name>JBoss Microcontainer OSGI INT</name>
+  <name>JBoss Microcontainer OSGi Int</name>
   <url>http://www.jboss.com/products/jbossmc</url>
   <description>JBoss Microcontainer</description>
   <build>

Modified: projects/microcontainer/trunk/osgi-int/pom.xml
===================================================================
--- projects/microcontainer/trunk/osgi-int/pom.xml	2007-09-19 18:33:21 UTC (rev 65478)
+++ projects/microcontainer/trunk/osgi-int/pom.xml	2007-09-19 19:02:47 UTC (rev 65479)
@@ -8,7 +8,7 @@
   <modelVersion>4.0.0</modelVersion>
   <artifactId>jboss-osgi-int</artifactId>
   <packaging>jar</packaging>
-  <name>JBoss Microcontainer OSGI INT</name>
+  <name>JBoss Microcontainer OSGi Int</name>
   <url>http://www.jboss.com/products/jbossmc</url>
   <description>JBoss Microcontainer</description>
   <build>

Modified: projects/microcontainer/trunk/pom.xml
===================================================================
--- projects/microcontainer/trunk/pom.xml	2007-09-19 18:33:21 UTC (rev 65478)
+++ projects/microcontainer/trunk/pom.xml	2007-09-19 19:02:47 UTC (rev 65479)
@@ -40,6 +40,7 @@
     <module>deployers-vfs-spi</module>
     <module>deployers-vfs</module>
     <module>spring-int</module>
+    <module>guice-int</module>
     <module>osgi-int</module>
     <module>classloader</module>
     <module>varia</module>




More information about the jboss-cvs-commits mailing list