[jboss-cvs] JBossAS SVN: r98985 - in projects/metadata/ejb/trunk/src: main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 4 08:45:58 EST 2010


Author: jaikiran
Date: 2010-01-04 08:45:57 -0500 (Mon, 04 Jan 2010)
New Revision: 98985

Added:
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/AbstractJNDIPolicyBasedJNDINameResolver.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedEntityBeanJNDINameResolver.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/EntityBeanJNDINameResolver.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/DefaultJNDIBindingPolicyFactory.java
Modified:
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedSessionBean31JNDINameResolver.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedSessionBeanJNDINameResolver.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/EnterpriseBeanJNDINameResolver.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/SessionBean31JNDINameResolver.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/SessionBeanJNDINameResolver.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/BasicJndiBindingPolicy.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/JavaEE6JndiBindingPolicy.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/spi/JbossEnterpriseBeanJndiNameResolver.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/spi/JbossSessionBeanJndiNameResolver.java
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jndiresolver/unit/SessionBeanJNDINameResolverTestCase.java
   projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/ejb/ResolveJndiNameDecoratorUnitTestCase.java
Log:
JBMETA-241 Additional JNDI name resolver implementation

Added: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/AbstractJNDIPolicyBasedJNDINameResolver.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/AbstractJNDIPolicyBasedJNDINameResolver.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/AbstractJNDIPolicyBasedJNDINameResolver.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -0,0 +1,195 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.metadata.ejb.jboss.jndi.resolver.impl;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.jboss.jndipolicy.spi.DefaultJndiBindingPolicy;
+import org.jboss.metadata.ejb.jboss.jndipolicy.spi.DeploymentSummary;
+import org.jboss.metadata.ejb.jboss.jndipolicy.spi.EjbDeploymentSummary;
+
+/**
+ * AbstractJNDIPolicyBasedJNDINameResolver
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public abstract class AbstractJNDIPolicyBasedJNDINameResolver
+{
+
+   /**
+    * Logger
+    */
+   private static Logger logger = Logger.getLogger(AbstractJNDIPolicyBasedJNDINameResolver.class);
+
+   /**
+    * The jndi binding policy which will be used to resolve jndi names,
+    * from enterprise bean metadata, if the metadata does not have a jndi binding 
+    * policy set, or if {@link #isIgnoreJNDIBindingPolicyOnMetaData()} returns true
+    */
+   protected DefaultJndiBindingPolicy jndiBindingPolicy;
+
+   /**
+    * Whether the jndi binding policy on the metadata should be ignored 
+    * while resolving the jndi names. 
+    * <ul>
+    *   <li>
+    *       If set to true, then the binding policy on metadata (if any) will be ignored 
+    *       and instead the jndi binding policy which was passed
+    *       to the constructor {@link #JNDIPolicyBasedSessionBeanJNDINameResolver(DefaultJndiBindingPolicy)}
+    *       will be used, during jndi name resolution.
+    *   </li>
+    *   <li>
+    *       If set to false, then the metadata will be checked to see if the jndi binding policy
+    *       has been set. If yes, then the jndi binding policy set on the metadata will be loaded
+    *       using the TCCL and that binding policy will be used to resolve the jndi names. If the 
+    *       binding policy is not set on the metadata then this resolver will use the jndi binding policy
+    *       which was passed to the constructor {@link #JNDIPolicyBasedSessionBeanJNDINameResolver(DefaultJndiBindingPolicy)}
+    *   </li> 
+    * </ul>
+    */
+   protected boolean ignoreJNDIBindingPolicyOnMetaData;
+
+   /**
+    * Constructs a {@link AbstractJNDIPolicyBasedJNDINameResolver} 
+    * 
+    * @param jndibindingPolicy The jndi binding policy which will be used for resolving jndi names 
+    *       out of session bean metadata, if the metadata does not have a jndi binding policy set
+    *       or if {@link #isIgnoreJNDIBindingPolicyOnMetaData()} returns true
+    * @throws IllegalArgumentException If the passed <code>jndibindingPolicy</code> is null
+    * @see #getJNDIBindingPolicy(JBossSessionBeanMetaData)       
+    */
+   public AbstractJNDIPolicyBasedJNDINameResolver(DefaultJndiBindingPolicy jndibindingPolicy)
+   {
+      if (jndibindingPolicy == null)
+      {
+         throw new IllegalArgumentException(
+               "JNDI binding policy cannot be null, for a JNDI binding policy based jndi-name resolver");
+      }
+      this.jndiBindingPolicy = jndibindingPolicy;
+   }
+
+   /**
+   *
+   * @return  Returns whether the {@link #ignoreJNDIBindingPolicyOnMetaData} flag is set
+   */
+   public boolean isIgnoreJNDIBindingPolicyOnMetaData()
+   {
+      return this.ignoreJNDIBindingPolicyOnMetaData;
+   }
+
+   /**
+    * Sets the {@link #ignoreJNDIBindingPolicyOnMetaData} flag
+    * @param ignoreJNDIBindingPolicyOnMetaData True if the jndi binding policy on the metadata
+    *         (if any) has to ignored during resolving jndi-names   
+    */
+   public void setIgnoreJNDIBindingPolicyOnMetaData(boolean ignoreJNDIBindingPolicyOnMetaData)
+   {
+      this.ignoreJNDIBindingPolicyOnMetaData = ignoreJNDIBindingPolicyOnMetaData;
+   }
+
+   /**
+    * Returns the {@link EjbDeploymentSummary} from the metadata
+    * 
+    * @param metadata Bean metadata
+    * @return
+    */
+   protected EjbDeploymentSummary getEjbDeploymentSummary(JBossEnterpriseBeanMetaData metadata)
+   {
+      DeploymentSummary dsummary = metadata.getJBossMetaData().getDeploymentSummary();
+      if (dsummary == null)
+         dsummary = new DeploymentSummary();
+      return new EjbDeploymentSummary(metadata, dsummary);
+   }
+
+   /**
+    * Returns an appropriate {@link DefaultJndiBindingPolicy} to be used for resolving
+    * jndi-names. <br/>
+    * 
+    * This method first checks whether the jndi binding policy on the metadata (if any)
+    * is to be ignored ({@link #isIgnoreJNDIBindingPolicyOnMetaData()}). If yes, then
+    * this method returns the jndi binding policy which was passed to the constructor 
+    * of this instance {@link #JNDIPolicyBasedSessionBeanJNDINameResolver(DefaultJndiBindingPolicy)}.
+    * 
+    * If {@link #isIgnoreJNDIBindingPolicyOnMetaData()} returns false, then this method checks
+    * to see if there is any jndi binding policy set on the metadata. If it finds one then
+    * this method uses the context classloader of the current thread ({@link Thread#getContextClassLoader()})
+    * to load that binding policy. If successfully loaded, then this method returns the instance
+    * of the jndi binding policy set on the metadata. If the binding policy cannot be loaded,
+    * or if the jndi binding policy doesn't implement {@link DefaultJndiBindingPolicy} then this method
+    * throws a {@link RuntimeException}.
+    * 
+    * If {@link #isIgnoreJNDIBindingPolicyOnMetaData()} returns false and there is *no* jndi binding 
+    * policy set on the metadata, then this method returns the jndi binding policy which was passed to the constructor 
+    * of this instance {@link #JNDIPolicyBasedSessionBeanJNDINameResolver(DefaultJndiBindingPolicy)}.
+    * 
+    * @param metadata Metadata of the bean, for which the jndi-names will be resolved by this resolver
+    * @throws RuntimeException If the jndi binding policy on the metadata cannot be loaded in 
+    *           the current thread's context classloader or if the jndi binding policy on the metadata
+    *           does not implement {@link DefaultJndiBindingPolicy}
+    * @return
+    */
+   protected DefaultJndiBindingPolicy getJNDIBindingPolicy(JBossEnterpriseBeanMetaData metadata)
+   {
+      if (this.isIgnoreJNDIBindingPolicyOnMetaData())
+      {
+         return this.jndiBindingPolicy;
+      }
+      String jndiBindingPolicyClassName = metadata.getJndiBindingPolicy();
+      if (jndiBindingPolicyClassName == null || jndiBindingPolicyClassName.trim().isEmpty())
+      {
+         return this.jndiBindingPolicy;
+      }
+      // TODO: Privileged block?
+      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+      try
+      {
+         Class<?> jndiBindingPolicyOnMetaDataClass = Class.forName(jndiBindingPolicyClassName, true, tccl);
+         // make sure it indeed implements DefaultJndiBindingPolicy
+         if (!DefaultJndiBindingPolicy.class.isAssignableFrom(jndiBindingPolicyOnMetaDataClass))
+         {
+            throw new RuntimeException("JNDI binding class: " + jndiBindingPolicyClassName + " on EJB named "
+                  + metadata.getEjbName() + " does not implement " + DefaultJndiBindingPolicy.class);
+         }
+         // create an instance
+         return (DefaultJndiBindingPolicy) jndiBindingPolicyOnMetaDataClass.newInstance();
+      }
+      catch (ClassNotFoundException cnfe)
+      {
+         throw new RuntimeException("Could not load jndi binding policy: " + jndiBindingPolicyClassName
+               + " from metadata for EJB named " + metadata.getEjbName(), cnfe);
+      }
+      catch (InstantiationException ine)
+      {
+         throw new RuntimeException("Could not create an instance of jndi binding policy: "
+               + jndiBindingPolicyClassName + " from metadata for EJB named " + metadata.getEjbName(), ine);
+      }
+      catch (IllegalAccessException iae)
+      {
+         throw new RuntimeException(
+               "IllegalAccessException while trying to create an instance of jndi binding policy: "
+                     + jndiBindingPolicyClassName + " from metadata for EJB named " + metadata.getEjbName(), iae);
+      }
+   }
+
+}

