[jboss-svn-commits] JBL Code SVN: r19742 - in labs/jbosslabs/labs-3.0-build: integration/seam-guice and 9 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Apr 28 08:30:17 EDT 2008


Author: wrzep
Date: 2008-04-28 08:30:17 -0400 (Mon, 28 Apr 2008)
New Revision: 19742

Added:
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/pom.xml
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/seam-guice.iml
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/EmptyGuiceModule.java
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/Guice.java
   labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/LabsGuiceInterceptor.java
Removed:
   labs/jbosslabs/labs-3.0-build/integration/src/
Modified:
   labs/jbosslabs/labs-3.0-build/integration/
   labs/jbosslabs/labs-3.0-build/integration/pom.xml
   labs/jbosslabs/labs-3.0-build/views/admin/pom.xml
Log:
JBLAB-928 seam&guice integration



Property changes on: labs/jbosslabs/labs-3.0-build/integration
___________________________________________________________________
Name: svn:ignore
   + target
.classpath
.project
.settings
.iml



Modified: labs/jbosslabs/labs-3.0-build/integration/pom.xml
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/pom.xml	2008-04-28 07:19:24 UTC (rev 19741)
+++ labs/jbosslabs/labs-3.0-build/integration/pom.xml	2008-04-28 12:30:17 UTC (rev 19742)
@@ -8,30 +8,14 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.jboss.labs</groupId>
   <artifactId>integration</artifactId>
-  <packaging>jar</packaging>
-  <name>Integration</name>
+  <packaging>pom</packaging>
+  <name>integration</name>
   <version>1.0-SNAPSHOT</version>
   <url>http://maven.apache.org</url>
   <build>
     <finalName>integration</finalName>
   </build>
-  <dependencies>
-     <dependency>
-	  <groupId>org.jboss.labs</groupId>
-	  <artifactId>api</artifactId>
-      <version>1.0</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
-	  <groupId>org.jboss.seam</groupId>
-	  <artifactId>jboss-seam</artifactId>
-      <version>2.1.0.A1</version>
-      <exclusions>
-                <exclusion>
-                  <groupId>jboss</groupId>
-                  <artifactId>javassist</artifactId>
-                </exclusion>
-       </exclusions>
-    </dependency>
-  </dependencies>
-</project>
\ No newline at end of file
+  <modules>
+    <module>seam-guice</module>
+  </modules>
+</project>


Property changes on: labs/jbosslabs/labs-3.0-build/integration/seam-guice
___________________________________________________________________
Name: svn:ignore
   + target
.classpath
.project
.settings
.iml



