[jboss-cvs] JBossAS SVN: r95915 - in projects/weld-int/trunk: deployer/src/main/java/org/jboss/weld/integration/deployer and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 2 08:25:53 EST 2009
Author: pete.muir at jboss.org
Date: 2009-11-02 08:25:53 -0500 (Mon, 02 Nov 2009)
New Revision: 95915
Added:
projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/
projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java
Removed:
projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldJndiBinder.java
Modified:
projects/weld-int/trunk/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml
Log:
new jndi binder
Modified: projects/weld-int/trunk/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml
===================================================================
--- projects/weld-int/trunk/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml 2009-11-02 12:24:15 UTC (rev 95914)
+++ projects/weld-int/trunk/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml 2009-11-02 13:25:53 UTC (rev 95915)
@@ -50,13 +50,4 @@
<!-- Responsible for adding the Weld listener to the Servlet -->
<bean name="PostWebMetadataDeployer" class="org.jboss.weld.integration.deployer.metadata.PostWebMetadataDeployer"/>
- <!-- Responsible for adding the Weld Manager object factory to JNDI -->
- <bean name="WeldJndiBinder" class="org.jboss.weld.integration.deployer.env.WeldJndiBinder">
- <start method="startService">
- <parameter>java:app/BeanManager</parameter>
- <parameter>org.jboss.weld.resources.ManagerObjectFactory</parameter>
- </start>
- <stop method="stopService"/>
- </bean>
-
</deployment>
Deleted: projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldJndiBinder.java
===================================================================
--- projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldJndiBinder.java 2009-11-02 12:24:15 UTC (rev 95914)
+++ projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldJndiBinder.java 2009-11-02 13:25:53 UTC (rev 95915)
@@ -1,98 +0,0 @@
-/*
- * 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.weld.integration.deployer.env;
-
-import javax.enterprise.inject.spi.BeanManager;
-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 WeldJndiBinder
-{
- private String jndiName = null;
-
- /**
- * Start the service.
- *
- * @param jndiContextPath the jndi context path
- * @param managerObjectFactoryClass the manager object factory
- * @throws Exception for any error
- */
- public void startService(String jndiContextPath, String managerObjectFactoryClass) throws Exception
- {
- jndiName = jndiContextPath;
- Reference managerReference = new Reference(BeanManager.class.getName(), managerObjectFactoryClass, null);
- bind(jndiContextPath, managerReference);
- }
-
- /**
- * Stop the service.
- *
- * @throws Exception for any error
- */
- public void stopService() throws Exception
- {
- Context initialContext = new InitialContext();
- initialContext.unbind(jndiName);
- }
-
- /**
- * Bind object to jndi.
- *
- * @param key the key
- * @param binding the object to bind
- * @throws Exception for any error
- */
- protected void bind(String key, Object binding) throws Exception
- {
- Context initialContext = new InitialContext();
- try
- {
- String[] parts = key.split("/");
- int length = parts.length;
- Context context = initialContext;
- Context nextContext;
- for (int i = 0; i < length - 1; i++)
- {
- try
- {
- nextContext = (Context) context.lookup(parts[i]);
- }
- catch (NamingException e)
- {
- nextContext = context.createSubcontext(parts[i]);
- }
- context = nextContext;
- }
- context.bind(parts[length - 1], binding);
- }
- catch (NamingException e)
- {
- throw new RuntimeException("Cannot bind " + binding + " to " + key, e);
- }
- }
-}
Added: projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java
===================================================================
--- projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java (rev 0)
+++ projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java 2009-11-02 13:25:53 UTC (rev 95915)
@@ -0,0 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.weld.integration.deployer.jndi;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.util.naming.NonSerializableFactory;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.integration.deployer.env.helpers.BootstrapBean;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ * Jndi name binder. This class binds Bean Managers into global JNDI
+ * under a well-known subcontext.
+ *
+ * @author Pete Muir
+ * @author <a href="mailto:stan.silvert at jboss.org">Stan Silvert</a>
+ */
+public class JndiBinder
+{
+
+ protected static class DeploymentVisitor
+ {
+
+ private final Map<String, BeanManager> beanManagers;
+ private final BootstrapBean bootstrapBean;
+
+ public DeploymentVisitor(BootstrapBean bootstrapBean)
+ {
+ this.beanManagers = new HashMap<String, BeanManager>();
+ this.bootstrapBean = bootstrapBean;
+ }
+
+ public Map<String, BeanManager> getBeanManagers()
+ {
+ return Collections.unmodifiableMap(beanManagers);
+ }
+
+ public DeploymentVisitor visit()
+ {
+ for (BeanDeploymentArchive bda : bootstrapBean.getDeployment().getBeanDeploymentArchives())
+ {
+ visit(bda, new HashSet<BeanDeploymentArchive>());
+ }
+ return this;
+ }
+
+ private void visit(BeanDeploymentArchive bda, Set<BeanDeploymentArchive> seenBdas)
+ {
+ WeldManager beanManager = bootstrapBean.getBootstrap().getManager(bda);
+ // BeanManager id is simply the BDA ID
+ String key = beanManager.getId();
+ beanManagers.put(key, beanManager);
+ for (BeanDeploymentArchive child : bda.getBeanDeploymentArchives())
+ {
+ if (!seenBdas.contains(child))
+ {
+ visit(child, seenBdas);
+ }
+ }
+ }
+
+ }
+
+ public static final String BEAN_MANAGER_JNDI_SUBCONTEXT = "BeanManagers";
+
+ protected static Context createSubContextForFactories(Hashtable<String, String> jndiEnvironment, String prefix)
+ {
+ try
+ {
+ Context root = new InitialContext(jndiEnvironment);
+ return root.createSubcontext(BEAN_MANAGER_JNDI_SUBCONTEXT).createSubcontext(prefix);
+ }
+ catch (NamingException e)
+ {
+ throw new IllegalStateException("Unable to create JNDI subcontext for Bean Managers", e);
+ }
+ }
+
+ protected static void addNonSerializableFactory(Hashtable<String, String> environment)
+ {
+ String nonSerializableFactory = NonSerializableFactory.class.getName();
+ String objFactory = environment.get(Context.OBJECT_FACTORIES);
+ if (objFactory != null)
+ {
+ objFactory = nonSerializableFactory + ":" + objFactory;
+ }
+ else
+ {
+ objFactory = nonSerializableFactory;
+ }
+
+ environment.put(Context.OBJECT_FACTORIES, objFactory);
+ }
+
+ private final Context beanManagerContext;
+ private final Map<String, BeanManager> beanManagers;
+
+ public JndiBinder(BootstrapBean bootstrapBean, String deploymentUnitName)
+ {
+ Hashtable<String, String> jndiEnvironment = new Hashtable<String, String>();
+ this.beanManagers = new DeploymentVisitor(bootstrapBean).visit().getBeanManagers();
+ this.beanManagerContext = createSubContextForFactories(jndiEnvironment, deploymentUnitName);
+ addNonSerializableFactory(jndiEnvironment);
+ }
+
+ public void bind() throws NamingException
+ {
+ for (Entry<String, BeanManager> entry : beanManagers.entrySet())
+ {
+ NonSerializableFactory.rebind(this.beanManagerContext, entry.getKey(), entry.getValue());
+ }
+ }
+
+ public void unbind() throws NamingException
+ {
+ for (Entry<String, BeanManager> entry : beanManagers.entrySet())
+ {
+ this.beanManagerContext.unbind(entry.getKey());
+ NonSerializableFactory.unbind(entry.getKey());
+ }
+ }
+
+}
Property changes on: projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list