[jboss-svn-commits] JBL Code SVN: r19909 - in labs/jbosslabs/labs-3.0-build: integration/seam-guice/src/main/java/org/jboss/labs/injection/seam and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu May 8 11:12:56 EDT 2008
Author: wrzep
Date: 2008-05-08 11:12:56 -0400 (Thu, 08 May 2008)
New Revision: 19909
Added:
labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/
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/package-info.java
labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/resources/
labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/resources/seam.properties
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/views/admin/src/main/webapp/WEB-INF/components.xml
Log:
JBLAB-950 guice namespace for the components.xml
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-08 15:11:48 UTC (rev 19908)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/LabsGuiceInterceptor.java 2008-05-08 15:12:56 UTC (rev 19909)
@@ -46,7 +46,7 @@
private static final long serialVersionUID = -6716553117162905303L;
- private static final String DEFAULT_INJECTOR_COMPONENT = "org.jboss.labs.injection.seam.guiceInjector";
+ public static final String DEFAULT_INJECTOR_COMPONENT = "org.jboss.labs.injection.seam.defaultInjector";
private static Injector CACHED_DEFAULT_INJECTOR = null;
Added: 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 (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/DefaultInjector.java 2008-05-08 15:12:56 UTC (rev 19909)
@@ -0,0 +1,167 @@
+/*
+* 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/package-info.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/package-info.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/java/org/jboss/labs/injection/seam/conf/package-info.java 2008-05-08 15:12:56 UTC (rev 19909)
@@ -0,0 +1,6 @@
+ at Namespace(value="http://jboss.org/jbosslabs/seam-guice", prefix = "org.jboss.labs.injection.seam")
+ at AutoCreate
+package org.jboss.labs.injection.seam.conf;
+
+import org.jboss.seam.annotations.Namespace;
+import org.jboss.seam.annotations.AutoCreate;
\ No newline at end of file
Added: labs/jbosslabs/labs-3.0-build/integration/seam-guice/src/main/resources/seam.properties
===================================================================
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-08 15:11:48 UTC (rev 19908)
+++ labs/jbosslabs/labs-3.0-build/views/admin/src/main/webapp/WEB-INF/components.xml 2008-05-08 15:12:56 UTC (rev 19909)
@@ -8,6 +8,7 @@
xmlns:mail="http://jboss.com/products/seam/mail"
xmlns:transaction="http://jboss.com/products/seam/transaction"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:guice="http://jboss.org/jbosslabs/seam-guice"
xsi:schemaLocation=
"http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
@@ -69,5 +70,11 @@
<!--<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>
+ <value>org.jboss.labs.injection.LabsGuiceModule</value>
+ </guice:modules>
+ </guice:default-injector>
</components>
More information about the jboss-svn-commits
mailing list