[jboss-cvs] JBossAS SVN: r82106 - in projects/ejb3/trunk: common and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Dec 8 04:25:17 EST 2008
Author: ALRubinger
Date: 2008-12-08 04:25:17 -0500 (Mon, 08 Dec 2008)
New Revision: 82106
Added:
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/plugins/
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/plugins/FirstMatchEjbReferenceResolver.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReference.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolver.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverFactory.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/NonDeterministicInterfaceException.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/UnresolvableReferenceException.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Bean.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Local.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalBusiness.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalHome.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Remote.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteBusiness.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteHome.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2Bean.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2LocalBusiness.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/NestedChildBean.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/NestedChildLocalBusiness.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/ParentBean.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/ParentLocalBusiness.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCase.java
Modified:
projects/ejb3/trunk/build/pom.xml
projects/ejb3/trunk/common/pom.xml
Log:
[EJBTHREE-1616] Flesh out SPI, Factory, and a simplified impl for EJB Reference resolution. Tests need more coverage.
Modified: projects/ejb3/trunk/build/pom.xml
===================================================================
--- projects/ejb3/trunk/build/pom.xml 2008-12-08 07:52:32 UTC (rev 82105)
+++ projects/ejb3/trunk/build/pom.xml 2008-12-08 09:25:17 UTC (rev 82106)
@@ -446,6 +446,12 @@
<artifactId>jboss-deployers-core-spi</artifactId>
<version>${version.org.jboss.deployers}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-spi</artifactId>
+ <version>${version.org.jboss.deployers}</version>
+ </dependency>
<dependency>
<groupId>org.jboss.ws</groupId>
Modified: projects/ejb3/trunk/common/pom.xml
===================================================================
--- projects/ejb3/trunk/common/pom.xml 2008-12-08 07:52:32 UTC (rev 82105)
+++ projects/ejb3/trunk/common/pom.xml 2008-12-08 09:25:17 UTC (rev 82106)
@@ -90,6 +90,11 @@
<groupId>org.jboss.metadata</groupId>
<artifactId>jboss-metadata</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-spi</artifactId>
+ </dependency>
</dependencies>
</project>
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/plugins/FirstMatchEjbReferenceResolver.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/plugins/FirstMatchEjbReferenceResolver.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/plugins/FirstMatchEjbReferenceResolver.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,141 @@
+/*
+ * 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.ejb3.common.resolvers.plugins;
+
+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;
+
+/**
+ * FirstMatchEjbReferenceResolver
+ *
+ * An EJB Reference resolver which will return the first match
+ * found. In cases where the reference may be non-deterministic
+ * this implementation will stop when the reference requirements
+ * are satisfied
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class FirstMatchEjbReferenceResolver extends EjbReferenceResolverBase implements EjbReferenceResolver
+{
+
+ // --------------------------------------------------------------------------------||
+ // Required Implementations -------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.resolver.EjbReferenceResolver#resolveEjb(org.jboss.deployers.structure.spi.DeploymentUnit, org.jboss.ejb3.resolver.EjbReference)
+ */
+ public String resolveEjb(DeploymentUnit du, EjbReference reference)
+ {
+ // Initialize
+ String jndiName = null;
+
+ // Resolve from the root deployment
+ DeploymentUnit root = this.getRoot(du);
+ jndiName = this.resolveEjbFromRoot(root, reference);
+
+ // Check that we could resolve
+ if(jndiName==null)
+ {
+ throw new UnresolvableReferenceException("Could not resolve reference " + reference + " for "
+ + DeploymentUnit.class.getSimpleName() + " " + du);
+ }
+
+ // Return
+ return jndiName;
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Helper Methods -----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the root deployment unit
+ *
+ * @param du
+ * @return
+ */
+ protected DeploymentUnit getRoot(DeploymentUnit du)
+ {
+ // Recurse until we hit the root
+ return du.getParent() == null ? du : this.getRoot(du.getParent());
+ }
+
+ /**
+ * Follows a preorder traversal scheme to resolve the specified reference from the
+ * specified metadata (or its children). Returns the resolved target JNDI name.
+ *
+ * @param rootDu
+ * @param reference
+ * @return
+ */
+ protected String resolveEjbFromRoot(DeploymentUnit rootDu, EjbReference reference)
+ {
+ // Initialize
+ String jndiName = null;
+
+ // Obtain the metadata for this DU
+ JBossMetaData metadata = this.getMetaData(rootDu);
+
+ // Ensure metadata's specified for this DU
+ if (metadata != null)
+ {
+ // Look for a match within this metadata
+ jndiName = this.getMatch(reference, metadata);
+ }
+
+ // If we haven't found the JNDI name in this DU
+ if (jndiName == null)
+ {
+ // Look to the children
+ List<DeploymentUnit> children = rootDu.getChildren();
+
+ // If we've got child deployments
+ if (children != null)
+ {
+ // Loop through them
+ for (DeploymentUnit child : children)
+ {
+ // Try to get the resolved JNDI name from the child
+ jndiName = this.resolveEjbFromRoot(child, reference);
+
+ // If found
+ if (jndiName != null)
+ {
+ // Break out
+ break;
+ }
+ }
+ }
+ }
+
+ // Return the JNDI Name
+ return jndiName;
+ }
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReference.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReference.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReference.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,142 @@
+/*
+ * 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.ejb3.common.resolvers.spi;
+
+import java.io.Serializable;
+
+/**
+ * EjbReference
+ *
+ * Models an EJB reference denoted by either javax.ejb.EJB or
+ * its XML equivalent
+ *
+ * Encapsulates descriptions required to resolve an @EJB reference
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class EjbReference implements Serializable
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final long serialVersionUID = 1L;
+
+ // --------------------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * The name of the target EJB
+ */
+ private String beanName;
+
+ /**
+ * The fully-qualified name of the target interface (EJB 3.x Business or EJB 2.x Home)
+ */
+ private String beanInterface;
+
+ /**
+ * The mapped-name used for the target
+ */
+ private String mappedName;
+
+ // --------------------------------------------------------------------------------||
+ // Constructors -------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Sole Constructor
+ */
+ public EjbReference(String beanName, String interfaceFqn, String mappedName)
+ {
+ // Ensure at least one of the requisite properties is specified
+ assert (beanName != null && beanName.trim().length() > 0)
+ || (interfaceFqn != null && interfaceFqn.trim().length() > 0)
+ || (mappedName != null && mappedName.trim().length() > 0) : "At least one of beanName, mappedName, or interfaceFqn must be specified";
+
+ // Set properties
+ this.setBeanName(beanName);
+ this.setBeanInterface(interfaceFqn);
+ this.setMappedName(mappedName);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Accessors / Mutators -----------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public String getBeanName()
+ {
+ return beanName;
+ }
+
+ protected void setBeanName(String beanName)
+ {
+ this.beanName = beanName;
+ }
+
+ public String getBeanInterface()
+ {
+ return beanInterface;
+ }
+
+ protected void setBeanInterface(String beanInterface)
+ {
+ this.beanInterface = beanInterface;
+ }
+
+ public String getMappedName()
+ {
+ return mappedName;
+ }
+
+ protected void setMappedName(String mappedName)
+ {
+ this.mappedName = mappedName;
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Overridden Implementations -----------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ @Override
+ public String toString()
+ {
+ // Initialize
+ StringBuffer buffer = new StringBuffer();
+
+ // Construct
+ buffer.append("[EJB Reference: beanInterface '");
+ buffer.append(this.getBeanInterface());
+ buffer.append("', beanName '");
+ buffer.append(this.getBeanName());
+ buffer.append("', mappedName '");
+ buffer.append(this.getMappedName());
+ buffer.append("']");
+
+ // Return
+ return buffer.toString();
+ }
+
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolver.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolver.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolver.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,50 @@
+/*
+ * 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.ejb3.common.resolvers.spi;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * EjbReferenceResolver
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface EjbReferenceResolver
+{
+
+ // --------------------------------------------------------------------------------||
+ // Contracts ----------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Returns the JNDI Name of the proxy described by the specified
+ * arguments.
+ *
+ * @param du The DeploymentUnit in question
+ * @param reference The EJB reference used
+ * @throws UnresolvableReferenceException If the reference cannot be resolved within scope
+ * @return
+ */
+ String resolveEjb(DeploymentUnit du, EjbReference reference) throws UnresolvableReferenceException;
+
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,235 @@
+/*
+ * 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.ejb3.common.resolvers.spi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
+import org.jboss.logging.Logger;
+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.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.jboss.jndipolicy.spi.JbossSessionBeanJndiNameResolver;
+import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
+import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
+
+/**
+ * EjbReferenceResolverBase
+ *
+ * A base upon which EJB Reference Resolvers
+ * may build upon. Provides capabilities expected
+ * to be required by providers.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class EjbReferenceResolverBase
+{
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(EjbReferenceResolverBase.class);
+
+ /**
+ * The attachment name of the metadata within the DU
+ */
+ public static final String DU_ATTACHMENT_NAME_METADATA = AttachmentNames.PROCESSED_METADATA;
+
+ // --------------------------------------------------------------------------------||
+ // Functional Methods -------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the metadata attachment from the specified deployment unit, returning
+ * null if not present
+ *
+ * @param du
+ * @return
+ */
+ protected JBossMetaData getMetaData(DeploymentUnit du)
+ {
+ return du.getAttachment(EjbReferenceResolverBase.DU_ATTACHMENT_NAME_METADATA, JBossMetaData.class);
+ }
+
+ /**
+ * Returns the session bean within the specified metadata to match the specified reference,
+ * otherwise returns null.
+ *
+ * @param reference
+ * @param metadata
+ * @return
+ */
+ protected String getMatch(EjbReference reference, JBossMetaData metadata) throws NonDeterministicInterfaceException
+ {
+
+ // Initialize
+ log.debug("Resolving reference for " + reference + " in " + metadata);
+ Collection<JBossSessionBeanMetaData> matches = new ArrayList<JBossSessionBeanMetaData>();
+
+ // Get all Enterprise Beans contained in the metadata
+ JBossEnterpriseBeansMetaData beans = metadata.getEnterpriseBeans();
+
+ // Loop through all EJBs
+ for (JBossEnterpriseBeanMetaData bean : beans)
+ {
+ // We only can inject Session Beans (Entity and MD are not targets)
+ if (!bean.isSession())
+ {
+ continue;
+ }
+
+ // Cast our Session Bean
+ JBossSessionBeanMetaData smd = (JBossSessionBeanMetaData) bean;
+
+ // See if this is a match
+ if (this.isMatch(reference, smd))
+ {
+ // Add to the matches found
+ matches.add(smd);
+ log.debug("Found match in EJB " + smd.getEjbName() + " for " + reference);
+ continue;
+ }
+ }
+
+ // Ensure we've only got one match
+ if (matches.size() > 1)
+ {
+ // If more than one match was found while EJB name was specified, there's a problem in resolution
+ String beanName = reference.getBeanName();
+ assert beanName == null || beanName.trim().length() == 0 : "Error in resolution logic, more than one eligible EJB "
+ + "was found to satisfy beanInterface "
+ + this.getBeanInterfaceName(reference)
+ + ", but EJB Name was explicitly-specified.";
+
+ // Report error
+ throw new NonDeterministicInterfaceException("Specified reference " + reference
+ + " was matched by more than one EJB: " + matches
+ + ". Specify beanName explciitly or ensure beanInterface is unique.");
+ }
+
+ // Return the JNDI name of the matching metadata if present, otherwise null
+ return matches.size() > 0 ? this.getJndiName(reference, matches.iterator().next()) : null;
+
+ }
+
+ /**
+ * Determines whether the specified session bean is a match for the specified
+ * reference
+ *
+ * @param reference
+ * @param md
+ * @return
+ */
+ protected boolean isMatch(EjbReference reference, JBossSessionBeanMetaData md)
+ {
+ // Initialize
+ Set<String> interfaces = new HashSet<String>();
+
+ // Add all eligible bean interfaces
+ BusinessLocalsMetaData businessLocals = md.getBusinessLocals();
+ BusinessRemotesMetaData businessRemotes = md.getBusinessRemotes();
+ String home = md.getHome();
+ String localHome = md.getLocalHome();
+ if (businessLocals != null)
+ {
+ interfaces.addAll(businessLocals);
+ }
+ if (businessRemotes != null)
+ {
+ interfaces.addAll(businessRemotes);
+ }
+ if (home != null && home.trim().length() > 0)
+ {
+ interfaces.add(home);
+ }
+ if (localHome != null && localHome.trim().length() > 0)
+ {
+ interfaces.add(localHome);
+ }
+
+ // Get the requested bean interface
+ String requestedInterface = reference.getBeanInterface();
+ assert requestedInterface != null && requestedInterface.trim().length() > 0 : "beanInterface must be specified";
+
+ // Does this EJB have the requested interface?
+ if (interfaces.contains(requestedInterface))
+ {
+ // Get the requested EJB name
+ String ejbName = reference.getBeanName();
+
+ // If the EJB name is explicitly-provided
+ if (ejbName != null && ejbName.trim().length() > 0)
+ {
+ // Ensure the EJB name matches this EJB
+ if (!ejbName.equals(md.getEjbName()))
+ {
+ return false;
+ }
+ }
+
+ // We've got a match
+ return true;
+ }
+
+ // No preconditions met, return false
+ return false;
+ }
+
+ /**
+ * Obtains the resolved JNDI target for the specified reference
+ * within the specified metadata
+ *
+ * @param reference
+ * @param metadata
+ * @return
+ */
+ protected String getJndiName(EjbReference reference, JBossSessionBeanMetaData metadata)
+ {
+ String interfaceName = this.getBeanInterfaceName(reference);
+ return JbossSessionBeanJndiNameResolver.resolveJndiName(metadata, interfaceName);
+ }
+
+ /**
+ * Returns the bean interface described by the specified
+ * reference, validating its presence along the way
+ *
+ * @param reference
+ * @return
+ */
+ private String getBeanInterfaceName(EjbReference reference)
+ {
+ // Get the bean interface
+ String interfaceName = reference.getBeanInterface();
+ assert interfaceName != null && interfaceName.trim().length() > 0 : "beanInterface must be specified";
+
+ // Return
+ return interfaceName;
+
+ }
+
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverFactory.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverFactory.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverFactory.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,76 @@
+/*
+ * 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.ejb3.common.resolvers.spi;
+
+/**
+ * EjbReferenceResolverFactory
+ *
+ * Factory allowing abstraction of EjbReferenceResolver instances
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version : $
+ */
+public class EjbReferenceResolverFactory
+{
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Prohibits instanciation
+ */
+ private EjbReferenceResolverFactory()
+ {
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Factory Members ----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Returns a new EjbReferenceResolver using the specified implementation
+ *
+ * @param implementationClassName
+ * @return
+ */
+ public static EjbReferenceResolver newInstance(String implementationClassName)
+ {
+ try
+ {
+ // Get the class from the defining ClassLoader of this class
+ Class<?> implClass = Class.forName(implementationClassName);
+
+ // Ensure we've got a type match
+ assert implClass.equals(EjbReferenceResolver.class) : "Specified implementation " + implementationClassName
+ + " is not a valid " + EjbReferenceResolver.class.getName();
+
+ // Make a new instance, cast and return it
+ return (EjbReferenceResolver) implClass.newInstance();
+
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException("Could not create new " + EjbReferenceResolver.class.getSimpleName()
+ + " with implementation of " + implementationClassName, t);
+ }
+ }
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/NonDeterministicInterfaceException.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/NonDeterministicInterfaceException.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/NonDeterministicInterfaceException.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,79 @@
+/*
+ * 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.ejb3.common.resolvers.spi;
+
+/**
+ * NonDeterministicInterfaceException
+ *
+ * Signifies that a beanInterface supplied for EJB
+ * reference resolution was not unique within the defined
+ * context
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class NonDeterministicInterfaceException extends RuntimeException
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final long serialVersionUID = 1L;
+
+ // --------------------------------------------------------------------------------||
+ // Constructors -------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ *
+ */
+ public NonDeterministicInterfaceException()
+ {
+ }
+
+ /**
+ * @param message
+ */
+ public NonDeterministicInterfaceException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public NonDeterministicInterfaceException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public NonDeterministicInterfaceException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/UnresolvableReferenceException.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/UnresolvableReferenceException.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/UnresolvableReferenceException.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,78 @@
+/*
+ * 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.ejb3.common.resolvers.spi;
+
+/**
+ * UnresolvableReferenceException
+ *
+ * Thrown when a reference is not resolvable to a target
+ * JNDI Name for a given deployment
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class UnresolvableReferenceException extends RuntimeException
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final long serialVersionUID = 1L;
+
+ // --------------------------------------------------------------------------------||
+ // Constructors -------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ *
+ */
+ public UnresolvableReferenceException()
+ {
+ }
+
+ /**
+ * @param message
+ */
+ public UnresolvableReferenceException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public UnresolvableReferenceException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public UnresolvableReferenceException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+}
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Bean.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Bean.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Bean.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,44 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+import javax.ejb.Local;
+import javax.ejb.LocalHome;
+import javax.ejb.Remote;
+import javax.ejb.RemoteHome;
+import javax.ejb.Stateless;
+
+/**
+ * Child1Bean
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local(Child1LocalBusiness.class)
+ at Remote(Child1RemoteBusiness.class)
+ at LocalHome(Child1LocalHome.class)
+ at RemoteHome(Child1RemoteHome.class)
+public class Child1Bean
+{
+
+}
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Local.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Local.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Local.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,35 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+import javax.ejb.EJBLocalObject;
+
+/**
+ * Child1Local
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Child1Local extends EJBLocalObject
+{
+
+}
\ No newline at end of file
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalBusiness.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalBusiness.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,33 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+/**
+ * Child1LocalBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Child1LocalBusiness
+{
+
+}
\ No newline at end of file
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalHome.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalHome.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalHome.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,36 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBLocalHome;
+
+/**
+ * Child1LocalHome
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Child1LocalHome extends EJBLocalHome
+{
+ Child1Local create() throws CreateException;
+}
\ No newline at end of file
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Remote.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Remote.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1Remote.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,35 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+import javax.ejb.EJBObject;
+
+/**
+ * Child1Remote
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Child1Remote extends EJBObject
+{
+
+}
\ No newline at end of file
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteBusiness.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteBusiness.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,33 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+/**
+ * Child1RemoteBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Child1RemoteBusiness
+{
+
+}
\ No newline at end of file
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteHome.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteHome.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteHome.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,38 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBHome;
+
+/**
+ * Child1RemoteHome
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Child1RemoteHome extends EJBHome
+{
+ Child1Remote create() throws CreateException, RemoteException;
+}
\ No newline at end of file
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2Bean.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2Bean.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2Bean.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,38 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * Child2Bean
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local(Child2LocalBusiness.class)
+public class Child2Bean
+{
+
+}
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2LocalBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2LocalBusiness.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2LocalBusiness.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,33 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+/**
+ * Child2LocalBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Child2LocalBusiness
+{
+
+}
\ No newline at end of file
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/NestedChildBean.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/NestedChildBean.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/NestedChildBean.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,38 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * NestedChildBean
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local(NestedChildLocalBusiness.class)
+public class NestedChildBean
+{
+
+}
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/NestedChildLocalBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/NestedChildLocalBusiness.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/NestedChildLocalBusiness.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,33 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+/**
+ * NestedChildLocalBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface NestedChildLocalBusiness
+{
+
+}
\ No newline at end of file
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/ParentBean.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/ParentBean.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/ParentBean.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,38 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * ParentBean
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local(ParentLocalBusiness.class)
+public class ParentBean
+{
+
+}
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/ParentLocalBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/ParentLocalBusiness.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/ParentLocalBusiness.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,33 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+/**
+ * ParentLocalBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface ParentLocalBusiness
+{
+
+}
\ No newline at end of file
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCase.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCase.java 2008-12-08 09:25:17 UTC (rev 82106)
@@ -0,0 +1,433 @@
+/*
+ * 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.
+ */
+/*
+ * 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.ejb3.test.common.resolvers.unit;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentUnit;
+import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
+import org.jboss.ejb3.common.metadata.MetadataUtil;
+import org.jboss.ejb3.common.resolvers.plugins.FirstMatchEjbReferenceResolver;
+import org.jboss.ejb3.common.resolvers.spi.EjbReference;
+import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
+import org.jboss.ejb3.test.common.resolvers.Child1Bean;
+import org.jboss.ejb3.test.common.resolvers.Child1LocalBusiness;
+import org.jboss.ejb3.test.common.resolvers.Child1LocalHome;
+import org.jboss.ejb3.test.common.resolvers.Child1RemoteBusiness;
+import org.jboss.ejb3.test.common.resolvers.Child1RemoteHome;
+import org.jboss.ejb3.test.common.resolvers.Child2Bean;
+import org.jboss.ejb3.test.common.resolvers.Child2LocalBusiness;
+import org.jboss.ejb3.test.common.resolvers.NestedChildBean;
+import org.jboss.ejb3.test.common.resolvers.NestedChildLocalBusiness;
+import org.jboss.ejb3.test.common.resolvers.ParentBean;
+import org.jboss.ejb3.test.common.resolvers.ParentLocalBusiness;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.annotation.creator.ejb.jboss.JBoss50Creator;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * EjbReferenceResolverUnitTestCase
+ *
+ * Test Cases to validate the pluggable EjbReferenceResolver
+ *
+ * Uses DUs with the following structure:
+ *
+ * Parent
+ * |
+ * |------ Child1
+ * | |
+ * | |------NestedChild
+ * |
+ * |------ Child2
+ *
+ * ...where each DU has an EJB w/ Local Business interface.
+ * "Child1" has bean interfaces for
+ * local business, remote business, home, and local home.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class EjbReferenceResolverUnitTestCase
+{
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(EjbReferenceResolverUnitTestCase.class);
+
+ private static MockDeploymentUnit parentDu;
+
+ private static MockDeploymentUnit child1Du;
+
+ private static MockDeploymentUnit child2Du;
+
+ private static MockDeploymentUnit nestedChildDu;
+
+ private static EjbReferenceResolver resolver;
+
+ // --------------------------------------------------------------------------------||
+ // Lifecycle Methods --------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the DeploymentUnit relationships are as expected for this
+ * test. In place to validate that the test setup is correct
+ */
+ @Test
+ public void testDeploymentUnitRelationships() throws Throwable
+ {
+ // Parent should have 2 children
+ TestCase.assertEquals("Parent DU does not have expected number of children", 2, parentDu.getChildren().size());
+
+ // Children should have parent of parentDU
+ TestCase.assertEquals("Child1 DU should have parent of Parent DU", parentDu, child1Du.getParent());
+ TestCase.assertEquals("Child2 DU should have parent of Parent DU", parentDu, child2Du.getParent());
+
+ // Tests for no children
+ TestCase.assertTrue("Child2 DU should have no children", child2Du.getChildren() == null
+ || child2Du.getChildren().size() == 0);
+ TestCase.assertTrue("NestedChild DU should have no children", nestedChildDu.getChildren() == null
+ || nestedChildDu.getChildren().size() == 0);
+
+ // Parent should have one child (Nested Child)
+ TestCase.assertEquals("Child1 DU should have 1 child", 1, child1Du.getChildren().size());
+ TestCase.assertEquals("Child1 DU should have child of Nested Child", nestedChildDu, child1Du.getChildren()
+ .iterator().next());
+
+ // Nested Child should have parent of Child 1
+ TestCase.assertEquals("Nested Child DU should have parent of Child1 DU", child1Du, nestedChildDu.getParent());
+ }
+
+ /**
+ * Ensures that the parent can resolve itself and children by bean
+ * interface alone (business and homes)
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testParentCanResolveItselfAndChildrenByBeanInterface() throws Throwable
+ {
+ // Initialize
+ String parentBeanInterfaceName = ParentLocalBusiness.class.getName();
+ String child1LocalBusinessBeanInterfaceName = Child1LocalBusiness.class.getName();
+ String child1RemoteBusinessBeanInterfaceName = Child1RemoteBusiness.class.getName();
+ String child1LocalHomeBeanInterfaceName = Child1LocalHome.class.getName();
+ String child1RemoteHomeBeanInterfaceName = Child1RemoteHome.class.getName();
+ String child2BeanInterfaceName = Child2LocalBusiness.class.getName();
+ String nestedChildBeanInterfaceName = NestedChildLocalBusiness.class.getName();
+
+ // Create references
+ EjbReference parentReference = new EjbReference(null, parentBeanInterfaceName, null);
+ EjbReference child1LocalBusinessReference = new EjbReference(null, child1LocalBusinessBeanInterfaceName, null);
+ EjbReference child1RemoteBusinessReference = new EjbReference(null, child1RemoteBusinessBeanInterfaceName, null);
+ EjbReference child1LocalHomeReference = new EjbReference(null, child1LocalHomeBeanInterfaceName, null);
+ EjbReference child1RemoteHomeReference = new EjbReference(null, child1RemoteHomeBeanInterfaceName, null);
+ EjbReference child2Reference = new EjbReference(null, child2BeanInterfaceName, null);
+ EjbReference nestedChildReference = new EjbReference(null, nestedChildBeanInterfaceName, null);
+
+ // Resolve
+ DeploymentUnit fromDu = parentDu;
+ String jndiNameParentLocalBusiness = resolver.resolveEjb(fromDu, parentReference);
+ String jndiNameChild1LocalBusiness = resolver.resolveEjb(fromDu, child1LocalBusinessReference);
+ log.debug("Resolved " + child1LocalBusinessReference + " from " + fromDu + " to " + jndiNameChild1LocalBusiness);
+ String jndiNameChild1RemoteBusiness = resolver.resolveEjb(fromDu, child1RemoteBusinessReference);
+ log
+ .debug("Resolved " + child1RemoteBusinessReference + " from " + fromDu + " to "
+ + jndiNameChild1RemoteBusiness);
+ String jndiNameChild1LocalHome = resolver.resolveEjb(fromDu, child1LocalHomeReference);
+ log.debug("Resolved " + child1LocalHomeReference + " from " + fromDu + " to " + jndiNameChild1LocalHome);
+ String jndiNameChild1RemoteHome = resolver.resolveEjb(fromDu, child1RemoteHomeReference);
+ log.debug("Resolved " + child1RemoteHomeReference + " from " + fromDu + " to " + jndiNameChild1RemoteHome);
+ String jndiNameChild2 = resolver.resolveEjb(fromDu, child2Reference);
+ log.debug("Resolved " + child2Reference + " from " + fromDu + " to " + jndiNameChild2);
+ String jndiNameNestedChild = resolver.resolveEjb(fromDu, nestedChildReference);
+ log.debug("Resolved " + nestedChildReference + " from " + fromDu + " to " + jndiNameNestedChild);
+
+ // Declare expected
+ String expectedParent = ParentBean.class.getSimpleName() + "/local-" + parentBeanInterfaceName;
+ String child1EjbName = Child1Bean.class.getSimpleName();
+ String expectedChild1LocalBusiness = child1EjbName + "/local-" + child1LocalBusinessBeanInterfaceName;
+ String expectedChild1RemoteBusiness = child1EjbName + "/remote-" + child1RemoteBusinessBeanInterfaceName;
+ String expectedChild1LocalHome = child1EjbName + "/localHome";
+ String expectedChild1RemoteHome = child1EjbName + "/home";
+ String expectedChild2 = Child2Bean.class.getSimpleName() + "/local-" + child2BeanInterfaceName;
+ String expectedNestedChild = NestedChildBean.class.getSimpleName() + "/local-" + nestedChildBeanInterfaceName;
+
+ // Test
+ TestCase.assertEquals(expectedParent, jndiNameParentLocalBusiness);
+ TestCase.assertEquals(expectedChild1LocalBusiness, jndiNameChild1LocalBusiness);
+ TestCase.assertEquals(expectedChild1RemoteBusiness, jndiNameChild1RemoteBusiness);
+ TestCase.assertEquals(expectedChild1LocalHome, jndiNameChild1LocalHome);
+ TestCase.assertEquals(expectedChild1RemoteHome, jndiNameChild1RemoteHome);
+ TestCase.assertEquals(expectedChild2, jndiNameChild2);
+ TestCase.assertEquals(expectedNestedChild, jndiNameNestedChild);
+ }
+
+ /**
+ * Ensures that a child can resolve a parent by bean interface
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testChildCanResolveParentByBeanInterface() throws Throwable
+ {
+ /*
+ * In this case, "child1" is the parent of "nestedChild", so we refer to
+ * it as "parent"
+ */
+
+ // Initialize
+ String parentLocalBusinessBeanInterfaceName = Child1LocalBusiness.class.getName();
+ String parentRemoteBusinessBeanInterfaceName = Child1RemoteBusiness.class.getName();
+ String parentLocalHomeBeanInterfaceName = Child1LocalHome.class.getName();
+ String parentRemoteHomeBeanInterfaceName = Child1RemoteHome.class.getName();
+
+ // Create references
+ EjbReference parentLocalBusinessReference = new EjbReference(null, parentLocalBusinessBeanInterfaceName, null);
+ EjbReference parentRemoteBusinessReference = new EjbReference(null, parentRemoteBusinessBeanInterfaceName, null);
+ EjbReference parentLocalHomeReference = new EjbReference(null, parentLocalHomeBeanInterfaceName, null);
+ EjbReference parentRemoteHomeReference = new EjbReference(null, parentRemoteHomeBeanInterfaceName, null);
+
+ // Resolve
+ DeploymentUnit fromDu = nestedChildDu;
+ String jndiNameParentLocalBusiness = resolver.resolveEjb(fromDu, parentLocalBusinessReference);
+ log.debug("Resolved " + parentLocalBusinessReference + " from " + fromDu + " to " + jndiNameParentLocalBusiness);
+ String jndiNameParentRemoteBusiness = resolver.resolveEjb(fromDu, parentRemoteBusinessReference);
+ log
+ .debug("Resolved " + parentRemoteBusinessReference + " from " + fromDu + " to "
+ + jndiNameParentRemoteBusiness);
+ String jndiNameParentLocalHome = resolver.resolveEjb(fromDu, parentLocalHomeReference);
+ log.debug("Resolved " + parentLocalHomeReference + " from " + fromDu + " to " + jndiNameParentLocalHome);
+ String jndiNameParentRemoteHome = resolver.resolveEjb(fromDu, parentRemoteHomeReference);
+ log.debug("Resolved " + parentRemoteHomeReference + " from " + fromDu + " to " + jndiNameParentRemoteHome);
+
+ // Declare expected
+ String parentEjbName = Child1Bean.class.getSimpleName();
+ String expectedParentLocalBusiness = parentEjbName + "/local-" + parentLocalBusinessBeanInterfaceName;
+ String expectedParentRemoteBusiness = parentEjbName + "/remote-" + parentRemoteBusinessBeanInterfaceName;
+ String expectedParentLocalHome = parentEjbName + "/localHome";
+ String expectedParentRemoteHome = parentEjbName + "/home";
+
+ // Test
+ TestCase.assertEquals(expectedParentLocalBusiness, jndiNameParentLocalBusiness);
+ TestCase.assertEquals(expectedParentRemoteBusiness, jndiNameParentRemoteBusiness);
+ TestCase.assertEquals(expectedParentLocalHome, jndiNameParentLocalHome);
+ TestCase.assertEquals(expectedParentRemoteHome, jndiNameParentRemoteHome);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Lifecycle Methods --------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+
+ // Make an annotation finder
+ AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+ JBoss50Creator creator = new JBoss50Creator(finder);
+
+ // Configure to scan the test EJBs
+ Collection<Class<?>> parentClasses, child1Classes, child2Classes, nestedChildClasses;
+ parentClasses = new ArrayList<Class<?>>();
+ child1Classes = new ArrayList<Class<?>>();
+ child2Classes = new ArrayList<Class<?>>();
+ nestedChildClasses = new ArrayList<Class<?>>();
+ parentClasses.add(ParentBean.class);
+ child1Classes.add(Child1Bean.class);
+ child2Classes.add(Child2Bean.class);
+ nestedChildClasses.add(NestedChildBean.class);
+
+ // Make the metadata
+ JBoss50MetaData parentMd = creator.create(parentClasses);
+ JBoss50MetaData child1Md = creator.create(child1Classes);
+ JBoss50MetaData child2Md = creator.create(child2Classes);
+ JBoss50MetaData nestedChildMd = creator.create(nestedChildClasses);
+ Collection<JBossMetaData> mds = new ArrayList<JBossMetaData>();
+ mds.add(parentMd);
+ mds.add(child1Md);
+ mds.add(child2Md);
+ mds.add(nestedChildMd);
+
+ // Decorate all EJBs w/ JNDI Policy
+ for (JBossMetaData md : mds)
+ {
+ // Decorate
+ MetadataUtil.decorateEjbsWithJndiPolicy(md, Thread.currentThread().getContextClassLoader());
+ }
+
+ // Parent DU
+ parentDu = new MockDeploymentUnit("Parent");
+ parentDu.addAttachment(AttachmentNames.PROCESSED_METADATA, parentMd);
+
+ // Child1 DU
+ child1Du = new MockDeploymentUnit("Child 1", parentDu);
+ child1Du.addAttachment(AttachmentNames.PROCESSED_METADATA, child1Md);
+
+ // Child1 DU
+ child2Du = new MockDeploymentUnit("Child 2", parentDu);
+ child2Du.addAttachment(AttachmentNames.PROCESSED_METADATA, child2Md);
+
+ // Nested Child DU
+ nestedChildDu = new MockDeploymentUnit("Nested Child", child1Du);
+ nestedChildDu.addAttachment(AttachmentNames.PROCESSED_METADATA, nestedChildMd);
+
+ // Set children of parents for bi-directional support
+ parentDu.addChild(child1Du);
+ parentDu.addChild(child2Du);
+ child1Du.addChild(nestedChildDu);
+
+ // Set Resolver
+ resolver = new FirstMatchEjbReferenceResolver();
+
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Inner Classes ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * A Mock DeploymentUnit with support to:
+ *
+ * - Add attachements
+ * - Manage the parent/child relationship
+ * - toString()
+ */
+ private static class MockDeploymentUnit extends AbstractDeploymentUnit implements DeploymentUnit
+ {
+
+ // --------------------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private String name;
+
+ private DeploymentUnit parent;
+
+ private List<DeploymentUnit> children;
+
+ private Map<String, Object> attachments;
+
+ // --------------------------------------------------------------------------------||
+ // Constructors -------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public MockDeploymentUnit(String name)
+ {
+ this.name = name;
+ this.children = new ArrayList<DeploymentUnit>();
+ this.attachments = new HashMap<String, Object>();
+ }
+
+ public MockDeploymentUnit(String name, DeploymentUnit parent)
+ {
+ this(name);
+ this.parent = parent;
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Functional Methods -------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public void addChild(DeploymentUnit child)
+ {
+ this.children.add(child);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Overridden Implementations -----------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ @Override
+ public List<DeploymentUnit> getChildren()
+ {
+ return this.children;
+ }
+
+ @Override
+ public DeploymentUnit getParent()
+ {
+ return this.parent;
+ }
+
+ @Override
+ public Object addAttachment(String name, Object attachment)
+ {
+ return this.attachments.put(name, attachment);
+ }
+
+ @Override
+ public Object getAttachment(String name)
+ {
+ return this.attachments.get(name);
+ }
+
+ @Override
+ public Map<String, Object> getAttachments()
+ {
+ return Collections.unmodifiableMap(this.attachments);
+ }
+
+ @Override
+ public String toString()
+ {
+ return this.getClass().getName() + ": " + this.name;
+ }
+
+ }
+
+}
More information about the jboss-cvs-commits
mailing list