Added: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedEntityBeanJNDINameResolver.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedEntityBeanJNDINameResolver.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedEntityBeanJNDINameResolver.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -0,0 +1,146 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.metadata.ejb.jboss.jndi.resolver.impl;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossEntityBeanMetaData;
+import org.jboss.metadata.ejb.jboss.jndi.resolver.spi.EntityBeanJNDINameResolver;
+import org.jboss.metadata.ejb.jboss.jndipolicy.spi.DefaultJndiBindingPolicy;
+import org.jboss.metadata.ejb.jboss.jndipolicy.spi.KnownInterfaces;
+import org.jboss.metadata.ejb.jboss.jndipolicy.spi.KnownInterfaces.KnownInterfaceType;
+
+/**
+ * JNDIPolicyBasedEntityBeanJNDINameResolver
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class JNDIPolicyBasedEntityBeanJNDINameResolver extends AbstractJNDIPolicyBasedJNDINameResolver
+      implements
+         EntityBeanJNDINameResolver
+{
+
+   /**
+    * Logger
+    */
+   private static Logger logger = Logger.getLogger(JNDIPolicyBasedEntityBeanJNDINameResolver.class);
+
+   public JNDIPolicyBasedEntityBeanJNDINameResolver(DefaultJndiBindingPolicy jndiBindingPolicy)
+   {
+      super(jndiBindingPolicy);
+   }
+
+   /**
+    * @see org.jboss.metadata.ejb.jboss.jndi.resolver.spi.EntityBeanJNDINameResolver#resolveLocalHomeJNDIName(org.jboss.metadata.ejb.jboss.JBossEntityBeanMetaData)
+    */
+   @Override
+   public String resolveLocalHomeJNDIName(JBossEntityBeanMetaData metadata)
+   {
+      // first check if the "local-jndi-name" (== jndi name for the local home interface of EJB2.x entity bean)
+      // has been set of metadata.
+      if (metadata.getLocalJndiName() != null)
+      {
+         return metadata.getLocalJndiName();
+      }
+      // Let the policy generate the actual name
+      DefaultJndiBindingPolicy policy = this.getJNDIBindingPolicy(metadata);
+      return policy.getJndiName(this.getEjbDeploymentSummary(metadata), metadata.getLocalHome(),
+            KnownInterfaceType.LOCAL_HOME);
+   }
+
+   /**
+    * @see org.jboss.metadata.ejb.jboss.jndi.resolver.spi.EntityBeanJNDINameResolver#resolveRemoteHomeJNDIName(org.jboss.metadata.ejb.jboss.JBossEntityBeanMetaData)
+    */
+   @Override
+   public String resolveRemoteHomeJNDIName(JBossEntityBeanMetaData metadata)
+   {
+      // first check if the "jndi-name" (== jndi-name for the home interface of EJB2.x entity bean)
+      // has been set of metadata.
+      if (metadata.getJndiName() != null)
+      {
+         return metadata.getJndiName();
+      }
+      // Let the policy generate the actual name
+      DefaultJndiBindingPolicy policy = this.getJNDIBindingPolicy(metadata);
+      return policy.getJndiName(this.getEjbDeploymentSummary(metadata), metadata.getHome(),
+            KnownInterfaceType.REMOTE_HOME);
+   }
+
+   @Override
+   public String resolveJNDIName(JBossEntityBeanMetaData metadata, String interfaceName)
+   {
+
+      String resolvedJndiName = null;
+
+      // Classify the interface
+      KnownInterfaceType ifaceType = classifyInterface(metadata, interfaceName);
+
+      // Take appropriate handling depending upon the interface
+      if (ifaceType.equals(KnownInterfaceType.REMOTE_HOME))
+      {
+         resolvedJndiName = this.resolveRemoteHomeJNDIName(metadata);
+      }
+      else if (ifaceType.equals(KnownInterfaceType.LOCAL_HOME))
+      {
+         resolvedJndiName = this.resolveLocalHomeJNDIName(metadata);
+      }
+      else
+      {
+         // Let the policy generate the actual name
+         DefaultJndiBindingPolicy policy = this.getJNDIBindingPolicy(metadata);
+         resolvedJndiName = policy.getJndiName(this.getEjbDeploymentSummary(metadata), interfaceName, ifaceType);
+      }
+      logger.debug("Resolved JNDI Name for Interface " + interfaceName + " of type " + ifaceType + " is "
+            + resolvedJndiName);
+
+      // Return
+      return resolvedJndiName;
+   }
+
+   protected KnownInterfaceType classifyInterface(JBossEntityBeanMetaData metadata, String interfaceName)
+   {
+      // TODO: Why do we need this? The KnownInterfaces.classifyInterface expects the param 
+      // passed to be strings like "home", "remote" etc...
+      // TODO: This is here just for backward compatibility of earlier ways where the interfacename could
+      // have even been "home", "remote", "local" etc... (see ResolveJndiNameDecoratorUnitTestCase#testResolvedJndiNamesWithKnownIfacesEntity)
+      // Once everyone has moved to new resolvers then remove this hack
+      KnownInterfaceType ifaceType = KnownInterfaces.classifyInterface(interfaceName);
+      if (ifaceType != KnownInterfaceType.UNKNOWN)
+      {
+         return ifaceType;
+      }
+      // end of hack
+
+      // Compare interface against the metadata local-home/home 
+      if (metadata.getLocalHome() != null && metadata.getLocalHome().equals(interfaceName))
+      {
+         return KnownInterfaceType.LOCAL_HOME;
+      }
+      else if (metadata.getHome() != null && metadata.getHome().equals(interfaceName))
+      {
+         return KnownInterfaceType.REMOTE_HOME;
+      }
+
+      // default unknown
+      return KnownInterfaceType.UNKNOWN;
+   }
+}

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedSessionBean31JNDINameResolver.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedSessionBean31JNDINameResolver.java	2010-01-04 13:39:26 UTC (rev 98984)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedSessionBean31JNDINameResolver.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -22,6 +22,7 @@
 package org.jboss.metadata.ejb.jboss.jndi.resolver.impl;
 
 import org.jboss.metadata.ejb.jboss.JBossSessionBean31MetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
 import org.jboss.metadata.ejb.jboss.jndi.resolver.spi.SessionBean31JNDINameResolver;
 import org.jboss.metadata.ejb.jboss.jndipolicy.spi.DefaultJndiBindingPolicy;
 import org.jboss.metadata.ejb.jboss.jndipolicy.spi.EjbDeploymentSummary;
