[jboss-cvs] JBossAS SVN: r87312 - in projects/webbeans-ri-int/trunk/deployer/src/main: java/org/jboss/webbeans/integration/deployer/env and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 14 19:26:24 EDT 2009


Author: petemuir
Date: 2009-04-14 19:26:24 -0400 (Tue, 14 Apr 2009)
New Revision: 87312

Added:
   projects/webbeans-ri-int/trunk/deployer/src/main/java/org/jboss/webbeans/integration/deployer/env/WebBeansJndiBinder.java
Modified:
   projects/webbeans-ri-int/trunk/deployer/src/main/assembly/resources/META-INF/webbeans-deployers-jboss-beans.xml
Log:
WBINT-12

Modified: projects/webbeans-ri-int/trunk/deployer/src/main/assembly/resources/META-INF/webbeans-deployers-jboss-beans.xml
===================================================================
--- projects/webbeans-ri-int/trunk/deployer/src/main/assembly/resources/META-INF/webbeans-deployers-jboss-beans.xml	2009-04-14 20:53:25 UTC (rev 87311)
+++ projects/webbeans-ri-int/trunk/deployer/src/main/assembly/resources/META-INF/webbeans-deployers-jboss-beans.xml	2009-04-14 23:26:24 UTC (rev 87312)
@@ -34,4 +34,13 @@
   <!-- Responsible for adding the Web Beans RI listener to the Servlet -->
   <bean name="PostWebMetadataDeployer" class="org.jboss.webbeans.integration.deployer.metadata.PostWebMetadataDeployer"/>
 
+  <!-- Responsible for adding the Web Beans Manager object factory to JNDI -->
+  <bean name="WebBeansJndiBinder" class="org.jboss.webbeans.integration.deployer.env.WebBeansJndiBinder">
+  	<install method="startService">
+  		<parameter>java:app/Manager</parameter>
+  		<parameter>org.jboss.webbeans.resources.ManagerObjectFactory</parameter>
+  	</install>
+  	<uninstall method="stopService"/>
+  </bean>
+
 </deployment>

Added: projects/webbeans-ri-int/trunk/deployer/src/main/java/org/jboss/webbeans/integration/deployer/env/WebBeansJndiBinder.java
===================================================================
--- projects/webbeans-ri-int/trunk/deployer/src/main/java/org/jboss/webbeans/integration/deployer/env/WebBeansJndiBinder.java	                        (rev 0)
+++ projects/webbeans-ri-int/trunk/deployer/src/main/java/org/jboss/webbeans/integration/deployer/env/WebBeansJndiBinder.java	2009-04-14 23:26:24 UTC (rev 87312)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.integration.deployer.env;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.ExecutionException;
+import javax.inject.manager.Manager;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+
+/**
+ * This singleton bean for the deployer is responsible for binding
+ * an object factory to the required name(s) in JNDI.  Once bound,
+ * all deployed applications can obtain the Web Beans manager from
+ * JNDI.
+ * 
+ * @author David Allen
+ *
+ */
+public class WebBeansJndiBinder
+{
+   private String jndiName = null;
+
+   public void startService(String jndiContextPath, String managerObjectFactoryClass) throws Exception
+   {
+      jndiName = jndiContextPath;
+      Reference managerReference = new Reference(Manager.class.getName(), managerObjectFactoryClass, null);
+      bind(jndiContextPath, managerReference);
+   }
+   
+   public void stopService() throws Exception
+   {
+      Context initialContext = new InitialContext();
+      initialContext.unbind(jndiName);
+   }
+   
+   protected void bind(String key, Object binding) throws Exception
+   {
+      Context initialContext = new InitialContext();
+      try
+      {
+         List<String> parts = splitIntoContexts(key);
+         Context context = initialContext;
+         Context nextContext = null;
+         for (int i = 0; i < parts.size() - 1; i++)
+         {
+            try
+            {
+               nextContext = (Context) context.lookup(parts.get(i));
+            }
+            catch (NamingException e)
+            {
+               nextContext = context.createSubcontext(parts.get(i));
+            }
+            context = nextContext;
+         }
+         context.bind(parts.get(parts.size() - 1), binding);
+      }
+      catch (NamingException e)
+      {
+         throw new ExecutionException("Cannot bind " + binding + " to " + key, e);
+      }
+
+   }
+
+   private static List<String> splitIntoContexts(String key)
+   {
+      List<String> parts = new ArrayList<String>();
+      for (String part : key.split("/"))
+      {
+         parts.add(part);
+      }
+      return parts;
+   }
+   
+}


Property changes on: projects/webbeans-ri-int/trunk/deployer/src/main/java/org/jboss/webbeans/integration/deployer/env/WebBeansJndiBinder.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the jboss-cvs-commits mailing list