[jboss-cvs] JBossAS SVN: r65597 - in projects/microcontainer/trunk: docs/gettingstarted/en-US/src/main/docbook/modules and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 25 10:43:27 EDT 2007


Author: alesj
Date: 2007-09-25 10:43:27 -0400 (Tue, 25 Sep 2007)
New Revision: 65597

Added:
   projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/guice.xml
   projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance.xml
   projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_identity.xml
   projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_jbpm.xml
   projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_rules.xml
   projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/GuiceKernelRegistryEntryPlugin.java
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/SingletonHolder.java
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceToMCTestCase.java
Modified:
   projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/master.xml
   projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceTestSuite.java
Log:
Additional docs + Guice2MC injection.

Modified: projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/master.xml
===================================================================
--- projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/master.xml	2007-09-25 13:00:30 UTC (rev 65596)
+++ projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/master.xml	2007-09-25 14:43:27 UTC (rev 65597)
@@ -80,6 +80,12 @@
    <xi:include href="modules/osgi.xml"
                xml:base="./"
                xmlns:xi="http://www.w3.org/2001/XInclude"/>
+   <xi:include href="modules/reliance.xml"
+               xml:base="./"
+               xmlns:xi="http://www.w3.org/2001/XInclude"/>
+   <xi:include href="modules/guice.xml"
+               xml:base="./"
+               xmlns:xi="http://www.w3.org/2001/XInclude"/>
    <xi:include href="modules/standalone.xml"
                xml:base="./"
                xmlns:xi="http://www.w3.org/2001/XInclude"/>

Added: projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/guice.xml
===================================================================
--- projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/guice.xml	                        (rev 0)
+++ projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/guice.xml	2007-09-25 14:43:27 UTC (rev 65597)
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+      "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+
+<chapter id="guice">
+   <title>Guice integration</title>
+
+   <para>Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 5 and above,
+      brought to you by Google.
+   </para>
+
+   <para>We've written a piece of integration code that bridges the two IoC frameworks together.
+      You can inject Guice defined beans into Microcontainer and/or the other way around.
+      See examples for more details.
+   </para>
+
+   <para>In this example we will define Guice module, binding simple Singleton class to one of it's
+      instances. We will then do a contextual lookup for the Singleton instance in SingletonHolder class.
+   </para>
+
+   <programlisting>
+      AbstractBeanMetaData guicePlugin = new AbstractBeanMetaData("GuicePlugin", GuiceKernelRegistryEntryPlugin.class.getName());
+      AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
+      AbstractArrayMetaData arrayMetaData = new AbstractArrayMetaData();
+      final Singleton singleton = new Singleton();
+      Module module = new AbstractModule()
+      {
+         protected void configure()
+         {
+            bind(Singleton.class).toInstance(singleton);
+         }
+      };
+      arrayMetaData.add(new AbstractValueMetaData(module));
+      constructor.setParameters(Collections.singletonList((ParameterMetaData)new AbstractParameterMetaData(arrayMetaData)));
+      guicePlugin.setConstructor(constructor);
+
+      public class SingletonHolder
+      {
+         private Singleton singleton;
+
+         @Constructor
+         public SingletonHolder(@Inject Singleton singleton)
+         {
+            this.singleton = singleton;
+         }
+
+         public Singleton getSingleton()
+         {
+            return singleton;
+         }
+      }
+
+      ControllerContext holderContext = controller.getInstalledContext("holder");
+      assertNotNull(holderContext);
+      SingletonHolder holder = (SingletonHolder)holderContext.getTarget();
+      assertNotNull(holder);
+      assertEquals(singleton, holder.getSingleton());
+   </programlisting>
+
+   <para>The detail that is hidden is in GuiceKernelRegistryEntryPlugin, which acts as a intermediate between
+      Microcontainer's registry and Guice Injector. But all you need to do is register GuiceKernelRegistryEntryPlugin
+      as a POJO into Microcontainer, providing Guice Modules with its constructor.
+   </para>
+
+   <para>We can also go the other way around. Injecting named beans into Guice Injector. There are a couple of ways
+      to achieve that. Lets look at them.
+   </para>
+
+   <programlisting>
+         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"));
+            }
+         });
+   </programlisting>
+
+   <programlisting>
+         AbstractBeanMetaData injectorBean = new AbstractBeanMetaData("injector", GuiceInjectorFactory.class.getName());
+         AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
+         constructor.setFactoryClass(GuiceInjectorFactory.class.getName());
+         constructor.setFactoryMethod("createInjector");
+         List&lt;ParameterMetaData> parameters = new ArrayList&lt;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);
+
+         ControllerContext injectorContext = controller.getInstalledContext("injector");
+         assertNotNull(injectorContext);
+         Injector injector = (Injector)injectorContext.getTarget();
+   </programlisting>
+
+   <programlisting>
+      &lt;bean name="injector" class="org.jboss.guice.plugins.GuiceInjectorFactory">
+         &lt;constructor factoryClass="org.jboss.guice.plugins.GuiceInjectorFactory" factoryMethod="createInjector">
+            &lt;parameter>jboss.kernel:service=Kernel&lt;/parameter>
+            &lt;parameter>
+               &lt;array>
+                  &lt;bean name="BindAll" class="org.jboss.guice.plugins.AllGuiceObject">
+                     &lt;constructor factoryClass="org.jboss.guice.plugins.AllGuiceObject" factoryMethod="getInstance"/>
+                  &lt;/bean>
+               &lt;/array>
+            &lt;/parameter>
+         &lt;/constructor>
+      &lt;/bean>
+   </programlisting>
+
+   <para>Here we see three way of usgin Microcontainer beans to do wiring in Guice. The first and second examples are
+      purely programmatic and you need to provide a Controller instance. The third one is how you would bind all
+      existing installed beans into Guice Injector via -beans.xml. Or you can provide a ControllerContextBindFilter
+      instance to the binding methods to filter those beans you want to bind. See API docs for more details.
+   </para>
+
+</chapter>