@@ -30,17 +31,28 @@
 
 /**
  * JNDIPolicyBasedSessionBean31JNDINameResolver
+ * 
+ * An implementation of {@link SessionBean31JNDINameResolver}, which uses 
+ * a {@link DefaultJndiBindingPolicy} for resolving jndi names for EJB3.1
+ * session beans 
  *
  * @author Jaikiran Pai
  * @version $Revision: $
  */
-public class JNDIPolicyBasedSessionBean31JNDINameResolver<T extends JBossSessionBean31MetaData>
-      extends
-         JNDIPolicyBasedSessionBeanJNDINameResolver<T> implements SessionBean31JNDINameResolver<T>
+public class JNDIPolicyBasedSessionBean31JNDINameResolver extends JNDIPolicyBasedSessionBeanJNDINameResolver
+      implements
+         SessionBean31JNDINameResolver
 {
 
    /**
-    * @param jndibindingPolicy
+    * Constructs a resolver based on the <code>jndibindingPolicy</code>
+    * 
+    * @param jndibindingPolicy The jndi binding policy which will be used for resolving jndi names 
+    *       out of session bean metadata, if the metadata does not have a jndi binding policy set
+    *       or if {@link #isIgnoreJNDIBindingPolicyOnMetaData()} returns true
+    *       
+    * @see #JNDIPolicyBasedSessionBean31JNDINameResolver(DefaultJndiBindingPolicy)
+    * @throws IllegalArgumentException If the passed <code>jndibindingPolicy</code> is null
     */
    public JNDIPolicyBasedSessionBean31JNDINameResolver(DefaultJndiBindingPolicy jndibindingPolicy)
    {
@@ -48,14 +60,19 @@
    }
 
    /**
+    * Uses the {@link DefaultJndiBindingPolicy} instance returned by {@link #getJNDIBindingPolicy(JBossSessionBeanMetaData)}
+    * to resolve the no-interface view jndi name for the <code>metadata</code>
+    * 
     * @see org.jboss.metadata.ejb.jboss.jndi.resolver.spi.SessionBean31JNDINameResolver#resolveNoInterfaceJNDIName(org.jboss.metadata.ejb.jboss.JBossSessionBean31MetaData)
+    * @see #getJNDIBindingPolicy(JBossSessionBeanMetaData)
     */
    @Override
-   public String resolveNoInterfaceJNDIName(T metadata)
+   public String resolveNoInterfaceJNDIName(JBossSessionBean31MetaData metadata)
    {
       // Get the no-interface view jndi name from the jndi binding policy
       EjbDeploymentSummary ejbDeploymentSummary = this.getEjbDeploymentSummary(metadata);
-      return this.jndiBindingPolicy.getJndiName(ejbDeploymentSummary, KnownInterfaces.NO_INTERFACE, KnownInterfaceType.NO_INTERFACE);
+      DefaultJndiBindingPolicy policy = this.getJNDIBindingPolicy(metadata);
+      return policy.getJndiName(ejbDeploymentSummary, KnownInterfaces.NO_INTERFACE, KnownInterfaceType.NO_INTERFACE);
    }
 
 }

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedSessionBeanJNDINameResolver.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedSessionBeanJNDINameResolver.java	2010-01-04 13:39:26 UTC (rev 98984)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/impl/JNDIPolicyBasedSessionBeanJNDINameResolver.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -28,7 +28,6 @@
 import org.jboss.metadata.ejb.jboss.RemoteBindingMetaData;
 import org.jboss.metadata.ejb.jboss.jndi.resolver.spi.SessionBeanJNDINameResolver;
 import org.jboss.metadata.ejb.jboss.jndipolicy.spi.DefaultJndiBindingPolicy;
-import org.jboss.metadata.ejb.jboss.jndipolicy.spi.DeploymentSummary;
 import org.jboss.metadata.ejb.jboss.jndipolicy.spi.EjbDeploymentSummary;
 import org.jboss.metadata.ejb.jboss.jndipolicy.spi.KnownInterfaces;
 import org.jboss.metadata.ejb.jboss.jndipolicy.spi.KnownInterfaces.KnownInterfaceType;
@@ -44,9 +43,9 @@
  * @author Jaikiran Pai
  * @version $Revision: $
  */
-public class JNDIPolicyBasedSessionBeanJNDINameResolver<T extends JBossSessionBeanMetaData>
+public class JNDIPolicyBasedSessionBeanJNDINameResolver extends AbstractJNDIPolicyBasedJNDINameResolver
       implements
