[jboss-svn-commits] JBL Code SVN: r19672 - in labs/jbosslabs/labs-3.0-build: views/admin/src/main/java/org/jboss/labs/admin and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Apr 21 11:25:49 EDT 2008
Author: wrzep
Date: 2008-04-21 11:25:49 -0400 (Mon, 21 Apr 2008)
New Revision: 19672
Added:
labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/EmptyGuiceModule.java
labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/LabsGuiceInterceptor.java
Modified:
labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/Guice.java
labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/admin/AdminEventsListener.java
labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/admin/action/ShowRequests.java
labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/AdminLabsGuiceModule.java
Log:
JBLAB-928 @Guice - allow guice module selection (global module in components.xml or module class/name specified in the annotation param)
Copied: labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/EmptyGuiceModule.java (from rev 19671, labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/Guice.java)
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/EmptyGuiceModule.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/EmptyGuiceModule.java 2008-04-21 15:25:49 UTC (rev 19672)
@@ -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
Modified: labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/Guice.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/Guice.java 2008-04-21 13:59:07 UTC (rev 19671)
+++ labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/Guice.java 2008-04-21 15:25:49 UTC (rev 19672)
@@ -35,7 +35,9 @@
*/
@Target(TYPE)
@Retention(RUNTIME)
- at Interceptors(LabsSeamInjectionInterceptor.class)
+ at Interceptors(LabsGuiceInterceptor.class)
public @interface Guice
{
+ String value() default "";
+ Class module() default EmptyGuiceModule.class;
}
Copied: labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/LabsGuiceInterceptor.java (from rev 19671, labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/LabsSeamInjectionInterceptor.java)
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/LabsGuiceInterceptor.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/src/main/java/org/jboss/labs/injection/seam/LabsGuiceInterceptor.java 2008-04-21 15:25:49 UTC (rev 19672)
@@ -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.info("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.info("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/src/main/java/org/jboss/labs/admin/AdminEventsListener.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/admin/AdminEventsListener.java 2008-04-21 13:59:07 UTC (rev 19671)
+++ labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/admin/AdminEventsListener.java 2008-04-21 15:25:49 UTC (rev 19672)
@@ -41,7 +41,7 @@
*/
@Name("adminEventsListener")
@Scope(ScopeType.APPLICATION)
- at Startup(depends = "org.jboss.labs.injection.seam.guiceConfiguration")
+ at Startup
@Guice
public class AdminEventsListener implements AdminEvents, Serializable {
Modified: labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/admin/action/ShowRequests.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/admin/action/ShowRequests.java 2008-04-21 13:59:07 UTC (rev 19671)
+++ labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/admin/action/ShowRequests.java 2008-04-21 15:25:49 UTC (rev 19672)
@@ -1,6 +1,7 @@
package org.jboss.labs.admin.action;
import org.jboss.labs.admin.Pages;
+import org.jboss.labs.injection.seam.Guice;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
@@ -10,6 +11,7 @@
* @author Pawel Wrzeszcz (pwrzeszcz [at] jboss . org)
*/
@Name("showRequests")
+ at Guice
public class ShowRequests {
@In private Conversation conversation;
Modified: labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/AdminLabsGuiceModule.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/AdminLabsGuiceModule.java 2008-04-21 13:59:07 UTC (rev 19671)
+++ labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/AdminLabsGuiceModule.java 2008-04-21 15:25:49 UTC (rev 19672)
@@ -1,6 +1,38 @@
+/*
+* 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.labs.injection.LabsGuiceModule;
+import com.google.inject.Binder;
+/**
+ * @author Pawel Wrzeszcz (pwrzeszcz [at] jboss . org)
+ **/
+
public class AdminLabsGuiceModule extends LabsGuiceModule {
+
+ public void configure(Binder binder) {
+ super.configure(binder);
+ }
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list