[seam-commits] Seam SVN: r12441 - in modules/faces/trunk/impl: src/main/java/org/jboss/seam/faces/cdi and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Tue Apr 13 02:30:20 EDT 2010
Author: nickarls
Date: 2010-04-13 02:30:19 -0400 (Tue, 13 Apr 2010)
New Revision: 12441
Added:
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerProvider.java
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/JndiBeanManagerProvider.java
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/ServletContextBeanManagerProvider.java
Modified:
modules/faces/trunk/impl/pom.xml
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java
modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml
Log:
BeanManager providers for lookup, start with ServletContext attribute, fallback to JNDI
Modified: modules/faces/trunk/impl/pom.xml
===================================================================
--- modules/faces/trunk/impl/pom.xml 2010-04-13 06:23:47 UTC (rev 12440)
+++ modules/faces/trunk/impl/pom.xml 2010-04-13 06:30:19 UTC (rev 12441)
@@ -33,6 +33,13 @@
<dependencies>
<dependency>
+ <!-- Required until the Servlet 3.0 API can be resolved in Central -->
+ <groupId>org.glassfish</groupId>
+ <artifactId>javax.servlet</artifactId>
+ <version>3.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<artifactId>seam-faces-api</artifactId>
<groupId>org.jboss.seam.faces</groupId>
<version>${project.version}</version>
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java 2010-04-13 06:23:47 UTC (rev 12440)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java 2010-04-13 06:30:19 UTC (rev 12441)
@@ -26,27 +26,25 @@
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
/**
+ * Super-class for listeners that need a reference to the BeanManager
*
* @author Nicklas Karlsson
- *
*/
public class BeanManagerAware
{
@Inject
BeanManager beanManager;
- // FIXME: hack to work around invalid binding in JBoss AS 6 M2
- private static final List<String> beanManagerLocations;
+ private static final List<BeanManagerProvider> beanManagerProviders;
static
{
- beanManagerLocations = new ArrayList<String>();
- beanManagerLocations.add("java:comp/BeanManager");
- beanManagerLocations.add("java:app/BeanManager");
+ beanManagerProviders = new ArrayList<BeanManagerProvider>();
+ beanManagerProviders.add(ServletContextBeanManagerProvider.DEFAULT);
+ beanManagerProviders.add(JndiBeanManagerProvider.DEFAULT);
+ beanManagerProviders.add(JndiBeanManagerProvider.JBOSS_HACK);
}
protected BeanManager getBeanManager()
@@ -60,17 +58,17 @@
private BeanManager lookupBeanManager()
{
- for (String location : beanManagerLocations)
+ BeanManager result = null;
+
+ for (BeanManagerProvider provider : beanManagerProviders)
{
- try
+ result = provider.getBeanManager();
+ if (result != null)
{
- return (BeanManager) new InitialContext().lookup(location);
+ break;
}
- catch (NamingException e)
- {
- // No panic, keep trying
- }
}
- throw new IllegalArgumentException("Could not find BeanManager in " + beanManagerLocations);
+ return result;
}
+
}
Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerProvider.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerProvider.java (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerProvider.java 2010-04-13 06:30:19 UTC (rev 12441)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * 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.seam.faces.cdi;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ * Provider for obtaining a BeanManager
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public interface BeanManagerProvider
+{
+ /**
+ * Try to obtain a BeanManager
+ *
+ * @return The BeanManager (or null if non found at this location)
+ */
+ public abstract BeanManager getBeanManager();
+}
Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/JndiBeanManagerProvider.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/JndiBeanManagerProvider.java (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/JndiBeanManagerProvider.java 2010-04-13 06:30:19 UTC (rev 12441)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * 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.seam.faces.cdi;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * A BeanManager provider for JNDI contexts
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class JndiBeanManagerProvider implements BeanManagerProvider
+{
+ private String location;
+
+ public static final JndiBeanManagerProvider DEFAULT = new JndiBeanManagerProvider("java:comp/BeanManager");
+ public static final JndiBeanManagerProvider JBOSS_HACK = new JndiBeanManagerProvider("java:app/BeanManager");
+
+ protected JndiBeanManagerProvider(String location)
+ {
+ this.location = location;
+ }
+
+ @Override
+ public BeanManager getBeanManager()
+ {
+ try
+ {
+ return (BeanManager) new InitialContext().lookup(location);
+ }
+ catch (NamingException e)
+ {
+ // No panic, it's just not there
+ }
+ return null;
+ }
+
+}
Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/ServletContextBeanManagerProvider.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/ServletContextBeanManagerProvider.java (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/ServletContextBeanManagerProvider.java 2010-04-13 06:30:19 UTC (rev 12441)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * 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.seam.faces.cdi;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletContext;
+
+/**
+ * A BeanManager provider for the Servlet Context attribute "javax.enterprise.inject.spi.BeanManager"
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class ServletContextBeanManagerProvider implements BeanManagerProvider
+{
+ public static final ServletContextBeanManagerProvider DEFAULT = new ServletContextBeanManagerProvider();
+
+ @Override
+ public BeanManager getBeanManager()
+ {
+ ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext();
+ return (BeanManager) servletContext.getAttribute(BeanManager.class.getName());
+ }
+
+}
Modified: modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml
===================================================================
--- modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml 2010-04-13 06:23:47 UTC (rev 12440)
+++ modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml 2010-04-13 06:30:19 UTC (rev 12441)
@@ -1,30 +1,8 @@
-<!--
-JBoss, Home of Professional Open Source
-Copyright 2010, Red Hat, Inc., and individual contributors
-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.
--->
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
- version="2.0"
- id="seam3">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+ version="2.0" id="seam3">
<name>seam3</name>
@@ -36,8 +14,8 @@
<lifecycle>
<phase-listener>org.jboss.seam.faces.context.FlashScopedContext</phase-listener>
- <phase-listener>org.jboss.seam.faces.event.DelegatingPhaseListener</phase-listener>
- </lifecycle>
+ <phase-listener>org.jboss.seam.faces.event.DelegatingPhaseListener</phase-listener>
+ </lifecycle>
<application>
<system-event-listener>
@@ -64,7 +42,7 @@
<system-event-listener-class>org.jboss.seam.faces.event.DelegatingSystemEventListener</system-event-listener-class>
<system-event-class>javax.faces.event.PreDestroyCustomScopeEvent</system-event-class>
</system-event-listener>
- </application>
+ </application>
<component>
<component-type>org.jboss.seam.faces.ViewAction</component-type>
More information about the seam-commits
mailing list