-         SessionBeanJNDINameResolver<T>
+         SessionBeanJNDINameResolver
 {
 
    /**
@@ -55,26 +54,28 @@
    private static Logger logger = Logger.getLogger(JNDIPolicyBasedSessionBeanJNDINameResolver.class);
 
    /**
-    * The jndi binding policy which will be used for resolving the jndi names
-    */
-   protected DefaultJndiBindingPolicy jndiBindingPolicy;
-
-   /**
     * Constructs a {@link JNDIPolicyBasedSessionBeanJNDINameResolver} 
     * 
     * @param jndibindingPolicy The jndi binding policy which will be used for resolving jndi names 
-    *       out of session bean metadata
+    *       out of session bean metadata, if the metadata does not have a jndi binding policy set
+    *       or if {@link #isIgnoreJNDIBindingPolicyOnMetaData()} returns true
+    * @throws IllegalArgumentException If the passed <code>jndibindingPolicy</code> is null
+    * @see #getJNDIBindingPolicy(JBossSessionBeanMetaData)       
     */
    public JNDIPolicyBasedSessionBeanJNDINameResolver(DefaultJndiBindingPolicy jndibindingPolicy)
    {
-      this.jndiBindingPolicy = jndibindingPolicy;
+      super(jndibindingPolicy);
    }
 
    /**
+    * Uses the {@link DefaultJndiBindingPolicy} instance returned by {@link #getJNDIBindingPolicy(JBossSessionBeanMetaData)}
+    * to resolve the local home jndi name for the <code>metadata</code>
+    * 
     * @see org.jboss.metadata.ejb.jboss.jndi.resolver.spi.SessionBeanJNDINameResolver#resolveLocalHomeJNDIName(org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData)
+    * @see #getJNDIBindingPolicy(JBossSessionBeanMetaData)
     */
    @Override
-   public String resolveLocalHomeJNDIName(T metadata)
+   public String resolveLocalHomeJNDIName(JBossSessionBeanMetaData metadata)
    {
       // Check first for explicitly-defined Local Home JNDI Name
       String localHomeJndiName = metadata.getLocalHomeJndiName();
@@ -83,15 +84,19 @@
 
       // Get the local home jndi name from the jndi binding policy
       EjbDeploymentSummary ejbDeploymentSummary = this.getEjbDeploymentSummary(metadata);
-      return this.jndiBindingPolicy.getJndiName(ejbDeploymentSummary, KnownInterfaces.LOCAL_HOME,
-            KnownInterfaceType.LOCAL_HOME);
+      DefaultJndiBindingPolicy policy = this.getJNDIBindingPolicy(metadata);
+      return policy.getJndiName(ejbDeploymentSummary, KnownInterfaces.LOCAL_HOME, KnownInterfaceType.LOCAL_HOME);
    }
 
    /**
+    * Uses the {@link DefaultJndiBindingPolicy} instance returned by {@link #getJNDIBindingPolicy(JBossSessionBeanMetaData)}
+    * to resolve the remote business default jndi name for the <code>metadata</code>
+    * 
     * @see org.jboss.metadata.ejb.jboss.jndi.resolver.spi.SessionBeanJNDINameResolver#resolveRemoteBusinessDefaultJNDIName(org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData)
+    * @see #getJNDIBindingPolicy(JBossSessionBeanMetaData)
     */
    @Override
-   public String resolveRemoteBusinessDefaultJNDIName(T metadata)
+   public String resolveRemoteBusinessDefaultJNDIName(JBossSessionBeanMetaData metadata)
    {
       // Obtain remote bindings
       List<RemoteBindingMetaData> bindings = metadata.getRemoteBindings();
@@ -118,15 +123,19 @@
 
       // Not explicitly defined, so delegate out to the policy
       EjbDeploymentSummary ejbDeploymentSummary = this.getEjbDeploymentSummary(metadata);
-      return this.jndiBindingPolicy.getJndiName(ejbDeploymentSummary, KnownInterfaces.REMOTE,
-            KnownInterfaceType.BUSINESS_REMOTE);
+      DefaultJndiBindingPolicy policy = this.getJNDIBindingPolicy(metadata);
+      return policy.getJndiName(ejbDeploymentSummary, KnownInterfaces.REMOTE, KnownInterfaceType.BUSINESS_REMOTE);
    }
 
    /**
+    * Uses the {@link DefaultJndiBindingPolicy} instance returned by {@link #getJNDIBindingPolicy(JBossSessionBeanMetaData)}
+    * to resolve the remote home jndi name for the <code>metadata</code>
+    * 
     * @see org.jboss.metadata.ejb.jboss.jndi.resolver.spi.SessionBeanJNDINameResolver#resolveRemoteHomeJNDIName(org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData)
+    * @see #getJNDIBindingPolicy(JBossSessionBeanMetaData)
     */
    @Override
-   public String resolveRemoteHomeJNDIName(T metadata)
+   public String resolveRemoteHomeJNDIName(JBossSessionBeanMetaData metadata)
    {
       // Check first for explicitly-defined Remote Home JNDI Name
       String remoteHomeJndiName = metadata.getHomeJndiName();
@@ -135,16 +144,20 @@
 
       // Get the remote home jndi name from the jndi binding policy
       EjbDeploymentSummary ejbDeploymentSummary = this.getEjbDeploymentSummary(metadata);
-      return this.jndiBindingPolicy.getJndiName(ejbDeploymentSummary, KnownInterfaces.HOME,
-            KnownInterfaceType.REMOTE_HOME);
+      DefaultJndiBindingPolicy policy = this.getJNDIBindingPolicy(metadata);
+      return policy.getJndiName(ejbDeploymentSummary, KnownInterfaces.HOME, KnownInterfaceType.REMOTE_HOME);
 
    }
 
    /**
+    * Uses the {@link DefaultJndiBindingPolicy} instance returned by {@link #getJNDIBindingPolicy(JBossSessionBeanMetaData)}
+    * to resolve the local default business jndi name for the <code>metadata</code>
+    * 
     * @see org.jboss.metadata.ejb.jboss.jndi.resolver.spi.SessionBeanJNDINameResolver#resolveLocalBusinessDefaultJNDIName(org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData)
+    * @see #getJNDIBindingPolicy(JBossSessionBeanMetaData)
     */
    @Override
-   public String resolveLocalBusinessDefaultJNDIName(T metadata)
+   public String resolveLocalBusinessDefaultJNDIName(JBossSessionBeanMetaData metadata)
    {
       // Check first for explicitly-defined local JNDI Name
       String localJndiName = metadata.getLocalJndiName();
@@ -153,15 +166,19 @@
 
       // Get the local jndi name from the jndi binding policy
       EjbDeploymentSummary ejbDeploymentSummary = this.getEjbDeploymentSummary(metadata);
-      return this.jndiBindingPolicy.getJndiName(ejbDeploymentSummary, KnownInterfaces.LOCAL,
-            KnownInterfaceType.BUSINESS_LOCAL);
+      DefaultJndiBindingPolicy policy = this.getJNDIBindingPolicy(metadata);
+      return policy.getJndiName(ejbDeploymentSummary, KnownInterfaces.LOCAL, KnownInterfaceType.BUSINESS_LOCAL);
    }
 
    /**
+    * Uses the {@link DefaultJndiBindingPolicy} instance returned by {@link #getJNDIBindingPolicy(JBossSessionBeanMetaData)}
+    * to resolve the jndi name for the <code>metadata</code> and the <code>interfaceName</code> combination
+    * 
     * @see org.jboss.metadata.ejb.jboss.jndi.resolver.spi.EnterpriseBeanJNDINameResolver#resolveJNDIName(org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData, java.lang.String)
+    * @see #getJNDIBindingPolicy(JBossSessionBeanMetaData)
     */
    @Override
-   public String resolveJNDIName(T metadata, String interfaceName)
+   public String resolveJNDIName(JBossSessionBeanMetaData metadata, String interfaceName)
    {
       String resolvedJndiName = null;
 
@@ -173,15 +190,15 @@
       {
          resolvedJndiName = this.resolveRemoteHomeJNDIName(metadata);
       }
-      if (ifaceType.equals(KnownInterfaceType.LOCAL_HOME))
+      else if (ifaceType.equals(KnownInterfaceType.LOCAL_HOME))
       {
          resolvedJndiName = this.resolveLocalHomeJNDIName(metadata);
       }
-      if (ifaceType.equals(KnownInterfaceType.BUSINESS_REMOTE) || ifaceType.equals(KnownInterfaceType.BUSINESS_LOCAL))
+      else 
       {
-         // Revert to defaults; have the policy generate the actual name
-         resolvedJndiName = this.jndiBindingPolicy.getJndiName(this.getEjbDeploymentSummary(metadata), interfaceName,
-               ifaceType);
+         // Let the policy generate the actual name
+         DefaultJndiBindingPolicy policy = this.getJNDIBindingPolicy(metadata);
+         resolvedJndiName = policy.getJndiName(this.getEjbDeploymentSummary(metadata), interfaceName, ifaceType);
       }
 
       logger.debug("Resolved JNDI Name for Interface " + interfaceName + " of type " + ifaceType + " is "
@@ -191,6 +208,7 @@
       return resolvedJndiName;
    }
 
+   
    /**
     * Classifies the fully qualified <code>interfaceName</code> into a {@link KnownInterfaceType}
     * based on the bean <code>metadata</code>.
@@ -200,17 +218,21 @@
     * @return Returns a {@link KnownInterfaceType}
     * @throws NullPointerException If <code>metadata</code> is null
     */
-   protected KnownInterfaceType classifyInterface(T metadata, String interfaceName)
+   protected KnownInterfaceType classifyInterface(JBossSessionBeanMetaData metadata, String interfaceName)
    {
 
       // TODO: Why do we need this? The KnownInterfaces.classifyInterface expects the param 
       // passed to be strings like "home", "remote" etc...
-//      KnownInterfaceType ifaceType = KnownInterfaces.classifyInterface(iface);
-//      if (ifaceType != KnownInterfaceType.UNKNOWN)
-//         return ifaceType;
+      // TODO: This is here just for backward compatibility of earlier ways where the interfacename could
+      // have even been "home", "remote", "local" etc... (see Default2xNamingStrategyTestCase#assertLocalHome)
+      // Once everyone has moved to new resolvers then remove this hack
+      KnownInterfaceType ifaceType = KnownInterfaces.classifyInterface(interfaceName);
+      if (ifaceType != KnownInterfaceType.UNKNOWN)
+      {
+         return ifaceType;
+      }
+      // end of hack
 
-      KnownInterfaceType ifaceType = KnownInterfaceType.UNKNOWN;
-      
       // Compare interface against the metadata local-home/home & business locals/remotes
       // Figure out the interface type from the metadata
       if (metadata.getLocalHome() != null && metadata.getLocalHome().equals(interfaceName))
@@ -252,19 +274,4 @@
       return KnownInterfaceType.BUSINESS_REMOTE;
    }
 
-   /**
-    * Returns the {@link EjbDeploymentSummary} from the metadata
-    * 
-    * @param metadata Bean metadata
-    * @return
-    */
-   protected EjbDeploymentSummary getEjbDeploymentSummary(T metadata)
-   {
-      DeploymentSummary dsummary = metadata.getJBossMetaData().getDeploymentSummary();
-      if (dsummary == null)
-         dsummary = new DeploymentSummary();
-      return new EjbDeploymentSummary(metadata, dsummary);
-   }
-   
-   
 }

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/EnterpriseBeanJNDINameResolver.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/EnterpriseBeanJNDINameResolver.java	2010-01-04 13:39:26 UTC (rev 98984)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/EnterpriseBeanJNDINameResolver.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -32,11 +32,11 @@
  * @author Jaikiran Pai
  * @version $Revision: $
  */
-public interface EnterpriseBeanJNDINameResolver<T extends JBossEnterpriseBeanMetaData>
+public interface EnterpriseBeanJNDINameResolver
 {
 
    /**
-    * Returns the JNDI name for the <code>interfaceName</code>, of the session bean
+    * Returns the JNDI name for the <code>interfaceName</code>, of the enterprise bean
     * represented by the <code>metadata</code>.
     * 
     * Returns null if the JNDI name for the <code>interfaceName</code> cannot be resolved
@@ -44,5 +44,5 @@
     * @param iface The fully qualified interface name 
     * @return
     */
-   String resolveJNDIName(T metadata, String interfaceName);
+   String resolveJNDIName(JBossEnterpriseBeanMetaData metadata, String interfaceName);
 }

Added: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/EntityBeanJNDINameResolver.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/EntityBeanJNDINameResolver.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/EntityBeanJNDINameResolver.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.metadata.ejb.jboss.jndi.resolver.spi;
+
+import org.jboss.metadata.ejb.jboss.JBossEntityBeanMetaData;
+
+/**
+ * EntityBeanJNDINameResolver
+ *
+ * A JNDI name resolver for EJB2.x entity beans
+ * 
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface EntityBeanJNDINameResolver 
+{
+   // For EJB2.x entity beans, only home and local home interfaces
+   // are bound to JNDI, hence this interface doesn't provide 
+   // anything more than resolveRemoteHomeJNDIName and resolveLocalHomeJNDIName
+
+   /**
+    * Returns the JNDI name for the EJB2.x Remote Home interface, of the entity bean
+    * represented by the <code>metadata</code>.
+    * 
+    * Returns null if the JNDI name EJB2.x Remote Home interface cannot be resolved
+    * @return
+    */
+   public String resolveRemoteHomeJNDIName(JBossEntityBeanMetaData metadata);
+
+   /**
+    * Returns the JNDI name for the EJB2.x Local Home interface, of the entity bean
+    * represented by the <code>metadata</code>.
+    * 
+    * Returns null if the JNDI name for EJB2.x Local Home interface cannot be resolved
+    * @return
+    */
+   public String resolveLocalHomeJNDIName(JBossEntityBeanMetaData metadata);
+   
+   /**
+    * Returns the JNDI name for the <code>interfaceName</code>, of the entity bean
+    * represented by the <code>metadata</code>.
+    * 
+    * Returns null if the JNDI name for the <code>interfaceName</code> cannot be resolved
+    * 
+    * @param iface The fully qualified interface name 
+    * @return
+    */
+   String resolveJNDIName(JBossEntityBeanMetaData metadata, String interfaceName);
+
+}

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/SessionBean31JNDINameResolver.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/SessionBean31JNDINameResolver.java	2010-01-04 13:39:26 UTC (rev 98984)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/SessionBean31JNDINameResolver.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -32,9 +32,7 @@
  * @author Jaikiran Pai
  * @version $Revision: $
  */
