[jboss-cvs] JBossAS SVN: r88999 - in projects/ejb3/trunk/core/src: main/java/org/jboss/ejb3/core and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 18 04:14:28 EDT 2009
Author: wolfc
Date: 2009-05-18 04:14:28 -0400 (Mon, 18 May 2009)
New Revision: 88999
Added:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/resolvers/
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/resolvers/ScopedEJBReferenceResolver.java
projects/ejb3/trunk/core/src/main/java/org/jboss/injection/EJBInjectionContainer.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/FirstStateless.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/FirstStatelessBean.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/SecondStateless.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/SecondStatelessBean.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/unit/
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/unit/EjbReferenceTestCase.java
Modified:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/MCDependencyPolicy.java
projects/ejb3/trunk/core/src/main/java/org/jboss/injection/AbstractHandler.java
projects/ejb3/trunk/core/src/main/java/org/jboss/injection/EJBRemoteHandler.java
projects/ejb3/trunk/core/src/main/java/org/jboss/injection/InjectionContainer.java
projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-jboss-beans.xml
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/MockEjb3Deployment.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/cachepassivation/MockDeploymentUnit.java
projects/ejb3/trunk/core/src/test/resources/container-beans.xml
Log:
EJBTHREE-1828: deprecate usage of runtime components during EJB reference resolving
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2009-05-18 07:45:54 UTC (rev 88998)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -95,6 +95,7 @@
import org.jboss.ejb3.tx.UserTransactionImpl;
import org.jboss.injection.DependsHandler;
import org.jboss.injection.EJBHandler;
+import org.jboss.injection.EJBInjectionContainer;
import org.jboss.injection.EncInjector;
import org.jboss.injection.ExtendedInjectionContainer;
import org.jboss.injection.InjectionHandler;
@@ -125,7 +126,9 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public abstract class EJBContainer implements Container, IndirectContainer<EJBContainer, DirectContainer<EJBContainer>>, ExtendedInjectionContainer, JavaEEComponent
+public abstract class EJBContainer
+ implements Container, IndirectContainer<EJBContainer, DirectContainer<EJBContainer>>,
+ EJBInjectionContainer, ExtendedInjectionContainer, JavaEEComponent
{
private static final Logger log = Logger.getLogger(EJBContainer.class);
@@ -140,7 +143,7 @@
protected Pool pool;
protected String ejbName;
-
+
protected ObjectName objectName;
protected int defaultConstructorIndex;
@@ -298,6 +301,12 @@
}
}
+ @Deprecated
+ public boolean canResolveEJB()
+ {
+ return deployment.canResolveEJB();
+ }
+
public abstract BeanContext<?> createBeanContext();
public String createObjectName(String ejbName)
@@ -1408,6 +1417,11 @@
}
*/
+ public String resolveEJB(String link, Class<?> beanInterface, String mappedName)
+ {
+ return deployment.resolveEJB(link, beanInterface, mappedName);
+ }
+
public Container resolveEjbContainer(String link, Class businessIntf)
{
return deployment.getEjbContainer(link, businessIntf);
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java 2009-05-18 07:45:54 UTC (rev 88998)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -48,6 +48,8 @@
import org.jboss.ejb3.cache.CacheFactoryRegistry;
import org.jboss.ejb3.cache.persistence.PersistenceManagerFactoryRegistry;
import org.jboss.ejb3.common.lang.ClassHelper;
+import org.jboss.ejb3.common.resolvers.spi.EjbReference;
+import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
import org.jboss.ejb3.javaee.JavaEEApplication;
import org.jboss.ejb3.javaee.JavaEEComponent;
import org.jboss.ejb3.javaee.JavaEEComponentHelper;
@@ -130,6 +132,8 @@
private org.jboss.deployers.structure.spi.DeploymentUnit deploymentUnit;
+ private EjbReferenceResolver ejbReferenceResolver;
+
private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
/**
@@ -162,6 +166,12 @@
this.deploymentUnit = deploymentUnit;
}
+ @Deprecated
+ public boolean canResolveEJB()
+ {
+ return ejbReferenceResolver != null;
+ }
+
public JavaEEApplication getApplication()
{
return deploymentScope;
@@ -225,6 +235,12 @@
}
@Inject
+ public void setEJBReferenceResolver(EjbReferenceResolver resolver)
+ {
+ this.ejbReferenceResolver = resolver;
+ }
+
+ @Inject
public void setMessageDestinationReferenceResolver(MessageDestinationReferenceResolver resolver)
{
this.messageDestinationReferenceResolver = resolver;
@@ -760,6 +776,12 @@
}
}
+ public String resolveEJB(String link, Class<?> beanInterface, String mappedName)
+ {
+ EjbReference reference = new EjbReference(link, beanInterface.getName(), mappedName);
+ return ejbReferenceResolver.resolveEjb(deploymentUnit, reference);
+ }
+
public String resolveMessageDestination(String link)
{
return messageDestinationReferenceResolver.resolveMessageDestinationJndiName(deploymentUnit, link);
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/MCDependencyPolicy.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/MCDependencyPolicy.java 2009-05-18 07:45:54 UTC (rev 88998)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/MCDependencyPolicy.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -81,7 +81,11 @@
addDependency(ds);
}
-
+ /**
+ * @param businessInterface
+ * @deprecated See EJBTHREE-1828, depend on a bean name not business interface
+ */
+ @Deprecated
public void addDependency(Class<?> businessInterface)
{
// TODO: more sophisticated
@@ -96,7 +100,9 @@
*
* @param ejbLink the name of the target enterprise bean
* @param businessInterface
+ * @deprecated See EJBTHREE-1828, depend on a bean name not business interface
*/
+ @Deprecated
public void addDependency(String ejbLink, Class<?> businessInterface)
{
assert ejbLink != null : "ejbLink is null";
Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/resolvers/ScopedEJBReferenceResolver.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/resolvers/ScopedEJBReferenceResolver.java (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/resolvers/ScopedEJBReferenceResolver.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -0,0 +1,88 @@
+/*
+ * 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.core.resolvers;
+
+import java.util.List;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.resolvers.spi.EjbReference;
+import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
+import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolverBase;
+import org.jboss.ejb3.common.resolvers.spi.UnresolvableReferenceException;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ScopedEJBReferenceResolver extends EjbReferenceResolverBase
+ implements EjbReferenceResolver
+{
+ protected String find(DeploymentUnit du, EjbReference reference)
+ {
+ JBossMetaData metadata = getMetaData(du);
+
+ return getMatch(reference, metadata, du.getClassLoader());
+ }
+
+ /**
+ * Search a deployment unit and it's children.
+ *
+ * @param du
+ * @param reference
+ * @return
+ */
+ protected String findWithin(DeploymentUnit du, DeploymentUnit excludeChild, EjbReference reference)
+ {
+ String jndiName = find(du, reference);
+ if(jndiName != null)
+ return jndiName;
+
+ List<DeploymentUnit> children = du.getChildren();
+ if(children != null)
+ {
+ for(DeploymentUnit child : children)
+ {
+ // already searched that one
+ if(child == excludeChild)
+ continue;
+
+ jndiName = findWithin(child, null, reference);
+ if(jndiName != null)
+ return jndiName;
+ }
+ }
+
+ DeploymentUnit parent = du.getParent();
+ if(parent != null)
+ return findWithin(parent, du, reference);
+ return null;
+ }
+
+ public String resolveEjb(DeploymentUnit du, EjbReference reference) throws UnresolvableReferenceException
+ {
+ String jndiName = findWithin(du, null, reference);
+ if(jndiName == null)
+ throw new UnresolvableReferenceException("Could not resolve reference " + reference + " in " + du);
+ return jndiName;
+ }
+}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/AbstractHandler.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/AbstractHandler.java 2009-05-18 07:45:54 UTC (rev 88998)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/AbstractHandler.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -25,6 +25,7 @@
import org.jboss.ejb3.EJBContainer;
import org.jboss.ejb3.deployers.JBoss5DependencyPolicy;
+import org.jboss.logging.Logger;
import org.jboss.metadata.javaee.spec.RemoteEnvironment;
/**
@@ -35,6 +36,8 @@
*/
public abstract class AbstractHandler<X extends RemoteEnvironment> implements InjectionHandler<X>
{
+ private static final Logger log = Logger.getLogger(AbstractHandler.class);
+
// protected void addDependency(String refName, EJBContainer refcon, InjectionContainer container)
// {
// // Do not depend on myself
@@ -42,8 +45,15 @@
// container.getDependencyPolicy().addDependency(refcon.getObjectName().getCanonicalName());
// }
+
+ /**
+ * @deprecated resolve until a bean name is acquired, do not depend on a business interface
+ */
+ @Deprecated
protected void addDependency(InjectionContainer container, Class<?> businessIntf)
{
+ log.warn("EJBTHREE-1828: calling deprecated addDependency");
+
EJBContainer refCon = null;
try
{
@@ -60,8 +70,14 @@
((JBoss5DependencyPolicy) container.getDependencyPolicy()).addDependency(businessIntf);
}
+ /**
+ * @deprecated resolve until a bean name is acquired, do not depend on a business interface
+ */
+ @Deprecated
protected void addDependency(InjectionContainer container, String link, Class<?> businessIntf)
{
+ log.warn("EJBTHREE-1828: calling deprecated addDependency");
+
EJBContainer refCon = (EJBContainer) container.resolveEjbContainer(link, businessIntf);
// Do not depend on myself
Added: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/EJBInjectionContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/EJBInjectionContainer.java (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/EJBInjectionContainer.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -0,0 +1,41 @@
+/*
+ * 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.injection;
+
+/**
+ * A temporary measure to resolve EJB references until a new injection framework is in place.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface EJBInjectionContainer
+{
+ /**
+ * Although EJBInjectionContainer is implemented it may not be configured. If so,
+ * this will return false.
+ * @return whether resolveEJB can be called.
+ * @deprecated configuration will become mandatory on the next release
+ */
+ boolean canResolveEJB();
+
+ String resolveEJB(String link, Class<?> beanInterface, String mappedName);
+}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/EJBRemoteHandler.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/EJBRemoteHandler.java 2009-05-18 07:45:54 UTC (rev 88998)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/EJBRemoteHandler.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -31,7 +31,6 @@
import javax.ejb.EJBs;
import javax.naming.NameNotFoundException;
-import org.jboss.ejb3.EJBContainer;
import org.jboss.ejb3.annotation.IgnoreDependency;
import org.jboss.logging.Logger;
import org.jboss.metadata.javaee.spec.AbstractEJBReferenceMetaData;
@@ -126,6 +125,17 @@
if(mappedName != null && mappedName.length() == 0) mappedName = null;
if (refClass != null && (refClass.equals(Object.class) || refClass.equals(void.class))) refClass = null;
+ if(container instanceof EJBInjectionContainer)
+ {
+ if(((EJBInjectionContainer) container).canResolveEJB())
+ {
+ addJNDIDependency(container, ((EJBInjectionContainer) container).resolveEJB(link, refClass, null));
+ return;
+ }
+ else
+ log.warn("EJBTHREE-1828: EJBInjectionContainer " + container + " is unconfigured, using legacy resolve");
+ }
+
if(mappedName == null)
mappedName = getMappedName(encName, container);
@@ -161,6 +171,18 @@
if (mappedName != null && mappedName.trim().equals(""))
mappedName = null;
+ if(container instanceof EJBInjectionContainer)
+ {
+ if(((EJBInjectionContainer) container).canResolveEJB())
+ {
+ mappedName = ((EJBInjectionContainer) container).resolveEJB(link, refClass, null);
+ if(mappedName == null)
+ throw new IllegalStateException("unable to resolve " + link + " " + refClass);
+ }
+ else
+ log.warn("EJBTHREE-1828: EJBInjectionContainer " + container + " is unconfigured, using legacy resolve");
+ }
+
if(mappedName == null)
mappedName = getMappedName(encName, container, fieldName);
@@ -183,43 +205,6 @@
container.getEncInjectors().put(encName, injector);
}
- public static EJBContainer getEjbContainer(EJB ref, InjectionContainer container, Class<?> memberType)
- {
- EJBContainer rtn = null;
-
- if (ref.mappedName() != null && !"".equals(ref.mappedName()))
- {
- return null;
- }
-
- if (ref.beanName().equals("") && memberType == null)
- throw new RuntimeException("For deployment " + container.getIdentifier() + "not enough information for @EJB. Please fill out the beanName and/or businessInterface attributes");
-
- Class<?> businessInterface = memberType;
- if (!ref.beanInterface().getName().equals(Object.class.getName()))
- {
- businessInterface = ref.beanInterface();
- }
-
- if (ref.beanName().equals(""))
- {
- try
- {
- rtn = (EJBContainer) container.resolveEjbContainer(businessInterface);
- }
- catch (NameNotFoundException e)
- {
- log.warn("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ") " + e.getMessage());
- }
- }
- else
- {
- rtn = (EJBContainer) container.resolveEjbContainer(ref.beanName(), businessInterface);
- }
-
- return rtn;
- }
-
public static String getJndiName(EJB ref, InjectionContainer container, Class<?> memberType)
{
String jndiName;
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/InjectionContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/InjectionContainer.java 2009-05-18 07:45:54 UTC (rev 88998)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/InjectionContainer.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -66,8 +66,24 @@
Context getEnc();
+ /**
+ * @param link
+ * @param businessIntf
+ * @return
+ * @deprecated dependency resolving must not rely on runtime components
+ */
+ @Deprecated
Container resolveEjbContainer(String link, Class<?> businessIntf);
+
+ /**
+ * @param businessIntf
+ * @return
+ * @throws NameNotFoundException
+ * @deprecated dependency resolving must not rely on runtime components
+ */
+ @Deprecated
Container resolveEjbContainer(Class<?> businessIntf) throws NameNotFoundException;
+
String getEjbJndiName(Class<?> businessInterface) throws NameNotFoundException;
String getEjbJndiName(String link, Class<?> businessInterface);
Modified: projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-jboss-beans.xml
===================================================================
--- projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-jboss-beans.xml 2009-05-18 07:45:54 UTC (rev 88998)
+++ projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-jboss-beans.xml 2009-05-18 08:14:28 UTC (rev 88999)
@@ -330,12 +330,7 @@
class="org.jboss.ejb3.deployers.EjbMetadataJndiPolicyDecoratorDeployer" />
<!-- EJB Reference Resolver -->
- <bean name="org.jboss.ejb3.EjbReferenceResolver" class="org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver">
- <constructor factoryClass="org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolverFactory"
- factoryMethod="newInstance">
- <parameter>org.jboss.ejb3.common.resolvers.plugins.FirstMatchEjbReferenceResolver</parameter>
- </constructor>
- </bean>
+ <bean name="org.jboss.ejb3.EjbReferenceResolver" class="org.jboss.ejb3.core.resolvers.ScopedEJBReferenceResolver"/>
<!-- Add Annotation Plugins upon installation -->
<bean name="org.jboss.ejb3.AddAnnotationPluginOnBeanAnnotationAdaptorCallbackService"
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java 2009-05-18 07:45:54 UTC (rev 88998)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -36,16 +36,28 @@
import org.jboss.aop.AspectXmlLoader;
import org.jboss.aop.Domain;
import org.jboss.aop.DomainDefinition;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractDemandMetaData;
+import org.jboss.beans.metadata.spi.DemandMetaData;
+import org.jboss.beans.metadata.spi.SupplyMetaData;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.ClassLoaderFactory;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentUnit;
+import org.jboss.ejb3.DependencyPolicy;
import org.jboss.ejb3.DeploymentUnit;
import org.jboss.ejb3.Ejb3Deployment;
import org.jboss.ejb3.Ejb3Registry;
import org.jboss.ejb3.InitialContextFactory;
+import org.jboss.ejb3.MCDependencyPolicy;
+import org.jboss.ejb3.MCKernelAbstraction.AlreadyInstantiated;
import org.jboss.ejb3.cache.CacheFactoryRegistry;
import org.jboss.ejb3.cache.persistence.PersistenceManagerFactoryRegistry;
+import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
import org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar;
-import org.jboss.ejb3.common.registrar.spi.DuplicateBindException;
import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
import org.jboss.ejb3.common.registrar.spi.NotBoundException;
+import org.jboss.ejb3.core.resolvers.ScopedEJBReferenceResolver;
import org.jboss.ejb3.service.ServiceContainer;
import org.jboss.ejb3.session.SessionContainer;
import org.jboss.ejb3.stateful.StatefulContainer;
@@ -184,8 +196,9 @@
*
* @param beanImplementationClasses
* @return
+ * @throws DeploymentException
*/
- public static Collection<SessionContainer> deploySessionEjbs(Class<?>[] beanImplementationClasses)
+ public static Collection<SessionContainer> deploySessionEjbs(Class<?>... beanImplementationClasses) throws DeploymentException
{
// Initialize
Collection<SessionContainer> containers = new HashSet<SessionContainer>();
@@ -199,6 +212,22 @@
}
});
+ AbstractDeploymentUnit deploymentUnit = new AbstractDeploymentUnit(new AbstractDeploymentContext("test", ""));
+ deploymentUnit.createClassLoader(new ClassLoaderFactory() {
+ public ClassLoader createClassLoader(org.jboss.deployers.structure.spi.DeploymentUnit unit) throws Exception
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ public void removeClassLoader(org.jboss.deployers.structure.spi.DeploymentUnit unit) throws Exception
+ {
+ }
+ });
+ DeploymentUnit unit = new MockDeploymentUnit(deploymentUnit);
+ Ejb3Deployment deployment = new MockEjb3Deployment(unit, deploymentUnit);
+
+ deployment.setEJBReferenceResolver(new ScopedEJBReferenceResolver());
+
/*
* Create Metadata
*/
@@ -206,6 +235,8 @@
// Create metadata
JBossMetaData jbossMetaData = MetaDataHelper.getMetaDataFromBeanImplClasses(beanImplementationClasses);
+ unit.addAttachment(AttachmentNames.PROCESSED_METADATA, jbossMetaData);
+
// Iterate through each EJB
for (JBossEnterpriseBeanMetaData beanMetaData : jbossMetaData.getEnterpriseBeans())
{
@@ -240,9 +271,7 @@
? AbstractEJB3TestCase.DOMAIN_NAME_SLSB
: AbstractEJB3TestCase.DOMAIN_NAME_SFSB);
Hashtable<?, ?> ctxProperties = null;
- DeploymentUnit unit = new MockDeploymentUnit();
- Ejb3Deployment deployment = new MockEjb3Deployment(unit);
-
+
// Is SFSB, manually set a PM Factory Registry and Cache Factory
//TODO C'mon, here? Much better elsewhere.
if (sessionType.equals(ContainerType.SFSB))
@@ -277,8 +306,9 @@
*
* @param beanImplementationClass
* @return
+ * @throws DeploymentException
*/
- public static SessionContainer deploySessionEjb(Class<?> beanImplementationClass)
+ public static SessionContainer deploySessionEjb(Class<?> beanImplementationClass) throws DeploymentException
{
Collection<SessionContainer> containers = deploySessionEjbs(new Class<?>[]
{beanImplementationClass});
@@ -287,6 +317,48 @@
return containers.iterator().next();
}
+ private static void install(String name, Object service, DependencyPolicy dependencies) throws Exception
+ {
+ AbstractBeanMetaData bean = new AbstractBeanMetaData(name, service.getClass().getName());
+ bean.setConstructor(new AlreadyInstantiated(service));
+ MCDependencyPolicy policy = (MCDependencyPolicy) dependencies;
+ bean.setDepends(policy.getDependencies());
+ bean.setDemands(policy.getDemands());
+ bean.setSupplies(policy.getSupplies());
+ log.info("installing bean: " + name);
+ log.info(" with dependencies:");
+ for (Object obj : policy.getDependencies())
+ {
+ Object msgObject = obj;
+ if (obj instanceof AbstractDemandMetaData)
+ {
+ msgObject = ((AbstractDemandMetaData)obj).getDemand();
+ }
+ log.info("\t" + msgObject);
+ }
+ log.info(" and demands:");
+ for(DemandMetaData dmd : policy.getDemands())
+ {
+ log.info("\t" + dmd.getDemand());
+ }
+ log.info(" and supplies:");
+ for(SupplyMetaData smd : policy.getSupplies())
+ {
+ log.info("\t" + smd.getSupply());
+ }
+ try
+ {
+ bootstrap.getKernel().getController().install(bean);
+ }
+ catch(Throwable t)
+ {
+ if(t instanceof Error)
+ throw (Error) t;
+ if(t instanceof RuntimeException)
+ throw (RuntimeException) t;
+ throw (Exception) t;
+ }
+ }
/**
* Instanciates the appropriate SessionContainer based on the specified arguments and returns it
*
@@ -362,8 +434,9 @@
*
* @param beanImplementationClass
* @return
+ * @throws DeploymentException
*/
- private static SessionContainer registerContainer(SessionContainer container)
+ private static SessionContainer registerContainer(SessionContainer container) throws DeploymentException
{
//FIXME
// Typically these steps are done by Ejb3Deployment
@@ -378,19 +451,11 @@
String containerName = container.getObjectName().getCanonicalName();
try
{
- Ejb3RegistrarLocator.locateRegistrar().bind(containerName, container);
+ install(containerName, container, container.getDependencyPolicy());
}
- catch (DuplicateBindException dbe)
+ catch(Exception e)
{
- try
- {
- container.stop();
- }
- catch (Exception e)
- {
- // Ignore
- }
- throw new RuntimeException("Object Store already has binding under " + containerName, dbe);
+ throw new DeploymentException(e);
}
// make sure we're installed
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/MockEjb3Deployment.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/MockEjb3Deployment.java 2009-05-18 07:45:54 UTC (rev 88998)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/MockEjb3Deployment.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -25,6 +25,7 @@
import javax.security.jacc.PolicyConfiguration;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext;
import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentUnit;
import org.jboss.ejb3.DependencyPolicy;
import org.jboss.ejb3.DeploymentScope;
@@ -56,7 +57,7 @@
{
// TODO This should be replaced w/ a MockDeploymentUnit when completed,
// to support nested deployments, @see ejb3-test MockDeploymentUnit
- this(unit, new AbstractDeploymentUnit());
+ this(unit, new AbstractDeploymentUnit(new AbstractDeploymentContext("test", "")));
}
public MockEjb3Deployment(DeploymentUnit unit, org.jboss.deployers.structure.spi.DeploymentUnit du)
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/FirstStateless.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/FirstStateless.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/FirstStateless.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -0,0 +1,31 @@
+/*
+ * 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.core.test.ejbthree1828;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface FirstStateless
+{
+ int mult(int a, int b);
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/FirstStatelessBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/FirstStatelessBean.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/FirstStatelessBean.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -0,0 +1,44 @@
+/*
+ * 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.core.test.ejbthree1828;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+public class FirstStatelessBean implements FirstStateless
+{
+ @EJB
+ private SecondStateless bean;
+
+ public int mult(int a, int b)
+ {
+ int r = 0;
+ while((b--) > 0)
+ r = bean.add(r, a);
+ return r;
+ }
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/SecondStateless.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/SecondStateless.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/SecondStateless.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -0,0 +1,31 @@
+/*
+ * 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.core.test.ejbthree1828;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface SecondStateless
+{
+ int add(int a, int b);
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/SecondStatelessBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/SecondStatelessBean.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/SecondStatelessBean.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -0,0 +1,38 @@
+/*
+ * 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.core.test.ejbthree1828;
+
+import javax.ejb.Stateless;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+public class SecondStatelessBean implements SecondStateless
+{
+ public int add(int a, int b)
+ {
+ return a + b;
+ }
+
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/unit/EjbReferenceTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/unit/EjbReferenceTestCase.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1828/unit/EjbReferenceTestCase.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -0,0 +1,56 @@
+/*
+ * 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.core.test.ejbthree1828.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.naming.NamingException;
+
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.core.test.ejbthree1828.FirstStateless;
+import org.jboss.ejb3.core.test.ejbthree1828.FirstStatelessBean;
+import org.jboss.ejb3.core.test.ejbthree1828.SecondStatelessBean;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class EjbReferenceTestCase extends AbstractEJB3TestCase
+{
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ AbstractEJB3TestCase.beforeClass();
+
+ deploySessionEjbs(FirstStatelessBean.class, SecondStatelessBean.class);
+ }
+
+ @Test
+ public void test1() throws NamingException
+ {
+ FirstStateless bean = lookup("FirstStatelessBean/local", FirstStateless.class);
+ int actual = bean.mult(13, 17);
+ assertEquals(221, actual);
+ }
+}
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/cachepassivation/MockDeploymentUnit.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/cachepassivation/MockDeploymentUnit.java 2009-05-18 07:45:54 UTC (rev 88998)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/cachepassivation/MockDeploymentUnit.java 2009-05-18 08:14:28 UTC (rev 88999)
@@ -41,18 +41,32 @@
*/
public class MockDeploymentUnit implements DeploymentUnit
{
+ private org.jboss.deployers.structure.spi.DeploymentUnit deploymentUnit;
+ /**
+ * @deprecated supply a deploymentUnit
+ */
+ public MockDeploymentUnit()
+ {
+ // TODO Auto-generated constructor stub
+ }
+
+ public MockDeploymentUnit(org.jboss.deployers.structure.spi.DeploymentUnit deploymentUnit)
+ {
+ this.deploymentUnit = deploymentUnit;
+ }
+
public Object addAttachment(String name, Object attachment)
{
- return null;
+ return deploymentUnit.addAttachment(name, attachment);
}
public Object getAttachment(String name)
{
- return null;
+ return deploymentUnit.getAttachment(name);
}
public Object removeAttachment(String name)
{
- return null;
+ return deploymentUnit.removeAttachment(name);
}
/* (non-Javadoc)
Modified: projects/ejb3/trunk/core/src/test/resources/container-beans.xml
===================================================================
--- projects/ejb3/trunk/core/src/test/resources/container-beans.xml 2009-05-18 07:45:54 UTC (rev 88998)
+++ projects/ejb3/trunk/core/src/test/resources/container-beans.xml 2009-05-18 08:14:28 UTC (rev 88999)
@@ -8,4 +8,6 @@
<bean name="MockConnectionManager" class="org.jboss.ejb3.core.test.common.MockCachedConnectionManager">
</bean>
+
+ <bean name="JNDIKernelRegistryPlugin" class="org.jboss.ejb3.kernel.JNDIKernelRegistryPlugin"/>
</deployment>
More information about the jboss-cvs-commits
mailing list