[seam-commits] Seam SVN: r10852 - in modules/trunk: bridge-api and 34 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon May 11 16:05:51 EDT 2009


Author: dan.j.allen
Date: 2009-05-11 16:05:51 -0400 (Mon, 11 May 2009)
New Revision: 10852

Added:
   modules/trunk/bridge-api/
   modules/trunk/bridge-api/pom.xml
   modules/trunk/bridge-api/src/
   modules/trunk/bridge-api/src/main/
   modules/trunk/bridge-api/src/main/java/
   modules/trunk/bridge-api/src/main/java/org/
   modules/trunk/bridge-api/src/main/java/org/jboss/
   modules/trunk/bridge-api/src/main/java/org/jboss/seam/
   modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/
   modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ManagerBridge.java
   modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ManagerProviderResolver.java
   modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ServiceLoaderManagerProviderResolver.java
   modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/spi/
   modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/spi/ManagerProvider.java
   modules/trunk/bridge-api/src/main/resources/
   modules/trunk/bridge-api/src/main/resources/META-INF/
   modules/trunk/bridge-api/src/main/resources/META-INF/beans.xml
   modules/trunk/openwebbeans-bridge/
   modules/trunk/openwebbeans-bridge/pom.xml
   modules/trunk/openwebbeans-bridge/src/
   modules/trunk/openwebbeans-bridge/src/main/
   modules/trunk/openwebbeans-bridge/src/main/java/
   modules/trunk/openwebbeans-bridge/src/main/java/org/
   modules/trunk/openwebbeans-bridge/src/main/java/org/jboss/
   modules/trunk/openwebbeans-bridge/src/main/java/org/jboss/seam/
   modules/trunk/openwebbeans-bridge/src/main/java/org/jboss/seam/bridge/
   modules/trunk/openwebbeans-bridge/src/main/java/org/jboss/seam/bridge/openwebbeans/
   modules/trunk/openwebbeans-bridge/src/main/java/org/jboss/seam/bridge/openwebbeans/OpenWebBeansManagerProvider.java
   modules/trunk/openwebbeans-bridge/src/main/resources/
   modules/trunk/openwebbeans-bridge/src/main/resources/META-INF/
   modules/trunk/openwebbeans-bridge/src/main/resources/META-INF/services/
   modules/trunk/openwebbeans-bridge/src/main/resources/META-INF/services/org.jboss.seam.bridge.spi.ManagerProvider
   modules/trunk/webbeans-bridge/
   modules/trunk/webbeans-bridge/pom.xml
   modules/trunk/webbeans-bridge/src/
   modules/trunk/webbeans-bridge/src/main/
   modules/trunk/webbeans-bridge/src/main/java/
   modules/trunk/webbeans-bridge/src/main/java/org/
   modules/trunk/webbeans-bridge/src/main/java/org/jboss/
   modules/trunk/webbeans-bridge/src/main/java/org/jboss/seam/
   modules/trunk/webbeans-bridge/src/main/java/org/jboss/seam/bridge/
   modules/trunk/webbeans-bridge/src/main/java/org/jboss/seam/bridge/webbeans/
   modules/trunk/webbeans-bridge/src/main/java/org/jboss/seam/bridge/webbeans/WebBeansManagerProvider.java
   modules/trunk/webbeans-bridge/src/main/resources/
   modules/trunk/webbeans-bridge/src/main/resources/META-INF/
   modules/trunk/webbeans-bridge/src/main/resources/META-INF/services/
   modules/trunk/webbeans-bridge/src/main/resources/META-INF/services/org.jboss.seam.bridge.spi.ManagerProvider
Log:
introduce a bridge API to lookup the JCDI Manager



Property changes on: modules/trunk/bridge-api
___________________________________________________________________
Name: svn:ignore
   + target


Added: modules/trunk/bridge-api/pom.xml
===================================================================
--- modules/trunk/bridge-api/pom.xml	                        (rev 0)
+++ modules/trunk/bridge-api/pom.xml	2009-05-11 20:05:51 UTC (rev 10852)
@@ -0,0 +1,53 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+   <modelVersion>4.0.0</modelVersion>
+
+   <parent>
+      <artifactId>seam-parent</artifactId>
+      <groupId>org.jboss.seam</groupId>
+      <version>3.0.0-SNAPSHOT</version>
+   </parent>
+
+   <!-- TODO might want to name this seam-jcdi-bridge-api -->
+   <artifactId>seam-bridge-api</artifactId>
+   <packaging>jar</packaging>
+   <version>3.0.0-SNAPSHOT</version>
+   <name>Seam Bridge API</name>
+   <description>An API wrapper around an SPI which Seam uses to lookup providers, such as the JCDI Manager.</description>
+
+   <build>
+      <plugins>
+
+         <!--
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+               <suiteXmlFiles>
+                  <suiteXmlFile>src/test/resources/test-suite.xml</suiteXmlFile>
+               </suiteXmlFiles>
+            </configuration>
+         </plugin>
+         -->
+
+      </plugins>
+   </build>
+
+   <dependencies>
+
+      <dependency>
+         <groupId>javax.el</groupId>
+         <artifactId>el-api</artifactId>
+         <scope>provided</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>${webbeans.groupId}</groupId>
+         <artifactId>jsr299-api</artifactId>
+         <scope>provided</scope>
+      </dependency>
+
+   </dependencies>
+
+</project>

