[jboss-cvs] JBossAS SVN: r108238 - in projects/ejb3/trunk/metadata-deployers: src/main/java/org/jboss/ejb3/metadata/deployers and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 21 06:06:43 EDT 2010
Author: jaikiran
Date: 2010-09-21 06:06:43 -0400 (Tue, 21 Sep 2010)
New Revision: 108238
Added:
projects/ejb3/trunk/metadata-deployers/src/main/java/org/jboss/ejb3/metadata/deployers/EJB31GlobalJNDINamespaceBinderDeployer.java
Modified:
projects/ejb3/trunk/metadata-deployers/pom.xml
Log:
EJBTHREE-2164 Initial work on java:global JNDI namespace. Note that java:app and java:module aren't yet handled
Modified: projects/ejb3/trunk/metadata-deployers/pom.xml
===================================================================
--- projects/ejb3/trunk/metadata-deployers/pom.xml 2010-09-21 02:22:19 UTC (rev 108237)
+++ projects/ejb3/trunk/metadata-deployers/pom.xml 2010-09-21 10:06:43 UTC (rev 108238)
@@ -24,7 +24,8 @@
<version.org.jboss.ejb3_deployers>1.1.0</version.org.jboss.ejb3_deployers>
<version.org.jboss.microcontainer>2.0.8.GA</version.org.jboss.microcontainer>
<version.org.jboss_jbossxb>2.0.1.GA</version.org.jboss_jbossxb>
- <version.metadata_ejb>2.0.0-alpha-5</version.metadata_ejb>
+ <version.metadata_ejb>2.0.0-alpha-18</version.metadata_ejb>
+ <version.reloaded.naming.deployer>0.1.0</version.reloaded.naming.deployer>
</properties>
<build>
@@ -94,6 +95,7 @@
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-spi</artifactId>
</dependency>
+
<!-- JBoss Metadata -->
<dependency>
Added: projects/ejb3/trunk/metadata-deployers/src/main/java/org/jboss/ejb3/metadata/deployers/EJB31GlobalJNDINamespaceBinderDeployer.java
===================================================================
--- projects/ejb3/trunk/metadata-deployers/src/main/java/org/jboss/ejb3/metadata/deployers/EJB31GlobalJNDINamespaceBinderDeployer.java (rev 0)
+++ projects/ejb3/trunk/metadata-deployers/src/main/java/org/jboss/ejb3/metadata/deployers/EJB31GlobalJNDINamespaceBinderDeployer.java 2010-09-21 10:06:43 UTC (rev 108238)
@@ -0,0 +1,212 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.metadata.deployers;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.LinkRef;
+import javax.naming.NamingException;
+
+import org.jboss.beans.metadata.api.annotations.Start;
+import org.jboss.beans.metadata.api.annotations.Stop;
+import org.jboss.beans.metadata.plugins.builder.BeanMetaDataBuilderFactory;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBean31MetaData;
+import org.jboss.metadata.ejb.jboss.jndi.resolver.impl.JNDIPolicyBasedSessionBean31JNDINameResolver;
+import org.jboss.metadata.ejb.jboss.jndipolicy.plugins.JavaEE6JndiBindingPolicy;
+import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
+import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
+import org.jboss.util.naming.Util;
+
+/**
+ * EJB31GlobalJNDINamespaceBinderDeployer
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class EJB31GlobalJNDINamespaceBinderDeployer extends AbstractDeployer
+{
+
+ private static final String EJB31_GLOBAL_JNDI_NAMESPACE_PREFIX = "java:global/";
+
+ private JNDIPolicyBasedSessionBean31JNDINameResolver javaGlobalNamespaceJNDINameResolver;
+
+
+ private JNDIPolicyBasedSessionBean31JNDINameResolver jbossNamingSchemeJNDINameResolver;
+
+
+ public EJB31GlobalJNDINamespaceBinderDeployer()
+ {
+ this.setStage(DeploymentStages.REAL);
+ // EJB metadata
+ this.setInput(JBossMetaData.class);
+
+ this.setOutput(BeanMetaData.class);
+
+ this.javaGlobalNamespaceJNDINameResolver = new JNDIPolicyBasedSessionBean31JNDINameResolver(new JavaEE6JndiBindingPolicy());
+ this.javaGlobalNamespaceJNDINameResolver.setIgnoreJNDIBindingPolicyOnMetaData(true);
+
+
+ this.jbossNamingSchemeJNDINameResolver = new JNDIPolicyBasedSessionBean31JNDINameResolver();
+ }
+
+
+ @Override
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ JBossMetaData jbossMetadata = unit.getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class);
+ if (jbossMetadata.isEJB31() == false)
+ {
+ return;
+ }
+ JBossEnterpriseBeansMetaData enterpriseBeans = jbossMetadata.getEnterpriseBeans();
+ if (enterpriseBeans == null || enterpriseBeans.isEmpty())
+ {
+ return;
+ }
+ for (JBossEnterpriseBeanMetaData enterpriseBean : enterpriseBeans)
+ {
+ if (enterpriseBean.isSession() == false || enterpriseBean instanceof JBossSessionBean31MetaData == false)
+ {
+ continue;
+ }
+ JBossSessionBean31MetaData sessionBean31 = (JBossSessionBean31MetaData) enterpriseBean;
+ this.processBusinessLocals(unit, sessionBean31);
+ this.processBusinessRemotes(unit, sessionBean31);
+ this.processNoInterfaceView(unit, sessionBean31);
+
+ }
+
+ }
+
+ private void processBusinessLocals(DeploymentUnit unit, JBossSessionBean31MetaData sessionBean31)
+ {
+ BusinessLocalsMetaData businessLocals = sessionBean31.getBusinessLocals();
+ if (businessLocals == null || businessLocals.isEmpty())
+ {
+ return;
+ }
+ for (String businessLocal : businessLocals)
+ {
+ this.generateJNDINames(unit, sessionBean31, businessLocal);
+
+ }
+ }
+
+ private void processBusinessRemotes(DeploymentUnit unit, JBossSessionBean31MetaData sessionBean31)
+ {
+ BusinessRemotesMetaData businessRemotes = sessionBean31.getBusinessRemotes();
+ if (businessRemotes == null || businessRemotes.isEmpty())
+ {
+ return;
+ }
+ for (String businessLocal : businessRemotes)
+ {
+ this.generateJNDINames(unit, sessionBean31, businessLocal);
+
+ }
+ }
+
+ private void processNoInterfaceView(DeploymentUnit unit, JBossSessionBean31MetaData sessionBean31)
+ {
+ if (sessionBean31.isNoInterfaceBean() == false)
+ {
+ return;
+ }
+ this.generateJNDINames(unit, sessionBean31, sessionBean31.getEjbClass());
+ }
+
+ private void generateJNDINames(DeploymentUnit unit, JBossSessionBean31MetaData sessionBean31, String className)
+ {
+ String jbossSpecificJNDIName = this.jbossNamingSchemeJNDINameResolver.resolveJNDIName(sessionBean31, className);
+
+ String javaGlobalJNDIName = EJB31_GLOBAL_JNDI_NAMESPACE_PREFIX + this.javaGlobalNamespaceJNDINameResolver.resolveJNDIName(sessionBean31, className);
+ Context ctx;
+ try
+ {
+ ctx = new InitialContext();
+ }
+ catch (NamingException ne)
+ {
+ throw new RuntimeException(ne);
+ }
+ LinkRef javaGlobalLinkRef = new LinkRef(jbossSpecificJNDIName);
+
+ JNDIBinder javaGlobalJNDIBinder = new JNDIBinder(ctx, javaGlobalJNDIName, javaGlobalLinkRef);
+
+ this.attachJNDIBinder(unit, javaGlobalJNDIBinder);
+ }
+
+ private void attachJNDIBinder(DeploymentUnit unit, JNDIBinder binder)
+ {
+ String mcBeanName = "javaee6-portable-jndibinder:" + binder.jndiName;
+ BeanMetaDataBuilder builder = BeanMetaDataBuilderFactory.createBuilder(mcBeanName, JNDIBinder.class.getName());
+ builder.setConstructorValue(binder);
+
+ unit.addAttachment(mcBeanName, builder.getBeanMetaData());
+ }
+
+
+ private class JNDIBinder
+ {
+ private Context jndiCtx;
+
+ private String jndiName;
+
+ private Object jndiObject;
+
+ private boolean bound;
+
+ JNDIBinder(Context ctx, String jndiName, Object object)
+ {
+ this.jndiCtx = ctx;
+ this.jndiName = jndiName;
+ this.jndiObject = object;
+ }
+
+ @Start
+ public void start() throws NamingException
+ {
+ Util.bind(this.jndiCtx, this.jndiName, this.jndiObject);
+ this.bound = true;
+ }
+
+ @Stop
+ public void stop() throws NamingException
+ {
+ if (bound)
+ {
+ Util.unbind(this.jndiCtx, this.jndiName);
+ }
+ }
+ }
+
+}
More information about the jboss-cvs-commits
mailing list