Added: projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance.xml
===================================================================
--- projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance.xml	                        (rev 0)
+++ projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance.xml	2007-09-25 14:43:27 UTC (rev 65597)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+      "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+
+<chapter id="reliance">
+   <title>Reliance modules</title>
+
+   <para>In Microcontainer it's all about dependecies. One of the features we promissed it ability to write your own
+      dependency. As a dependency we mean some condition that must be satisfied in order that a state machine let's
+      a node pass to next state. In our case nodes are our beans, which we eventually want to install into
+      Microcontainer's registry.
+   </para>
+
+   <para>Almost all component models impose some sort of authentification or authorization. We've added a simple
+      identity module that relies on plain java.security concepts. On top of this we added an extension module
+      where you can define your security requirements via Drools declarative rules. Drools integration is not limited
+      to just security handling, it can be extended to suite any Drools defined rules. More about the subject in
+      the chapters below.
+   </para>
+
+   <para>We've also added a jBPM integration to support long lasting state flow definitions. This integration provides
+      a plugable way of notifying state machine nodes that they can move forward to the next state. We'll show a simple
+      human interaction of accepting state change request to move bean into next state.
+   </para>
+
+   <xi:include href="reliance_identity.xml"
+               xml:base="./"
+               xmlns:xi="http://www.w3.org/2001/XInclude"/>
+   <xi:include href="reliance_rules.xml"
+               xml:base="./"
+               xmlns:xi="http://www.w3.org/2001/XInclude"/>
+   <xi:include href="reliance_jbpm.xml"
+               xml:base="./"
+               xmlns:xi="http://www.w3.org/2001/XInclude"/>
+</chapter>
\ No newline at end of file