-public interface SessionBean31JNDINameResolver<T extends JBossSessionBean31MetaData>
-      extends
-         SessionBeanJNDINameResolver<T>
+public interface SessionBean31JNDINameResolver extends SessionBeanJNDINameResolver
 {
 
    /**
@@ -44,5 +42,5 @@
     * Returns null if the JNDI name for EJB3.1 no-interface view cannot be resolved
     * @return
     */
-   public String resolveNoInterfaceJNDIName(T metadata);
+   public String resolveNoInterfaceJNDIName(JBossSessionBean31MetaData metadata);
 }

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/SessionBeanJNDINameResolver.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/SessionBeanJNDINameResolver.java	2010-01-04 13:39:26 UTC (rev 98984)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndi/resolver/spi/SessionBeanJNDINameResolver.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -32,9 +32,7 @@
  * @author Jaikiran Pai
  * @version $Revision: $
  */
-public interface SessionBeanJNDINameResolver<T extends JBossSessionBeanMetaData>
-      extends
-         EnterpriseBeanJNDINameResolver<T>
+public interface SessionBeanJNDINameResolver
 {
 
    /**
@@ -44,7 +42,7 @@
     * Returns null if the JNDI name EJB2.x Remote Home interface cannot be resolved
     * @return
     */
-   public String resolveRemoteHomeJNDIName(T metadata);
+   public String resolveRemoteHomeJNDIName(JBossSessionBeanMetaData metadata);
 
    /**
     * Returns the JNDI name for the EJB2.x Local Home interface, of the session bean
@@ -53,7 +51,7 @@
     * Returns null if the JNDI name for EJB2.x Local Home interface cannot be resolved
     * @return
     */
-   public String resolveLocalHomeJNDIName(T metadata);
+   public String resolveLocalHomeJNDIName(JBossSessionBeanMetaData metadata);
 
    /**
     * Returns the JNDI name for the default EJB3.x Remote Business interfaces, of the session bean
@@ -62,7 +60,7 @@
     * Returns null if the JNDI name for EJB3.x Remote Business interfaces cannot be resolved
     * @return
     */
-   public String resolveRemoteBusinessDefaultJNDIName(T metadata);
+   public String resolveRemoteBusinessDefaultJNDIName(JBossSessionBeanMetaData metadata);
 
    /**
     * Returns the JNDI name for the default EJB3.x Local Business interfaces, of the session bean
@@ -71,5 +69,16 @@
     * Returns null if the JNDI name for EJB3.x Local Business interfaces cannot be resolved
     * @return
     */
-   public String resolveLocalBusinessDefaultJNDIName(T metadata);
+   public String resolveLocalBusinessDefaultJNDIName(JBossSessionBeanMetaData metadata);
+
+   /**
+    * Returns the JNDI name for the <code>interfaceName</code>, of the session bean
+    * represented by the <code>metadata</code>.
+    * 
+    * Returns null if the JNDI name for the <code>interfaceName</code> cannot be resolved
+    * 
+    * @param iface The fully qualified interface name 
+    * @return
+    */
+   String resolveJNDIName(JBossSessionBeanMetaData metadata, String interfaceName);
 }

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/BasicJndiBindingPolicy.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/BasicJndiBindingPolicy.java	2010-01-04 13:39:26 UTC (rev 98984)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/BasicJndiBindingPolicy.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -174,6 +174,19 @@
                   // base-name / (local|remote)Home
                   jndiName = baseJndiName + "/" + ifaceType.toSuffix();
                   break;