Added: modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ManagerBridge.java
===================================================================
--- modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ManagerBridge.java	                        (rev 0)
+++ modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ManagerBridge.java	2009-05-11 20:05:51 UTC (rev 10852)
@@ -0,0 +1,95 @@
+package org.jboss.seam.bridge;
+
+import javax.event.Observes;
+import javax.inject.manager.Deployed;
+import javax.inject.manager.Manager;
+
+import org.jboss.seam.bridge.spi.ManagerProvider;
+
+/**
+ * A bridge to the JCDI Manager implementation. This bean observers the event
+ * that is fired when the Manager is deployed and attempts to match a provider
+ * that produces that same Manager. That provider is then used to access the
+ * deployed Manager by a non-managed resource (such as a JSF phase listener)
+ * 
+ * @author Dan Allen
+ */
+public class ManagerBridge
+{
+   private static ManagerProvider provider;
+   
+   private static boolean discover = true;
+   
+   // QUESTION: should this be a String, Class, or instance?
+   private Class<? extends ManagerProviderResolver> resolverClass = ServiceLoaderManagerProviderResolver.class;
+   
+   public Class<? extends ManagerProviderResolver> getResolverClass()
+   {
+      return resolverClass;
+   }
+
+   public void setResolverClass(Class<? extends ManagerProviderResolver> resolverClass)
+   {
+      this.resolverClass = resolverClass;
+   }
+
+   public static ManagerProvider getProvider()
+   {
+      return provider;
+   }
+   
+   public static void setProvider(ManagerProvider override)
+   {
+      provider = override;
+   }
+   
+   /**
+    * Configure whether discovery of the provider when the manager
+    * is deployed. The default is to use discovery. This can
+    * be disabled in a mock environment.
+    */
+   public static void setDiscover(boolean flag)
+   {
+      discover = flag;
+   }
+   
+   /**
+    * Observes the event fired when the manager is deployed and resolves a provider
+    * that can produce this same Manager instance.
+    * 
+    * @param manager The deployed Manager instance
+    */
+   public void onManagerDeployed(@Observes @Deployed Manager manager)
+   {
+      // intended for a mock environment, skip discovery
+      if (!discover)
+      {
+         return;
+      }
+      
+      ManagerProviderResolver resolver;
+      try
+      {
+         resolver = resolverClass.newInstance();
+      }
+      catch (InstantiationException e)
+      {
+         throw new IllegalStateException("Could not instantiate ManagerProviderResolver class " + resolverClass, e);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new IllegalStateException("Access was denied while attempting to instantiate ManagerProviderResolver class " + resolverClass, e);
+      }
+      
+      for (ManagerProvider candidate : resolver.getManagerProviders())
+      {
+         if (manager.equals(candidate.getRootManager()))
+         {
+            provider = candidate;
+            return;
+         }
+      }
+
+      throw new IllegalStateException("Cannot resolve a ManagerProvider corresponding to the deployed Manager implementation " + manager.getClass());
+   }
+}

Added: modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ManagerProviderResolver.java
===================================================================
--- modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ManagerProviderResolver.java	                        (rev 0)
+++ modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ManagerProviderResolver.java	2009-05-11 20:05:51 UTC (rev 10852)
@@ -0,0 +1,10 @@
+package org.jboss.seam.bridge;
+
+import java.util.List;
+
+import org.jboss.seam.bridge.spi.ManagerProvider;
+
+public interface ManagerProviderResolver
+{
+   List<ManagerProvider> getManagerProviders();
+}

Added: modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ServiceLoaderManagerProviderResolver.java
===================================================================
--- modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ServiceLoaderManagerProviderResolver.java	                        (rev 0)
+++ modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/ServiceLoaderManagerProviderResolver.java	2009-05-11 20:05:51 UTC (rev 10852)
@@ -0,0 +1,30 @@
+package org.jboss.seam.bridge;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ServiceLoader;
+
+import org.jboss.seam.bridge.spi.ManagerProvider;
+
+/**
+ * An implementation of the ManagerProviderResolver interface that utilizes the
+ * Java SE 6 ServiceLoader interface to locate declared providers on the classpath.
+ * 
+ * @author Dan Allen
+ */
+public class ServiceLoaderManagerProviderResolver implements ManagerProviderResolver
+{
+   public List<ManagerProvider> getManagerProviders()
+   {
+      List<ManagerProvider> providers = new ArrayList<ManagerProvider>();
+      ServiceLoader<ManagerProvider> managerProvidersLoader = ServiceLoader.load(ManagerProvider.class);
+      Iterator<ManagerProvider> iterator = managerProvidersLoader.iterator();
+      while (iterator.hasNext())
+      {
+         providers.add(iterator.next());
+      }
+      
+      return providers;
+   }
+}