Added: projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_identity.xml
===================================================================
--- projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_identity.xml	                        (rev 0)
+++ projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_identity.xml	2007-09-25 14:43:27 UTC (rev 65597)
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+      "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+
+<sect1>
+   <title>Reliance identity</title>
+
+   <para>Identity ...
+   </para>
+
+   <sect2>
+      <title>Deployment</title>
+
+      <para>The
+         <varname>deployment</varname>
+         element acts as a container for many beans that are deployed together.
+      </para>
+
+      <programlisting>
+<![CDATA[
+
+         <?xml version="1.0" encoding="UTF-8"?>
+
+         <!-- Deployment holds beans -->
+         <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
+            xmlns="urn:jboss:bean-deployer:2.0">
+
+         <!-- bean part of the deployment -->
+         <bean .../>
+
+         <!-- bean part of the deployment -->
+         <bean .../>
+
+         </deployment&gt;
+
+]]>
+   </programlisting>
+
+   </sect2>
+
+</sect1>

Added: projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_jbpm.xml
===================================================================
--- projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_jbpm.xml	                        (rev 0)
+++ projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_jbpm.xml	2007-09-25 14:43:27 UTC (rev 65597)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+      "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+
+<sect1>
+   <title>Reliance jBPM</title>
+
+   <para>jBPM ...
+   </para>
+
+   <sect2>
+      <title>Deployment</title>
+
+      <para>The
+         <varname>deployment</varname>
+         element acts as a container for many beans that are deployed together.
+      </para>
+
+      <programlisting>
+<![CDATA[
+
+         <?xml version="1.0" encoding="UTF-8"?>
+
+         <!-- Deployment holds beans -->
+         <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
+            xmlns="urn:jboss:bean-deployer:2.0">
+
+         <!-- bean part of the deployment -->
+         <bean .../>
+
+         <!-- bean part of the deployment -->
+         <bean .../>
+
+         </deployment&gt;
+
+]]>
+   </programlisting>
+
+   </sect2>
+</sect1>

Added: projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_rules.xml
===================================================================
--- projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_rules.xml	                        (rev 0)
+++ projects/microcontainer/trunk/docs/gettingstarted/en-US/src/main/docbook/modules/reliance_rules.xml	2007-09-25 14:43:27 UTC (rev 65597)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+      "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+
+<sect1>
+   <title>Reliance rules</title>
+
+   <para>Drools...
+   </para>
+
+   <sect2>
+      <title>Deployment</title>
+
+      <para>The
+         <varname>deployment</varname>
+         element acts as a container for many beans that are deployed together.
+      </para>
+
+      <programlisting>
+<![CDATA[
+
+         <?xml version="1.0" encoding="UTF-8"?>
+
+         <!-- Deployment holds beans -->
+         <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
+            xmlns="urn:jboss:bean-deployer:2.0">
+
+         <!-- bean part of the deployment -->
+         <bean .../>
+
+         <!-- bean part of the deployment -->
+         <bean .../>
+
+         </deployment&gt;
+
+]]>
+   </programlisting>
+
+   </sect2>
+</sect1>

