[jboss-cvs] JBossAS SVN: r72296 - in trunk/ejb3/src/main/org/jboss/ejb3/deployers: tmp and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 16 12:20:01 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-04-16 12:20:01 -0400 (Wed, 16 Apr 2008)
New Revision: 72296
Added:
trunk/ejb3/src/main/org/jboss/ejb3/deployers/tmp/
trunk/ejb3/src/main/org/jboss/ejb3/deployers/tmp/DeploymentEjbResolver.java
trunk/ejb3/src/main/org/jboss/ejb3/deployers/tmp/EjbModuleEjbResolver.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/deployers/EJBRegistrationDeployer.java
trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3Deployer.java
trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java
Log:
EJBTHREE-1291, bridge resolution between the MappedReferenceMetaDataResolverDeployer and ReferenceMetaDataResolverDeployer in the DeploymentScope implementation while resolution is being unified.
Modified: trunk/ejb3/src/main/org/jboss/ejb3/deployers/EJBRegistrationDeployer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/EJBRegistrationDeployer.java 2008-04-16 16:07:21 UTC (rev 72295)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/EJBRegistrationDeployer.java 2008-04-16 16:20:01 UTC (rev 72296)
@@ -34,10 +34,12 @@
import org.jboss.deployers.vfs.spi.deployer.AbstractVFSRealDeployer;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.deployment.security.JaccPolicyUtil;
+import org.jboss.deployment.spi.DeploymentEndpointResolver;
import org.jboss.ejb3.DeploymentScope;
import org.jboss.ejb3.Ejb3Deployment;
import org.jboss.kernel.Kernel;
import org.jboss.logging.Logger;
+import org.jboss.metadata.ear.jboss.JBossAppMetaData;
import org.jboss.virtual.VirtualFile;
/**
@@ -226,21 +228,35 @@
}
log.debug("********* EJBRegistrationDepoyer Begin Unit: " + unit.getSimpleName() + " jar: " + jar.getName());
- DeploymentScope scope = null;
+ JBoss5DeploymentScope scope = null;
VFSDeploymentUnit parent = unit.getParent();
- if (parent != null && parent.getSimpleName().endsWith(".ear")) // todo should look for metadata instead of ".ear"
+ boolean initScopeDeployment = false;
+ if (parent != null && parent.isAttachmentPresent(JBossAppMetaData.class))
{
- scope = parent.getAttachment(DeploymentScope.class);
+ // An ear parent
+ scope = (JBoss5DeploymentScope) parent.getAttachment(DeploymentScope.class);
if (scope == null)
{
- scope = new JBoss5DeploymentScope(unit.getParent());
+ if(parent.isAttachmentPresent(DeploymentEndpointResolver.class) == true)
+ scope = new JBoss5DeploymentScope(parent);
+ else
+ {
+ // EJBTHREE-1291
+ scope = new JBoss5DeploymentScope(parent, unit.getSimpleName());
+ initScopeDeployment = true;
+ }
parent.addAttachment(DeploymentScope.class, scope);
}
}
JBoss5DeploymentUnit du = new JBoss5DeploymentUnit(unit);
du.setDefaultPersistenceProperties(defaultPersistenceProperties);
Ejb3JBoss5Deployment deployment = new Ejb3JBoss5Deployment(du, kernel, mbeanServer, unit, scope, null, null);
- if (scope != null) scope.register(deployment);
+ if (scope != null)
+ scope.register(deployment);
+ if(initScopeDeployment)
+ {
+ scope.setDeployment(deployment);
+ }
// create() creates initial EJB containers and initializes metadata.
deployment.create();
if (deployment.getEjbContainers().size() == 0 && deployment.getPersistenceUnitDeployments().size() == 0)
Modified: trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3Deployer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3Deployer.java 2008-04-16 16:07:21 UTC (rev 72295)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3Deployer.java 2008-04-16 16:20:01 UTC (rev 72296)
@@ -21,6 +21,7 @@
*/
package org.jboss.ejb3.deployers;
+import java.util.LinkedHashMap;
import java.util.Properties;
import java.util.Set;
@@ -30,6 +31,7 @@
import org.jboss.deployers.vfs.spi.deployer.AbstractVFSRealDeployer;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.deployment.security.JaccPolicyUtil;
+import org.jboss.deployment.spi.DeploymentEndpointResolver;
import org.jboss.ejb.deployers.MergedJBossMetaDataDeployer;
import org.jboss.ejb3.DeploymentScope;
import org.jboss.ejb3.Ejb3Deployment;
@@ -39,6 +41,7 @@
import org.jboss.ejb3.pool.PoolFactoryRegistry;
import org.jboss.ejb3.remoting.RemoteProxyFactoryRegistry;
import org.jboss.kernel.Kernel;
+import org.jboss.metadata.ear.jboss.JBossAppMetaData;
import org.jboss.metadata.ejb.jboss.JBossMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.virtual.VirtualFile;
@@ -133,25 +136,39 @@
log.debug("********* " + this.getClass().getSimpleName() + " Begin Unit: " + unit.getSimpleName() + " jar: "
+ jar.getName());
- DeploymentScope scope = null;
+ JBoss5DeploymentScope scope = null;
VFSDeploymentUnit parent = unit.getParent();
- if (parent != null && parent.getSimpleName().endsWith(".ear")) // todo should look for metadata instead of ".ear"
+ boolean initScopeDeployment = false;
+ if (parent != null && parent.isAttachmentPresent(JBossAppMetaData.class))
{
- scope = parent.getAttachment(DeploymentScope.class);
+ // An ear parent
+ scope = (JBoss5DeploymentScope) parent.getAttachment(DeploymentScope.class);
if (scope == null)
{
- scope = new JBoss5DeploymentScope(unit.getParent());
+ if(parent.isAttachmentPresent(DeploymentEndpointResolver.class) == true)
+ scope = new JBoss5DeploymentScope(parent);
+ else
+ {
+ // EJBTHREE-1291
+ scope = new JBoss5DeploymentScope(parent, unit.getSimpleName());
+ initScopeDeployment = true;
+ }
parent.addAttachment(DeploymentScope.class, scope);
}
}
JBoss5DeploymentUnit du = new JBoss5DeploymentUnit(unit);
du.setDefaultPersistenceProperties(defaultPersistenceProperties);
Ejb3JBoss5Deployment deployment = new Ejb3JBoss5Deployment(du, kernel, mbeanServer, unit, scope, metaData, persistenceUnitsMetaData);
+ if(initScopeDeployment)
+ {
+ scope.setDeployment(deployment);
+ }
deployment.setCacheFactoryRegistry(this.getCacheFactoryRegistry());
deployment.setPersistenceManagerFactoryRegistry(this.getPersistenceManagerFactoryRegistry());
deployment.setRemoteProxyFactoryRegistry(this.getRemoteProxyFactoryRegistry());
deployment.setPoolFactoryRegistry(this.getPoolFactoryRegistry());
- if (scope != null) scope.register(deployment);
+ if (scope != null)
+ scope.register(deployment);
// create() creates initial EJB containers and initializes metadata.
deployment.create();
if (deployment.getEjbContainers().size() == 0 && deployment.getPersistenceUnitDeployments().size() == 0)
Modified: trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java 2008-04-16 16:07:21 UTC (rev 72295)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java 2008-04-16 16:20:01 UTC (rev 72296)
@@ -22,9 +22,11 @@
package org.jboss.ejb3.deployers;
import java.util.Collection;
+import java.util.LinkedHashMap;
import java.util.concurrent.ConcurrentHashMap;
import javax.management.ObjectName;
+import javax.naming.NameNotFoundException;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.deployment.spi.DeploymentEndpointResolver;
@@ -33,6 +35,7 @@
import org.jboss.ejb3.DeploymentScope;
import org.jboss.ejb3.EJBContainer;
import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.deployers.tmp.EjbModuleEjbResolver;
import org.jboss.ejb3.javaee.JavaEEComponentHelper;
import org.jboss.logging.Logger;
@@ -52,6 +55,7 @@
private ConcurrentHashMap<String, Ejb3Deployment> deployments;
/** The deployment endpoint resolver implementation */
private DeploymentEndpointResolver endpointResolver;
+ private EjbModuleEjbResolver ejbRefResolver;
/** The parent deployment short name */
private String shortName;
/** The deployment short name minus any .suffix */
@@ -74,12 +78,29 @@
deployments = new ConcurrentHashMap<String, Ejb3Deployment>();
parent.addAttachment(ATTACHMENT_KEY, deployments);
}
- /* MappedReferenceMetaDataResolverDeployer output, Look for the endpoint resolver
+ // MappedReferenceMetaDataResolverDeployer output, Look for the endpoint resolver
endpointResolver = parent.getAttachment(DeploymentEndpointResolver.class);
+ /*
if(endpointResolver == null)
throw new IllegalStateException("No DeploymentEndpointResolver found in deployment: "+parent);
*/
}
+ /**
+ * Temp ctor until EJBTHREE-1291 is resolved
+ * @param parent
+ * @param errorName
+ * @param ejbContainers
+ * @param deployment
+ */
+ public JBoss5DeploymentScope(VFSDeploymentUnit parent, String errorName)
+ {
+ this(parent);
+ ejbRefResolver = new EjbModuleEjbResolver(this, shortName);
+ }
+ public void setDeployment(Ejb3Deployment deployment)
+ {
+ ejbRefResolver.setDeployment(deployment);
+ }
public DeploymentEndpointResolver getEndpointResolver()
{
@@ -122,9 +143,16 @@
@SuppressWarnings("unchecked")
public EJBContainer getEjbContainer(Class businessIntf, String vfsContext)
+ throws NameNotFoundException
{
+ // Get the deployment endpoint
+ if(ejbRefResolver != null)
+ {
+ // TODO: EJBTHREE-1291
+ return ejbRefResolver.getEjbContainer(businessIntf);
+ }
+
EJBContainer container = null;
- // Get the deployment endpoint
EndpointInfo endpoint = endpointResolver.getEndpointInfo(businessIntf, EndpointType.EJB, vfsContext);
if(endpoint != null)
{
@@ -153,6 +181,12 @@
@SuppressWarnings("unchecked")
public EJBContainer getEjbContainer(String ejbLink, Class businessIntf, String vfsContext)
{
+ if(ejbRefResolver != null)
+ {
+ // TODO: EJBTHREE-1291
+ return ejbRefResolver.getEjbContainer(ejbLink, businessIntf);
+ }
+
EJBContainer container = null;
// First try the ejbLink
EndpointInfo endpoint = endpointResolver.getEndpointInfo(ejbLink, EndpointType.EJB, vfsContext);
@@ -177,7 +211,14 @@
{
log.debug("Failed to find endpoint for ejbLink: "+ejbLink);
// Try the business interface
- container = getEjbContainer(businessIntf, vfsContext);
+ try
+ {
+ container = getEjbContainer(businessIntf, vfsContext);
+ }
+ catch(NameNotFoundException e)
+ {
+ log.debug("Did not resolve container by interface: "+businessIntf, e);
+ }
}
return container;
}
@@ -196,4 +237,5 @@
{
return baseName;
}
+
}
Copied: trunk/ejb3/src/main/org/jboss/ejb3/deployers/tmp/DeploymentEjbResolver.java (from rev 72283, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/enc/DeploymentEjbResolver.java)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/tmp/DeploymentEjbResolver.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/tmp/DeploymentEjbResolver.java 2008-04-16 16:20:01 UTC (rev 72296)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.deployers.tmp;
+
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.Ejb3Registry;
+import org.jboss.ejb3.ProxyFactoryHelper;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.DeploymentScope;
+import org.jboss.logging.Logger;
+
+import javax.naming.NameNotFoundException;
+import java.util.Iterator;
+
+/**
+ * Class to resolve EJB containers from ejb-ref or @EJB metadata
+ * This class is overriden for specific behaviors, specifically whether or not
+ * to resolve the EJB internally in a specific deployment or not. There will be one for
+ * an EJB jar deployment and a WAR deployment and any other deployment package that needs to
+ * use @EJB.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public abstract class DeploymentEjbResolver
+{
+ private static final Logger log = Logger.getLogger(DeploymentEjbResolver.class);
+
+ protected DeploymentScope deploymentScope;
+ protected String errorName;
+
+ protected DeploymentEjbResolver(DeploymentScope deploymentScope, String errorName)
+ {
+ this.deploymentScope = deploymentScope;
+ this.errorName = errorName;
+ }
+
+ protected abstract EJBContainer searchDeploymentInternally(String ejbLink, Class businessIntf);
+
+ public EJBContainer getEjbContainer(String ejbLink, Class businessIntf)
+ {
+ int hashIndex = ejbLink.indexOf('#');
+ if (hashIndex != -1)
+ {
+ if (deploymentScope == null)
+ {
+ log.warn("ejb link '" + ejbLink + "' is relative, but no deployment scope found");
+ return null;
+ }
+ String relativePath = ejbLink.substring(0, hashIndex);
+ Ejb3Deployment dep = deploymentScope.findRelativeDeployment(relativePath);
+ if (dep == null)
+ {
+ log.warn("can't find a deployment for path '" + relativePath + "' of ejb link '" + ejbLink + "'");
+ return null;
+ }
+ String ejbName = ejbLink.substring(hashIndex + 1);
+ return dep.getEjbContainer(ejbName, businessIntf);
+ }
+ // look internally
+ EJBContainer ejb = searchDeploymentInternally(ejbLink, businessIntf);
+ if (ejb != null) return ejb;
+ for (Object obj : Ejb3Registry.getContainers())
+ {
+ EJBContainer container = (EJBContainer) obj;
+ if (container.getEjbName().equals(ejbLink))
+ {
+ return container;
+ }
+ }
+ return null;
+ }
+
+ public String getEjbJndiName(String ejbLink, Class businessIntf)
+ {
+ EJBContainer container = getEjbContainer(ejbLink, businessIntf);
+ if (container == null)
+ {
+ return null;
+ }
+ return ProxyFactoryHelper.getJndiName(container, businessIntf);
+ }
+
+ public EJBContainer getEjbContainer(Ejb3Deployment deployment, Class businessIntf) throws NameNotFoundException
+ {
+ EJBContainer container = null;
+ // search in myself
+ for (Object obj : deployment.getEjbContainers().values())
+ {
+ EJBContainer newContainer = (EJBContainer) obj;
+ if (container == newContainer) continue;
+ if (ProxyFactoryHelper.publishesInterface(newContainer, businessIntf))
+ {
+ if (container != null) throw new NameNotFoundException("duplicated in " + errorName);
+ container = newContainer;
+ }
+ }
+ return container;
+ }
+
+ public EJBContainer getEjbContainer(Class businessIntf) throws NameNotFoundException
+ {
+ EJBContainer rtnContainer = null;
+ // search in deployment first
+ rtnContainer = searchForEjbContainerInternally(businessIntf);
+ if (rtnContainer != null) return rtnContainer;
+ // search in EAR
+ String jarName = null;
+ if (deploymentScope != null)
+ {
+ for (Ejb3Deployment deployment : deploymentScope.getEjbDeployments())
+ {
+ EJBContainer newContainer = getEjbContainer(deployment, businessIntf);
+ if (rtnContainer == newContainer) continue; // don't check self
+ if (rtnContainer != null && newContainer != null)
+ {
+ throw new NameNotFoundException("duplicated in .ear within " + jarName +
+ " and " + deployment.getDeploymentUnit().getShortName());
+ }
+ if (newContainer != null)
+ {
+ rtnContainer = newContainer;
+ jarName = deployment.getDeploymentUnit().getShortName();
+ }
+ }
+ }
+ if (rtnContainer != null)
+ {
+ return rtnContainer;
+ }
+ // search everywhere
+ Iterator containers = Ejb3Registry.getContainers().iterator();
+ while (containers.hasNext())
+ {
+ Container container = (Container)containers.next();
+ EJBContainer ejbContainer = (EJBContainer) container;
+ if (ejbContainer == rtnContainer) continue;
+ if (ProxyFactoryHelper.publishesInterface(container, businessIntf))
+ {
+ if (rtnContainer != null)
+ {
+ throw new NameNotFoundException("duplicated in " + ejbContainer.getDeployment().getDeploymentUnit().getShortName()
+ + " and " + jarName);
+ }
+ rtnContainer = ejbContainer;
+ jarName = ejbContainer.getDeployment().getDeploymentUnit().getShortName();
+ }
+ }
+ if (rtnContainer != null) return rtnContainer;
+ throw new NameNotFoundException("not used by any EJBs");
+ }
+
+ protected abstract EJBContainer searchForEjbContainerInternally(Class businessIntf) throws NameNotFoundException;
+
+ public String getEjbJndiName(Class businessIntf) throws NameNotFoundException
+ {
+ EJBContainer container = getEjbContainer(businessIntf);
+ String jndiName = ProxyFactoryHelper.getJndiName(container, businessIntf);
+ if (jndiName == null) throw new NameNotFoundException("not used by any EJBs");
+ return jndiName;
+ }
+}
Copied: trunk/ejb3/src/main/org/jboss/ejb3/deployers/tmp/EjbModuleEjbResolver.java (from rev 72283, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/enc/EjbModuleEjbResolver.java)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/tmp/EjbModuleEjbResolver.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/tmp/EjbModuleEjbResolver.java 2008-04-16 16:20:01 UTC (rev 72296)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.deployers.tmp;
+
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.DeploymentScope;
+
+import javax.naming.NameNotFoundException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Resolve EJBs.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class EjbModuleEjbResolver extends DeploymentEjbResolver
+{
+ protected Map<?, EJBContainer> ejbContainers;
+ protected Ejb3Deployment deployment;
+
+ public EjbModuleEjbResolver(DeploymentScope deploymentScope, String errorName)
+ {
+ this(deploymentScope, errorName, null, null);
+ }
+ public EjbModuleEjbResolver(DeploymentScope deploymentScope, String errorName,
+ Map ejbContainers, Ejb3Deployment deployment)
+ {
+ super(deploymentScope, errorName);
+ this.ejbContainers = ejbContainers;
+ this.deployment = deployment;
+ }
+
+ public Ejb3Deployment getDeployment()
+ {
+ return deployment;
+ }
+ public void setDeployment(Ejb3Deployment deployment)
+ {
+ this.deployment = deployment;
+ this.ejbContainers = deployment.getEjbContainers();
+ }
+
+ @Override
+ protected EJBContainer searchDeploymentInternally(String ejbLink, Class businessIntf)
+ {
+ for (EJBContainer container : ejbContainers.values())
+ {
+ if (container.getEjbName().equals(ejbLink))
+ {
+ return container;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected EJBContainer searchForEjbContainerInternally(Class businessIntf) throws NameNotFoundException
+ {
+ EJBContainer rtnContainer;
+ rtnContainer = getEjbContainer(deployment, businessIntf);
+ return rtnContainer;
+ }
+
+}
More information about the jboss-cvs-commits
mailing list