Added: labs/jbosslabs/labs-3.0-build/integration/seam-guice/pom.xml
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/seam-guice/pom.xml	                        (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/pom.xml	2008-04-28 12:30:17 UTC (rev 19742)
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<project>
+   <parent>
+    <artifactId>integration</artifactId>
+    <groupId>org.jboss.labs</groupId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.jboss.labs</groupId>
+  <artifactId>seam-guice</artifactId>
+  <packaging>jar</packaging>
+  <name>seam-guice</name>
+  <version>1.0</version>
+  <url>http://maven.apache.org</url>
+  <build>
+    <finalName>seam-guice</finalName>
+  </build>
+  <dependencies>
+     <dependency>
+	  <groupId>org.jboss.labs</groupId>
+	  <artifactId>api</artifactId>
+      <version>1.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+	  <groupId>org.jboss.seam</groupId>
+	  <artifactId>jboss-seam</artifactId>
+      <version>2.1.0.A1</version>
+      <exclusions>
+                <exclusion>
+                  <groupId>jboss</groupId>
+                  <artifactId>javassist</artifactId>
+                </exclusion>
+       </exclusions>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Added: labs/jbosslabs/labs-3.0-build/integration/seam-guice/seam-guice.iml
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/seam-guice/seam-guice.iml	                        (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/seam-guice.iml	2008-04-28 12:30:17 UTC (rev 19742)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntryProperties />
+  </component>
+</module>
+

Added: labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/EmptyGuiceModule.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/EmptyGuiceModule.java	                        (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/EmptyGuiceModule.java	2008-04-28 12:30:17 UTC (rev 19742)
@@ -0,0 +1,36 @@
+/*
+* JBoss Labs. http://labs.jboss.com/jbosslabs
+*
+* Copyright © 2008  Red Hat Middleware, LLC. All rights reserved.
+*
+* This copyrighted material is made available to anyone wishing to use,
+* modify, copy, or redistribute it subject to the terms and conditions
+* of the GNU Lesser General Public License, v. 2.1.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+* 02110-1301, USA.
+*
+* Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik,
+*     Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
+*/
+
+package org.jboss.labs.injection.seam;
+
+import com.google.inject.Module;
+import com.google.inject.Binder;
+
+/**
+ * @author Pawel Wrzeszcz (pwrzeszcz [at] jboss . org)
+ */
+
+public class EmptyGuiceModule implements Module
+{
+    public void configure(Binder binder) {}
+}
\ No newline at end of file

Added: labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/Guice.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/Guice.java	                        (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/Guice.java	2008-04-28 12:30:17 UTC (rev 19742)
@@ -0,0 +1,43 @@
+/*
+* JBoss Labs. http://labs.jboss.com/jbosslabs
+*
+* Copyright © 2008  Red Hat Middleware, LLC. All rights reserved.
+*
+* This copyrighted material is made available to anyone wishing to use,
+* modify, copy, or redistribute it subject to the terms and conditions
+* of the GNU Lesser General Public License, v. 2.1.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+* 02110-1301, USA.
+*
+* Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik,
+*     Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
+*/
+
+package org.jboss.labs.injection.seam;
+
+import org.jboss.seam.annotations.intercept.Interceptors;
+
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * @author Pawel Wrzeszcz (pwrzeszcz [at] jboss . org)
+ */
+ at Target(TYPE)
+ at Retention(RUNTIME)
+ at Interceptors(LabsGuiceInterceptor.class)
+public @interface Guice
+{
+    String value() default "";
+    Class module() default EmptyGuiceModule.class;
+}

Added: labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/LabsGuiceInterceptor.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/LabsGuiceInterceptor.java	                        (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/LabsGuiceInterceptor.java	2008-04-28 12:30:17 UTC (rev 19742)
@@ -0,0 +1,116 @@
+/*
+* JBoss Labs. http://labs.jboss.com/jbosslabs
+*
+* Copyright © 2008  Red Hat Middleware, LLC. All rights reserved.
+*
+* This copyrighted material is made available to anyone wishing to use,
+* modify, copy, or redistribute it subject to the terms and conditions
+* of the GNU Lesser General Public License, v. 2.1.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+* 02110-1301, USA.
+*
+* Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik,
+*     Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
+*/
+
+package org.jboss.labs.injection.seam;
+
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import org.jboss.seam.Component;
+import org.jboss.seam.annotations.intercept.AroundInvoke;
+import org.jboss.seam.annotations.intercept.Interceptor;
+import org.jboss.seam.intercept.AbstractInterceptor;
+import org.jboss.seam.intercept.InvocationContext;
+import org.jboss.seam.log.Log;
+import org.jboss.seam.log.Logging;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Pawel Wrzeszcz (pwrzeszcz [at] jboss . org)
+ */
+ at Interceptor
+public class LabsGuiceInterceptor extends AbstractInterceptor
+{
+    private final static Log log = Logging.getLog(LabsGuiceInterceptor.class);
+    
+    private static final long serialVersionUID = -6716553117162905303L;
+
+    private static final ConcurrentHashMap<Class, Injector> INJECTOR_CACHE
+                                 = new ConcurrentHashMap<Class, Injector>();
+
+    private static final String DEFAULT_GUICE_MODULE_COMPONENT
+                                 = "org.jboss.labs.injection.seam.guiceModule";
+
+    @AroundInvoke
+    public Object aroundInvoke(InvocationContext invocationContext) throws Exception
+    {
+        Module module = getGuiceModule(invocationContext.getMethod().getDeclaringClass());
+
+        if (module == null)
+        {
+            throw new IllegalStateException("Guice module not specified.");
+        }
+
+        log.debug("Injecting members for: "
+				+ invocationContext.getTarget().getClass().getName()
+                + " using module " + module);
+
+        Injector injector = getModuleInjectorFromCache(module);
+        injector.injectMembers(invocationContext.getTarget());        
+
+        return invocationContext.proceed();
+    }
+
+    private static Injector getModuleInjectorFromCache(Module module)
+    {
+        Injector injector = INJECTOR_CACHE.get(module.getClass());
+
+        if (injector == null)
+        {
+            log.debug("Injector not found in cache. Creating a new one.");
+
+            injector = com.google.inject.Guice.createInjector(module);
+            INJECTOR_CACHE.put(module.getClass(), injector);
+        }
+
+        return injector;
+    }
+
+    private static Module getGuiceModule(final Class<?> declaringClass)
+                        throws IllegalAccessException, InstantiationException
+    {
+        Module module;
+
+        final String moduleComponentName = declaringClass.getAnnotation(Guice.class).value();
+
+        if (moduleComponentName.length() > 0)
+        {
+            module = (Module) Component.getInstance(moduleComponentName);
+        }
+        else
+        {
+            final Class moduleClass
+                        = declaringClass.getAnnotation(Guice.class).module();
+            if (!moduleClass.equals(EmptyGuiceModule.class))
+            {
+                module = (Module) moduleClass.newInstance();
+            }
+            else
+            {
+                module = (Module) Component.getInstance(DEFAULT_GUICE_MODULE_COMPONENT);
+            }
+        }
+
+        return module;
+    }
+}

Modified: labs/jbosslabs/labs-3.0-build/views/admin/pom.xml
===================================================================
--- labs/jbosslabs/labs-3.0-build/views/admin/pom.xml	2008-04-28 07:19:24 UTC (rev 19741)
+++ labs/jbosslabs/labs-3.0-build/views/admin/pom.xml	2008-04-28 12:30:17 UTC (rev 19742)
@@ -18,8 +18,8 @@
   <dependencies>
     <dependency>
 	  <groupId>org.jboss.labs</groupId>
-	  <artifactId>integration</artifactId>
-      <version>1.0-SNAPSHOT</version>
+	  <artifactId>seam-guice</artifactId>
+      <version>1.0</version>
       <!--<scope>provided</scope>-->
     </dependency>
     <!-- Seam -->




More information about the jboss-svn-commits mailing list