+                  
+               case NO_INTERFACE :
+                  if (iface == null)
+                  {
+                     // base-name / no-interface
+                     jndiName = baseJndiName + "/" + ifaceType.toSuffix();
+                  }
+                  else
+                  {
+                     // base-name / fully-qualified-bean-class-name  
+                     jndiName = baseJndiName + "/" + iface;
+                  }
+                  break;
             }
          }
          else

Added: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/DefaultJNDIBindingPolicyFactory.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/DefaultJNDIBindingPolicyFactory.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/DefaultJNDIBindingPolicyFactory.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -0,0 +1,100 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.metadata.ejb.jboss.jndipolicy.plugins;
+
+import org.jboss.metadata.ejb.jboss.jndipolicy.spi.DefaultJndiBindingPolicy;
+
+/**
+ * DefaultJNDIBindingPolicyFactory
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class DefaultJNDIBindingPolicyFactory
+{
+
+   private static final String DEFAULT_JNDI_BINDING_CLASS_NAME = BasicJndiBindingPolicy.class.getName();
+
+   public static DefaultJndiBindingPolicy getDefaultJNDIBindingPolicy()
+   {
+      ClassLoader tccl = getTCCL();
+      return getDefaultJNDIBindingPolicy(tccl);
+   }
+
+   public static DefaultJndiBindingPolicy getDefaultJNDIBindingPolicy(ClassLoader cl)
+   {
+      return getJNDIBindingPolicy(DEFAULT_JNDI_BINDING_CLASS_NAME, cl);
+   }
+
+   public static DefaultJndiBindingPolicy getJNDIBindingPolicy(String jndiBindingPolicyClassName)
+   {
+      ClassLoader tccl = getTCCL();
+      return getJNDIBindingPolicy(jndiBindingPolicyClassName, tccl);
+
+   }
+
+   public static DefaultJndiBindingPolicy getJNDIBindingPolicy(String jndiBindingPolicyClassName, ClassLoader cl)
+   {
+      if (cl == null)
+      {
+         throw new IllegalArgumentException("Classloader cannot be null while creating a jndi binding policy: " + jndiBindingPolicyClassName);
+      }
+      if (jndiBindingPolicyClassName == null || jndiBindingPolicyClassName.trim().isEmpty())
+      {
+         throw new IllegalArgumentException("JNDI binding policy classname cannot be null or empty string: " + jndiBindingPolicyClassName);
+      }
+      try
+      {
+         Class<?> jndiBindingPolicyOnMetaDataClass = Class.forName(jndiBindingPolicyClassName, true, cl);
+         // make sure it indeed implements DefaultJndiBindingPolicy
+         if (!DefaultJndiBindingPolicy.class.isAssignableFrom(jndiBindingPolicyOnMetaDataClass))
+         {
+            throw new RuntimeException("JNDI binding class: " + jndiBindingPolicyClassName + " does not implement "
+                  + DefaultJndiBindingPolicy.class);
+         }
+         // create an instance
+         return (DefaultJndiBindingPolicy) jndiBindingPolicyOnMetaDataClass.newInstance();
+      }
+      catch (ClassNotFoundException cnfe)
+      {
+         throw new RuntimeException("Could not load jndi binding policy: " + jndiBindingPolicyClassName, cnfe);
+      }
+      catch (InstantiationException ine)
+      {
+         throw new RuntimeException("Could not create an instance of jndi binding policy: "
+               + jndiBindingPolicyClassName, ine);
+      }
+      catch (IllegalAccessException iae)
+      {
+         throw new RuntimeException(
+               "IllegalAccessException while trying to create an instance of jndi binding policy: "
+                     + jndiBindingPolicyClassName, iae);
+      }
+   }
+
+   private static ClassLoader getTCCL()
+   {
+      // TODO: Privileged block?
+      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+      return tccl;
+   }
+}

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/JavaEE6JndiBindingPolicy.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/JavaEE6JndiBindingPolicy.java	2010-01-04 13:39:26 UTC (rev 98984)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/plugins/JavaEE6JndiBindingPolicy.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -171,8 +171,16 @@
                   break;
                   
                case NO_INTERFACE:
-                  // base-name ! no-interface
-                  jndiName = baseJndiName + "!" + ifaceType.toSuffix();
+                  if (iface == null)
+                  {
+                     // base-name ! no-interface
+                     jndiName = baseJndiName + "!" + ifaceType.toSuffix();
+                  }
+                  else
+                  {
+                     // base-name ! fully-qualified-bean-class-name  
+                     jndiName = baseJndiName + "!" + iface;
+                  }
                   break;
             }
          }

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/spi/JbossEnterpriseBeanJndiNameResolver.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/spi/JbossEnterpriseBeanJndiNameResolver.java	2010-01-04 13:39:26 UTC (rev 98984)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/spi/JbossEnterpriseBeanJndiNameResolver.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -22,6 +22,14 @@
 package org.jboss.metadata.ejb.jboss.jndipolicy.spi;
 
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEntityBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.jboss.jndi.resolver.impl.JNDIPolicyBasedEntityBeanJNDINameResolver;
+import org.jboss.metadata.ejb.jboss.jndi.resolver.impl.JNDIPolicyBasedSessionBeanJNDINameResolver;
+import org.jboss.metadata.ejb.jboss.jndi.resolver.spi.EnterpriseBeanJNDINameResolver;
+import org.jboss.metadata.ejb.jboss.jndi.resolver.spi.EntityBeanJNDINameResolver;
+import org.jboss.metadata.ejb.jboss.jndi.resolver.spi.SessionBeanJNDINameResolver;
+import org.jboss.metadata.ejb.jboss.jndipolicy.plugins.DefaultJNDIBindingPolicyFactory;
 
 /**
  * JbossEnterpriseBeanJndiNameResolver
@@ -31,7 +39,9 @@
  *
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
+ * @deprecated Since 2.0.0-alpha-5 - Use an implementation of {@link EnterpriseBeanJNDINameResolver} 
  */