Added: modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/spi/ManagerProvider.java
===================================================================
--- modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/spi/ManagerProvider.java	                        (rev 0)
+++ modules/trunk/bridge-api/src/main/java/org/jboss/seam/bridge/spi/ManagerProvider.java	2009-05-11 20:05:51 UTC (rev 10852)
@@ -0,0 +1,19 @@
+package org.jboss.seam.bridge.spi;
+
+import javax.el.ELResolver;
+import javax.inject.manager.Manager;
+
+/**
+ * A contract between the provider engine and the JCDI bootstrap
+ * mechanism to return the current (root) Manager instance.
+ * 
+ * @author Dan Allen
+ */
+public interface ManagerProvider
+{
+   Manager getRootManager();
+   
+   Manager getCurrentManager();
+   
+   ELResolver getELResolver();
+}

Added: modules/trunk/bridge-api/src/main/resources/META-INF/beans.xml
===================================================================


Property changes on: modules/trunk/openwebbeans-bridge
___________________________________________________________________
Name: svn:ignore
   + target


Added: modules/trunk/openwebbeans-bridge/pom.xml
===================================================================
--- modules/trunk/openwebbeans-bridge/pom.xml	                        (rev 0)
+++ modules/trunk/openwebbeans-bridge/pom.xml	2009-05-11 20:05:51 UTC (rev 10852)
@@ -0,0 +1,58 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+   <modelVersion>4.0.0</modelVersion>
+
+   <parent>
+      <artifactId>seam-parent</artifactId>
+      <groupId>org.jboss.seam</groupId>
+      <version>3.0.0-SNAPSHOT</version>
+   </parent>
+
+   <artifactId>seam-openwebbeans-bridge</artifactId>
+   <packaging>jar</packaging>
+   <version>3.0.0-SNAPSHOT</version>
+   <name>Seam OpenWebBeans Bridge</name>
+   <description>An implementation of the Seam Bridge SPI to obtain an OpenWebBeans Manager.</description>
+
+   <build>
+      <plugins>
+
+         <!--
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+               <suiteXmlFiles>
+                  <suiteXmlFile>src/test/resources/test-suite.xml</suiteXmlFile>
+               </suiteXmlFiles>
+            </configuration>
+         </plugin>
+         -->
+
+      </plugins>
+   </build>
+
+   <dependencies>
+
+      <dependency>
+         <groupId>${seam.groupId}</groupId>
+         <artifactId>seam-bridge-api</artifactId>
+      </dependency>
+
+      <dependency>
+         <groupId>${webbeans.groupId}</groupId>
+         <artifactId>jsr299-api</artifactId>
+         <scope>provided</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>org.apache.openwebbeans</groupId>
+         <artifactId>openwebbeans-impl</artifactId>
+         <version>1.0.0-incubating-SNAPSHOT</version>
+         <scope>provided</scope>
+      </dependency>
+
+   </dependencies>
+
+</project>

Added: modules/trunk/openwebbeans-bridge/src/main/java/org/jboss/seam/bridge/openwebbeans/OpenWebBeansManagerProvider.java
===================================================================
--- modules/trunk/openwebbeans-bridge/src/main/java/org/jboss/seam/bridge/openwebbeans/OpenWebBeansManagerProvider.java	                        (rev 0)
+++ modules/trunk/openwebbeans-bridge/src/main/java/org/jboss/seam/bridge/openwebbeans/OpenWebBeansManagerProvider.java	2009-05-11 20:05:51 UTC (rev 10852)
@@ -0,0 +1,33 @@
+package org.jboss.seam.bridge.openwebbeans;
+
+import javax.el.ELResolver;
+import javax.inject.manager.Manager;
+
+import org.apache.webbeans.container.activity.ActivityManager;
+import org.jboss.seam.bridge.spi.ManagerProvider;
+import org.jboss.webbeans.el.WebBeansELResolver;
+
+/**
+ * An implementation of Seam's Manager SPI interface for integrating Seam with
+ * the OpenWebBeans Manager.
+ * 
+ * @author Dan Allen
+ */
+public class OpenWebBeansManagerProvider implements ManagerProvider
+{
+   public Manager getCurrentManager()
+   {
+      return ActivityManager.getInstance().getCurrentActivity();
+   }
+
+   public Manager getRootManager()
+   {
+      return ActivityManager.getInstance().getRootActivity();
+   }
+
+   public ELResolver getELResolver()
+   {
+      return new WebBeansELResolver();
+   }
+
+}