Added: projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/GuiceKernelRegistryEntryPlugin.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/GuiceKernelRegistryEntryPlugin.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/main/org/jboss/guice/spi/GuiceKernelRegistryEntryPlugin.java	2007-09-25 14:43:27 UTC (rev 65597)
@@ -0,0 +1,73 @@
+/*
+* 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.kernel.spi.registry.KernelRegistryPlugin;
+import org.jboss.kernel.spi.registry.KernelRegistryEntry;
+import org.jboss.kernel.plugins.registry.AbstractKernelRegistryEntry;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.Module;
+import com.google.inject.Guice;
+
+/**
+ * Guice kernel registry plugin.
+ * Providing a way to inject Guice beans into MC.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GuiceKernelRegistryEntryPlugin implements KernelRegistryPlugin
+{
+   private Injector injector;
+
+   public GuiceKernelRegistryEntryPlugin(Module... modules)
+   {
+      injector = Guice.createInjector(modules);
+   }
+
+   public void destroy()
+   {
+      injector = null;
+   }
+
+   public KernelRegistryEntry getEntry(Object name)
+   {
+      KernelRegistryEntry entry = null;
+      try
+      {
+         if (name instanceof Class<?>)
+         {
+            Class<?> clazz = (Class<?>)name;
+            entry = new AbstractKernelRegistryEntry(name, injector.getInstance(clazz));
+         }
+         else if (name instanceof Key)
+         {
+            Key<?> key = (Key<?>)name;
+            entry = new AbstractKernelRegistryEntry(name, injector.getInstance(key));
+         }
+      }
+      catch (Exception ignored)
+      {
+      }
+      return entry;
+   }
+}

Added: projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/SingletonHolder.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/SingletonHolder.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/support/SingletonHolder.java	2007-09-25 14:43:27 UTC (rev 65597)
@@ -0,0 +1,44 @@
+/*
+* 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;
+
+import org.jboss.beans.metadata.api.annotations.Constructor;
+import org.jboss.beans.metadata.api.annotations.Inject;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SingletonHolder
+{
+   private Singleton singleton;
+
+   @Constructor
+   public SingletonHolder(@Inject Singleton singleton)
+   {
+      this.singleton = singleton;
+   }
+
+   public Singleton getSingleton()
+   {
+      return singleton;
+   }
+}

Modified: 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	2007-09-25 13:00:30 UTC (rev 65596)
+++ projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceTestSuite.java	2007-09-25 14:43:27 UTC (rev 65597)
@@ -44,6 +44,7 @@
 
       suite.addTest(GuiceIntegrationTestCase.suite());
       suite.addTest(GuiceObjectsTestCase.suite());
+      suite.addTest(GuiceToMCTestCase.suite());
 
       return suite;
    }

Added: projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceToMCTestCase.java
===================================================================
--- projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceToMCTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/guice-int/src/tests/org/jboss/test/guice/test/GuiceToMCTestCase.java	2007-09-25 14:43:27 UTC (rev 65597)
@@ -0,0 +1,108 @@
+/*
+* 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.Collections;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Module;
+import junit.framework.Test;
+import org.jboss.beans.metadata.plugins.AbstractArrayMetaData;
+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.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.guice.spi.GuiceKernelRegistryEntryPlugin;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.test.guice.support.Singleton;
+import org.jboss.test.guice.support.SingletonHolder;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+
+/**
+ * Inject Guice objects into MC test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GuiceToMCTestCase extends MicrocontainerTest
+{
+   public GuiceToMCTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Setup the test
+    *
+    * @return the test
+    */
+   public static Test suite()
+   {
+      return suite(GuiceToMCTestCase.class);
+   }
+
+   private KernelController getController()
+   {
+      BasicBootstrap bootstrap = new BasicBootstrap();
+      bootstrap.run();
+      return bootstrap.getKernel().getController();
+   }
+
+   public void testGuice2MC() throws Throwable
+   {
+      final KernelController controller = getController();
+      try
+      {
+         AbstractBeanMetaData guicePlugin = new AbstractBeanMetaData("GuicePlugin", GuiceKernelRegistryEntryPlugin.class.getName());
+         AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
+         AbstractArrayMetaData arrayMetaData = new AbstractArrayMetaData();
+         final Singleton singleton = new Singleton();
+         Module module = new AbstractModule()
+         {
+            protected void configure()
+            {
+               bind(Singleton.class).toInstance(singleton);
+            }
+         };
+         arrayMetaData.add(new AbstractValueMetaData(module));
+         constructor.setParameters(Collections.singletonList((ParameterMetaData)new AbstractParameterMetaData(arrayMetaData)));
+         guicePlugin.setConstructor(constructor);
+         controller.install(guicePlugin);
+
+         BeanMetaData holderBean = new AbstractBeanMetaData("holder", SingletonHolder.class.getName());
+         controller.install(holderBean);
+
+         ControllerContext holderContext = controller.getInstalledContext("holder");
+         assertNotNull(holderContext);
+         SingletonHolder holder = (SingletonHolder)holderContext.getTarget();
+         assertNotNull(holder);
+         assertEquals(singleton, holder.getSingleton());
+      }
+      finally
+      {
+         controller.shutdown();
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list