[jboss-svn-commits] JBL Code SVN: r19936 - in labs/jbosslabs/labs-3.0-build: integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon May 12 12:46:05 EDT 2008
Author: wrzep
Date: 2008-05-12 12:46:05 -0400 (Mon, 12 May 2008)
New Revision: 19936
Added:
labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/GuiceInit.java
labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/Injector.java
Removed:
labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/DefaultInjector.java
Modified:
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
labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/AdminLabsGuiceInjector.java
labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/YetAnotherLabsGuiceInjector.java
labs/jbosslabs/labs-3.0-build/views/admin/src/main/webapp/WEB-INF/components.xml
Log:
JBLAB-950
Modified: 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 2008-05-12 15:53:57 UTC (rev 19935)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/Guice.java 2008-05-12 16:46:05 UTC (rev 19936)
@@ -42,8 +42,6 @@
{
/**
* Name of the Guice injector component.
- * If not specified, the component named "org.jboss.labs.injection.seam.guiceInjector"
- * will be used (You have to provide it).
*/
String value() default "";
}
Modified: 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 2008-05-12 15:53:57 UTC (rev 19935)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/LabsGuiceInterceptor.java 2008-05-12 16:46:05 UTC (rev 19936)
@@ -24,10 +24,11 @@
package org.jboss.labs.injection.seam;
import com.google.inject.Injector;
+import org.jboss.labs.injection.seam.conf.GuiceInit;
import org.jboss.seam.Component;
+import org.jboss.seam.core.Expressions;
import org.jboss.seam.annotations.intercept.AroundInvoke;
import org.jboss.seam.annotations.intercept.Interceptor;
-import org.jboss.seam.core.Expressions;
import org.jboss.seam.intercept.AbstractInterceptor;
import org.jboss.seam.intercept.InvocationContext;
import org.jboss.seam.log.Log;
@@ -46,8 +47,6 @@
private static final long serialVersionUID = -6716553117162905303L;
- public static final String DEFAULT_INJECTOR_COMPONENT = "org.jboss.labs.injection.seam.defaultInjector";
-
private static Injector CACHED_DEFAULT_INJECTOR = null;
@AroundInvoke
@@ -55,14 +54,8 @@
{
final Injector injector = getInjectorForClass(invocationContext.getMethod().getDeclaringClass());
- if (injector == null)
- {
- throw new IllegalStateException("Guice injector not specified.");
- }
-
log.debug("Injecting members for: "
- + invocationContext.getTarget().getClass().getName()
- + " using injector " + injector);
+ + invocationContext.getTarget().getClass().getName());
injector.injectMembers(invocationContext.getTarget());
@@ -83,27 +76,20 @@
{
if (CACHED_DEFAULT_INJECTOR == null)
{
- Object result = Component.getInstance(DEFAULT_INJECTOR_COMPONENT);
+ log.trace("Get default injector.");
- if (result == null)
- {
- throw new IllegalArgumentException("Default Guice injector is not specified.");
- }
+ GuiceInit init = (GuiceInit) Component.getInstance("org.jboss.labs.injection.seam.init");
- if (!(result instanceof Injector))
- {
- throw new IllegalArgumentException("Expression '" + DEFAULT_INJECTOR_COMPONENT +
- "' does not evaluate to a Guice injector.");
- }
-
- CACHED_DEFAULT_INJECTOR = (Injector) result;
+ CACHED_DEFAULT_INJECTOR = init.getInjector();
}
return CACHED_DEFAULT_INJECTOR;
}
- private static Injector getInjectorByName(final String expr)
+ public static Injector getInjectorByName(final String expr)
{
+ log.trace("Get injector by name: " + expr);
+
Object result;
if (expr.startsWith("#"))
@@ -121,7 +107,6 @@
"' does not evaluate to a Guice injector.");
}
-
return (Injector) result;
- }
+ }
}
Deleted: labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/DefaultInjector.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/DefaultInjector.java 2008-05-12 15:53:57 UTC (rev 19935)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/DefaultInjector.java 2008-05-12 16:46:05 UTC (rev 19936)
@@ -1,167 +0,0 @@
-/*
-* 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.conf;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
-import org.jboss.seam.core.Expressions;
-import org.jboss.seam.core.Expressions.ValueExpression;
-import org.jboss.seam.annotations.*;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import static org.jboss.seam.annotations.Install.FRAMEWORK;
-import org.jboss.labs.injection.seam.LabsGuiceInterceptor;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.List;
-import java.util.ArrayList;
-
-import com.google.inject.Injector;
-import com.google.inject.Guice;
-import com.google.inject.Module;
-
-/**
- * @author Pawel Wrzeszcz (pwrzeszcz [at] jboss . org)
- */
- at Name("org.jboss.labs.injection.seam.injector")
- at Scope(ScopeType.APPLICATION)
- at Startup
- at Install(value=false, precedence = FRAMEWORK)
- at BypassInterceptors
-public class DefaultInjector implements Serializable
-{
- private static final long serialVersionUID = 8935525407647910950L;
-
- private static final LogProvider log = Logging.getLogProvider(DefaultInjector.class);
-
- private ValueExpression<Injector> value;
-
- private String[] modules;
-
- @Factory(value = LabsGuiceInterceptor.DEFAULT_INJECTOR_COMPONENT, autoCreate = true)
- public Injector getInjector() throws IllegalAccessException, InstantiationException, ClassNotFoundException
- {
-
- log.info("S T A R T U P");
-
- return (value != null)
- ? value.getValue()
- : createInjector(modules);
- }
-
-
- private static Injector createInjector(String[] modules) throws IllegalAccessException, ClassNotFoundException, InstantiationException
- {
- if ((modules == null) || (modules.length == 0))
- {
- log.error("No Guice module specified. Using empty injector.");
-
- return Guice.createInjector();
- }
-
- List<Module> moduleList = getModuleList(modules);
-
- return Guice.createInjector(moduleList);
- }
-
- private static List<Module> getModuleList(String[] modules) throws IllegalAccessException, InstantiationException, ClassNotFoundException
- {
- List<Module> moduleList = new ArrayList<Module>();
-
- for (String m : modules)
- {
- Module module = getModule(m);
- moduleList.add(module);
- }
-
- return moduleList;
- }
-
- private static Module getModule(String moduleString)
- {
- Object module;
-
- if (moduleString.startsWith("#"))
- {
- module = Expressions.instance().createValueExpression(moduleString).getValue();
- }
- else
- {
- module = getModuleForClass(moduleString);
- }
-
- if (!(module instanceof Module))
- {
- throw new IllegalArgumentException("Not a Guice module: " + moduleString);
- }
-
- return (Module) module;
- }
-
- private static Object getModuleForClass(String className)
- {
- try
- {
- Class<?> clazz = Class.forName(className, true, Thread.currentThread().getContextClassLoader());
- return clazz.newInstance();
- }
- catch (ClassNotFoundException e)
- {
- throw new IllegalArgumentException("Unable to create guice module: " + className, e);
- }
- catch (IllegalAccessException e)
- {
- throw new IllegalArgumentException("Unable to create guice module: " + className, e);
- }
- catch (InstantiationException e)
- {
- throw new IllegalArgumentException("Unable to create guice module: " + className, e);
- }
- }
-
- public ValueExpression<Injector> getValue() {
- return value;
- }
-
- public void setValue(ValueExpression<Injector> value) {
- this.value = value;
- }
-
- public String[] getModules()
- {
- return modules;
- }
-
- public void setModules(String[] modules)
- {
- this.modules = modules;
- }
-
- @Override
- public String toString()
- {
- return "org.jboss.labs.injection.seam.injector(" + value + "; " + Arrays.toString(modules) + ")";
- }
-}
\ No newline at end of file
Added: labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/GuiceInit.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/GuiceInit.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/GuiceInit.java 2008-05-12 16:46:05 UTC (rev 19936)
@@ -0,0 +1,77 @@
+/*
+* 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.conf;
+
+import com.google.inject.Injector;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.*;
+import static org.jboss.seam.annotations.Install.FRAMEWORK;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+
+import java.io.Serializable;
+
+/**
+ * @author Pawel Wrzeszcz (pwrzeszcz [at] jboss . org)
+ */
+ at Name("org.jboss.labs.injection.seam.init")
+ at Scope(ScopeType.APPLICATION)
+ at Startup
+ at Install(precedence = FRAMEWORK)
+ at BypassInterceptors
+public class GuiceInit implements Serializable
+{
+ private static final long serialVersionUID = -1517814449129434488L;
+ private static final LogProvider log = Logging.getLogProvider(GuiceInit.class);
+
+ private Injector injector;
+
+ @Create
+ public void create()
+ {
+ if (injector == null) // Perform check at deploy time
+ {
+ throw new IllegalStateException("Guice injector not specified.");
+ }
+
+ log.info("Guice support initialized.");
+ }
+
+ public Injector getInjector()
+ {
+ return injector;
+ }
+
+ public void setInjector(Injector injector)
+ {
+ this.injector = injector;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "org.jboss.labs.injection.seam.init(" + injector + ")";
+ }
+}
\ No newline at end of file
Copied: labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/Injector.java (from rev 19909, labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/DefaultInjector.java)
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/Injector.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/Injector.java 2008-05-12 16:46:05 UTC (rev 19936)
@@ -0,0 +1,110 @@
+/*
+* 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.conf;
+
+import com.google.inject.Guice;
+import com.google.inject.Module;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Install;
+import static org.jboss.seam.annotations.Install.FRAMEWORK;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Startup;
+import org.jboss.seam.annotations.Unwrap;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author Pawel Wrzeszcz (pwrzeszcz [at] jboss . org)
+ */
+ at Scope(ScopeType.APPLICATION)
+ at Startup
+ at Install(value=false, precedence = FRAMEWORK)
+ at BypassInterceptors
+public class Injector implements Serializable
+{
+ private static final long serialVersionUID = 8935525407647910950L;
+
+ private static final LogProvider log = Logging.getLogProvider(Injector.class);
+
+ private String[] modules;
+
+ @Unwrap
+ public com.google.inject.Injector getInjector() throws IllegalAccessException, InstantiationException, ClassNotFoundException
+ {
+ if ((modules == null) || (modules.length == 0))
+ {
+ throw new IllegalArgumentException("No Guice module specified.");
+ }
+
+ log.info("Creating injector from modules: " + Arrays.toString(modules));
+
+ final List<Module> moduleList = getModuleList(modules);
+
+ return Guice.createInjector(moduleList);
+ }
+
+ private static List<Module> getModuleList(String[] modules) throws IllegalAccessException, InstantiationException, ClassNotFoundException
+ {
+ List<Module> moduleList = new ArrayList<Module>();
+
+ for (String m : modules)
+ {
+ Module module = getModule(m);
+ moduleList.add(module);
+ }
+
+ return moduleList;
+ }
+
+ private static Module getModule(String className)
+ {
+ try
+ {
+ final Class<?> clazz = Class.forName(className, true, Thread.currentThread().getContextClassLoader());
+
+ return (Module) clazz.newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Unable to create guice module: " + className, e);
+ }
+ }
+
+
+ public String[] getModules()
+ {
+ return modules;
+ }
+
+ public void setModules(String[] modules)
+ {
+ this.modules = modules;
+ }
+}
\ No newline at end of file
Modified: labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/AdminLabsGuiceInjector.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/AdminLabsGuiceInjector.java 2008-05-12 15:53:57 UTC (rev 19935)
+++ labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/AdminLabsGuiceInjector.java 2008-05-12 16:46:05 UTC (rev 19936)
@@ -36,9 +36,8 @@
@Name("adminLabsGuiceInjectorFactory")
public class AdminLabsGuiceInjector {
- @Factory(value = "org.jboss.labs.injection.seam.guiceInjector", scope = ScopeType.APPLICATION, autoCreate = true)
+ @Factory(value = "labsInjector", scope = ScopeType.APPLICATION, autoCreate = true)
public Injector getInjector() {
- System.out.println("AdminLabsGuiceInjector.getInjector");
return LabsInjection.getInjector();
}
}
\ No newline at end of file
Modified: labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/YetAnotherLabsGuiceInjector.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/YetAnotherLabsGuiceInjector.java 2008-05-12 15:53:57 UTC (rev 19935)
+++ labs/jbosslabs/labs-3.0-build/views/admin/src/main/java/org/jboss/labs/injection/seam/YetAnotherLabsGuiceInjector.java 2008-05-12 16:46:05 UTC (rev 19936)
@@ -23,13 +23,11 @@
package org.jboss.labs.injection.seam;
-import org.jboss.labs.injection.LabsGuiceModule;
+import com.google.inject.Injector;
import org.jboss.labs.injection.LabsInjection;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Factory;
import org.jboss.seam.ScopeType;
-import com.google.inject.Binder;
-import com.google.inject.Injector;
+import org.jboss.seam.annotations.Factory;
+import org.jboss.seam.annotations.Name;
/**
* @author Pawel Wrzeszcz (pwrzeszcz [at] jboss . org)
@@ -40,7 +38,6 @@
@Factory(value = "myInjector", scope = ScopeType.APPLICATION, autoCreate = true)
public Injector getInjector() {
- System.out.println("YetAnotherLabsGuiceInjector.getInjector");
return LabsInjection.getInjector();
}
}
\ No newline at end of file
Modified: labs/jbosslabs/labs-3.0-build/views/admin/src/main/webapp/WEB-INF/components.xml
===================================================================
--- labs/jbosslabs/labs-3.0-build/views/admin/src/main/webapp/WEB-INF/components.xml 2008-05-12 15:53:57 UTC (rev 19935)
+++ labs/jbosslabs/labs-3.0-build/views/admin/src/main/webapp/WEB-INF/components.xml 2008-05-12 16:46:05 UTC (rev 19936)
@@ -35,7 +35,7 @@
<persistence:entity-manager-factory name="admin"/>
- <persistence:managed-persistence-context name="entityManager"
+ <persistence:managed-persistence-context name="entityManager"
auto-create="true" entity-manager-factory="#{admin}"/>
<!--<persistence:entity-manager-factory persistence-unit-name="admin" name="entityManagerFactory"/>
@@ -50,7 +50,7 @@
<action execute="#{redirect.returnToCapturedView}"/>
</event>
- <mail:mail-session host="poczta.o2.pl" port="25" username="jboss" password="jboss" />
+ <mail:mail-session host="poczta.o2.pl" port="25" username="jboss" password="jboss"/>
<bpm:jbpm>
<bpm:process-definitions>
@@ -66,15 +66,17 @@
<factory name="emailIT" value="jboss at o2.pl" scope="APPLICATION"/>
<factory name="emailReplyTo" value="jboss at o2.pl" scope="APPLICATION"/>
- <!-- Guice integration -->
- <!--<component name="org.jboss.labs.injection.seam.guiceModule"-->
- <!--class="org.jboss.labs.injection.seam.AdminLabsGuiceInjector"-->
- <!--auto-create="true" scope="APPLICATION" startup="true"/>-->
-
- <guice:default-injector>
- <guice:modules>
+ <!--Guice integration -->
+ <guice:injector name="myFantasticInjector">
+ <guice:modules>
<value>org.jboss.labs.injection.LabsGuiceModule</value>
- </guice:modules>
- </guice:default-injector>
+ </guice:modules>
+ </guice:injector>
+ <!-- This causes NoClassDefFoundError: Proxy
+ <component name="labsInjectorFactory" class="org.jboss.labs.injection.LabsInjection"/>
+ -->
+
+ <guice:init injector="#{labsInjector}"/>
+
</components>
More information about the jboss-svn-commits
mailing list