Added: modules/trunk/openwebbeans-bridge/src/main/resources/META-INF/services/org.jboss.seam.bridge.spi.ManagerProvider
===================================================================
--- modules/trunk/openwebbeans-bridge/src/main/resources/META-INF/services/org.jboss.seam.bridge.spi.ManagerProvider	                        (rev 0)
+++ modules/trunk/openwebbeans-bridge/src/main/resources/META-INF/services/org.jboss.seam.bridge.spi.ManagerProvider	2009-05-11 20:05:51 UTC (rev 10852)
@@ -0,0 +1 @@
+org.jboss.seam.bridge.openwebbeans.OpenWebBeansManagerProvider


Property changes on: modules/trunk/webbeans-bridge
___________________________________________________________________
Name: svn:ignore
   + target


Added: modules/trunk/webbeans-bridge/pom.xml
===================================================================
--- modules/trunk/webbeans-bridge/pom.xml	                        (rev 0)
+++ modules/trunk/webbeans-bridge/pom.xml	2009-05-11 20:05:51 UTC (rev 10852)
@@ -0,0 +1,57 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+   <modelVersion>4.0.0</modelVersion>
+
+   <parent>
+      <artifactId>seam-parent</artifactId>
+      <groupId>org.jboss.seam</groupId>
+      <version>3.0.0-SNAPSHOT</version>
+   </parent>
+
+   <artifactId>seam-webbeans-bridge</artifactId>
+   <packaging>jar</packaging>
+   <version>3.0.0-SNAPSHOT</version>
+   <name>Seam Web Beans Bridge</name>
+   <description>An implementation of the Seam Bridge SPI to obtain a Web Beans Manager.</description>
+
+   <build>
+      <plugins>
+
+         <!--
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+               <suiteXmlFiles>
+                  <suiteXmlFile>src/test/resources/test-suite.xml</suiteXmlFile>
+               </suiteXmlFiles>
+            </configuration>
+         </plugin>
+         -->
+
+      </plugins>
+   </build>
+
+   <dependencies>
+
+      <dependency>
+         <groupId>${seam.groupId}</groupId>
+         <artifactId>seam-bridge-api</artifactId>
+      </dependency>
+
+      <dependency>
+         <groupId>${webbeans.groupId}</groupId>
+         <artifactId>jsr299-api</artifactId>
+         <scope>provided</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>${webbeans.groupId}</groupId>
+         <artifactId>webbeans-core</artifactId>
+         <scope>provided</scope>
+      </dependency>
+
+   </dependencies>
+
+</project>

Added: modules/trunk/webbeans-bridge/src/main/java/org/jboss/seam/bridge/webbeans/WebBeansManagerProvider.java
===================================================================
--- modules/trunk/webbeans-bridge/src/main/java/org/jboss/seam/bridge/webbeans/WebBeansManagerProvider.java	                        (rev 0)
+++ modules/trunk/webbeans-bridge/src/main/java/org/jboss/seam/bridge/webbeans/WebBeansManagerProvider.java	2009-05-11 20:05:51 UTC (rev 10852)
@@ -0,0 +1,33 @@
+package org.jboss.seam.bridge.webbeans;
+
+import javax.el.ELResolver;
+import javax.inject.manager.Manager;
+
+import org.jboss.seam.bridge.spi.ManagerProvider;
+import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.el.WebBeansELResolver;
+
+/**
+ * An implementation of Seam's Manager SPI interface for integrating Seam with
+ * the WebBeans Manager.
+ * 
+ * @author Dan Allen
+ */
+public class WebBeansManagerProvider implements ManagerProvider
+{
+   public Manager getCurrentManager()
+   {
+      return CurrentManager.rootManager().getCurrent();
+   }
+
+   public Manager getRootManager()
+   {
+      return CurrentManager.rootManager();
+   }
+
+   public ELResolver getELResolver()
+   {
+      return new WebBeansELResolver();
+   }
+
+}

Added: modules/trunk/webbeans-bridge/src/main/resources/META-INF/services/org.jboss.seam.bridge.spi.ManagerProvider
===================================================================
--- modules/trunk/webbeans-bridge/src/main/resources/META-INF/services/org.jboss.seam.bridge.spi.ManagerProvider	                        (rev 0)
+++ modules/trunk/webbeans-bridge/src/main/resources/META-INF/services/org.jboss.seam.bridge.spi.ManagerProvider	2009-05-11 20:05:51 UTC (rev 10852)
@@ -0,0 +1 @@
+org.jboss.seam.bridge.webbeans.WebBeansManagerProvider




More information about the seam-commits mailing list