+ at Deprecated
 public class JbossEnterpriseBeanJndiNameResolver
 {
 
@@ -45,14 +55,22 @@
     */
    public static String resolveJndiName(JBossEnterpriseBeanMetaData md, String iface)
    {
-      // Ensure the metadata is able to resolve JNDI names
-      ResolveableJndiNameJbossEnterpriseBeanMetadata rmd = ensureResolvable(md);
 
-      // Resolve
-      String resolved = rmd.determineResolvedJndiName(iface);
+      DefaultJndiBindingPolicy policy = DefaultJNDIBindingPolicyFactory.getDefaultJNDIBindingPolicy();
+      // This if block is a hack to allow for backward compatibility (the days
+      // when decorated metadata was being used)
+      if (md.isSession() || md.isService())
+      {
+         SessionBeanJNDINameResolver sessionBeanJNDINameResolver = new JNDIPolicyBasedSessionBeanJNDINameResolver(policy);
+         return sessionBeanJNDINameResolver.resolveJNDIName((JBossSessionBeanMetaData) md, iface);
+      }
+      else if (md.isEntity())
+      {
+         EntityBeanJNDINameResolver entityBeanJNDINameResolver = new JNDIPolicyBasedEntityBeanJNDINameResolver(policy);
+         return entityBeanJNDINameResolver.resolveJNDIName((JBossEntityBeanMetaData) md, iface);
+      }
+      return null;
 
-      // Return
-      return resolved;
    }
 
    /**

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/spi/JbossSessionBeanJndiNameResolver.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/spi/JbossSessionBeanJndiNameResolver.java	2010-01-04 13:39:26 UTC (rev 98984)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/jndipolicy/spi/JbossSessionBeanJndiNameResolver.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -22,6 +22,9 @@
 package org.jboss.metadata.ejb.jboss.jndipolicy.spi;
 
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.jboss.jndi.resolver.impl.JNDIPolicyBasedSessionBeanJNDINameResolver;
+import org.jboss.metadata.ejb.jboss.jndi.resolver.spi.SessionBeanJNDINameResolver;
+import org.jboss.metadata.ejb.jboss.jndipolicy.plugins.DefaultJNDIBindingPolicyFactory;
 
 /**
  * JbossSessionBeanJndiNameResolver
@@ -31,7 +34,9 @@
  *
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
+ * @deprecated Since 2.0.0-alpha-5 - Use an implementation of {@link SessionBeanJNDINameResolver} instead
  */
+ at Deprecated
 public class JbossSessionBeanJndiNameResolver extends JbossEnterpriseBeanJndiNameResolver
 {
    /**
@@ -42,11 +47,9 @@
     */
    public static String resolveRemoteHomeJndiName(JBossSessionBeanMetaData md)
    {
-      // Ensure Resolveable
-      ResolveableJndiNameJbossSessionBeanMetadata rmd = ensureResolvable(md);
 
       // Resolve
-      String resolved = rmd.determineResolvedRemoteHomeJndiName();
+      String resolved = getSessionBeanJNDINameResolver().resolveRemoteHomeJNDIName(md);
 
       // Return
       return resolved;
@@ -60,11 +63,8 @@
     */
    public static String resolveLocalHomeJndiName(JBossSessionBeanMetaData md)
    {
-      // Ensure Resolveable
-      ResolveableJndiNameJbossSessionBeanMetadata rmd = ensureResolvable(md);
-
       // Resolve
-      String resolved = rmd.determineResolvedLocalHomeJndiName();
+      String resolved = getSessionBeanJNDINameResolver().resolveLocalHomeJNDIName(md);
 
       // Return
       return resolved;
@@ -78,11 +78,8 @@
     */
    public static String resolveRemoteBusinessDefaultJndiName(JBossSessionBeanMetaData md)
    {
-      // Ensure Resolveable
-      ResolveableJndiNameJbossSessionBeanMetadata rmd = ensureResolvable(md);
-
       // Resolve
-      String resolved = rmd.determineResolvedRemoteBusinessDefaultJndiName();
+      String resolved = getSessionBeanJNDINameResolver().resolveRemoteBusinessDefaultJNDIName(md);
 
       // Return
       return resolved;
@@ -96,11 +93,8 @@
     */
    public static String resolveLocalBusinessDefaultJndiName(JBossSessionBeanMetaData md)
    {
-      // Ensure Resolveable
-      ResolveableJndiNameJbossSessionBeanMetadata rmd = ensureResolvable(md);
-
       // Resolve
-      String resolved = rmd.determineResolvedLocalBusinessDefaultJndiName();
+      String resolved = getSessionBeanJNDINameResolver().resolveLocalBusinessDefaultJNDIName(md);
 
       // Return
       return resolved;
@@ -113,7 +107,9 @@
     * 
     * @param md
     * @return
+    * @deprecated
     */
+   @Deprecated
    protected static ResolveableJndiNameJbossSessionBeanMetadata ensureResolvable(JBossSessionBeanMetaData md)
    {
       // Check that castable to a JNDI Resolveable type
@@ -132,4 +128,18 @@
       throw new IllegalArgumentException(errorMessage);
 
    }
+
+   private static SessionBeanJNDINameResolver getSessionBeanJNDINameResolver()
+   {
+      DefaultJndiBindingPolicy jndiBindingPolicy = getDefaultJNDIBindingPolicy();
+      SessionBeanJNDINameResolver sessionBeanJNDINameResolver = new JNDIPolicyBasedSessionBeanJNDINameResolver(
+            jndiBindingPolicy);
+      return sessionBeanJNDINameResolver;
+   }
+
+   private static DefaultJndiBindingPolicy getDefaultJNDIBindingPolicy()
+   {
+      return DefaultJNDIBindingPolicyFactory.getDefaultJNDIBindingPolicy();
+
+   }
 }

Modified: projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jndiresolver/unit/SessionBeanJNDINameResolverTestCase.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jndiresolver/unit/SessionBeanJNDINameResolverTestCase.java	2010-01-04 13:39:26 UTC (rev 98984)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jndiresolver/unit/SessionBeanJNDINameResolverTestCase.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -97,8 +97,7 @@
       JBossSessionBeanMetaData sessionBean = (JBossSessionBeanMetaData) bean;
       // Create a jndi name resolver based on the jndi binding policy
       DefaultJndiBindingPolicy jndiBindingPolicy = new BasicJndiBindingPolicy();
-      SessionBeanJNDINameResolver<JBossSessionBeanMetaData> jndiNameResolver = new JNDIPolicyBasedSessionBeanJNDINameResolver<JBossSessionBeanMetaData>(
-            jndiBindingPolicy);
+      SessionBeanJNDINameResolver jndiNameResolver = new JNDIPolicyBasedSessionBeanJNDINameResolver(jndiBindingPolicy);
 
       // ensure that the remote default business interface jndi name is correctly resolved
       String remoteDefaultBusinessJNDIName = jndiNameResolver.resolveRemoteBusinessDefaultJNDIName(sessionBean);
@@ -175,8 +174,7 @@
       JBossSessionBeanMetaData sessionBean = (JBossSessionBeanMetaData) bean;
       // Create a jndi name resolver based on the jndi binding policy
       DefaultJndiBindingPolicy jndiBindingPolicy = new BasicJndiBindingPolicy();
-      SessionBeanJNDINameResolver<JBossSessionBeanMetaData> jndiNameResolver = new JNDIPolicyBasedSessionBeanJNDINameResolver<JBossSessionBeanMetaData>(
-            jndiBindingPolicy);
+      SessionBeanJNDINameResolver jndiNameResolver = new JNDIPolicyBasedSessionBeanJNDINameResolver(jndiBindingPolicy);
       EjbDeploymentSummary ejbDeploymentSummary = this.getEjbDeploymentSummary(sessionBean);
       // ensure that the remote default business interface jndi name is correctly resolved
       String remoteDefaultBusinessJNDIName = jndiNameResolver.resolveRemoteBusinessDefaultJNDIName(sessionBean);

Modified: projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/ejb/ResolveJndiNameDecoratorUnitTestCase.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/ejb/ResolveJndiNameDecoratorUnitTestCase.java	2010-01-04 13:39:26 UTC (rev 98984)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/ejb/ResolveJndiNameDecoratorUnitTestCase.java	2010-01-04 13:45:57 UTC (rev 98985)
@@ -537,7 +537,9 @@
       
       // Define expected results
       String expectedRemote = "base/testResolvedJndiNamesWithKnownIfacesEntity-jndi-name";
-      String expectedHome = "base/testResolvedJndiNamesWithKnownIfacesEntity-jndi-name/home";
+      // jndi-name is set in getEntityMetaData(), so the remote home of the bean would be 
+      // bound to that name
+      String expectedHome = beanMD.getJndiName(); 
       String expectedLocalHome = "base/testResolvedJndiNamesWithKnownIfacesEntity-jndi-name/localHome";
       String expectedRandomInterface = "base/testResolvedJndiNamesWithKnownIfacesEntity-jndi-name/" + randomInterface;
       
@@ -560,8 +562,11 @@
       // Test Deprecated, backwards-compat behavior (may be removed when these methods no longer exist, JBMETA-68)
       String resolvedJndiNameD = beanMD.determineResolvedJndiName(null, null);
       assertEquals(expectedRemote, resolvedJndiNameD);
+      // since we are skipping the resolvers, which take into account the "jndi-name" set on metadata
+      // while resolving home jndi name, the resolved home jndi name will be as below 
+      String expectedResolvedHomeJNDIName = "base/testResolvedJndiNamesWithKnownIfacesEntity-jndi-name/home";
       String resolvedJndiNameHomeD = beanMD.determineResolvedJndiName(home, null);
-      assertEquals(expectedHome, resolvedJndiNameHomeD);
+      assertEquals(expectedResolvedHomeJNDIName, resolvedJndiNameHomeD);
       String resolvedJndiNameLocalHomeD = beanMD.determineResolvedJndiName(localHome, null);
       assertEquals(expectedLocalHome, resolvedJndiNameLocalHomeD);
       String resolvedJndiNameIfaceD = beanMD.determineResolvedJndiName(randomInterface, null);
@@ -580,6 +585,7 @@
       JBossSessionBeanMetaData beanMD = this.getEjbMetaData();
       
       // Manually Decorate
+      beanMD.setJndiBindingPolicy(EjbNameJndiBindingPolicy.class.getName());
       beanMD = new JBossSessionPolicyDecorator(beanMD,new EjbNameJndiBindingPolicy());
       
       // Define Expected Results




More information about the jboss-cvs-commits mailing list