[jboss-cvs] JBossAS SVN: r66714 - in trunk/ejb3: src/main/org/jboss/annotation/ejb and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Nov 4 01:16:16 EST 2007


Author: ALRubinger
Date: 2007-11-04 01:16:16 -0500 (Sun, 04 Nov 2007)
New Revision: 66714

Added:
   trunk/ejb3/src/main/org/jboss/annotation/ejb/JndiBindingPolicy.java
   trunk/ejb3/src/main/org/jboss/annotation/ejb/JndiBindingPolicyImpl.java
   trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DeploymentSummary.java
   trunk/ejb3/src/main/org/jboss/ejb3/jndipolicy/
   trunk/ejb3/src/main/org/jboss/ejb3/jndipolicy/DefaultJndiBindingPolicy.java
   trunk/ejb3/src/main/org/jboss/ejb3/jndipolicy/PackagingBasedJndiBindingPolicy.java
Modified:
   trunk/ejb3/build.xml
   trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
   trunk/ejb3/src/resources/ejb3-interceptors-aop.xml
   trunk/ejb3/src/resources/test/defaultremotebindings/default-ejb3-interceptors-aop.xml
Log:
[EJBTHREE-1101] Moved hardcoded JNDI Binding Strategy to pluggable solution allowing custom implementations.  Currently works annotation-based only.

Modified: trunk/ejb3/build.xml
===================================================================
--- trunk/ejb3/build.xml	2007-11-04 04:21:51 UTC (rev 66713)
+++ trunk/ejb3/build.xml	2007-11-04 06:16:16 UTC (rev 66714)
@@ -325,9 +325,11 @@
    	<jar jarfile="${build.lib}/jboss-ejb3-ext-api.jar" manifest="${build.etc}/default.mf">
    		<fileset dir="${build.classes}">
 			<include name="org/jboss/annotation/**/*.class"/>
-   		   <include name="org/jboss/ejb3/remoting/RemoteProxyFactory.class"/>
-   		   <include name="org/jboss/ejb3/cache/**/*Factory.class"/>
-   		   <exclude name="org/jboss/**/*Impl.class"/>
+   		    <include name="org/jboss/ejb3/remoting/RemoteProxyFactory.class"/>
+   		    <include name="org/jboss/ejb3/cache/**/*Factory.class"/>
+            <include name="org/jboss/ejb3/jndipolicy/DefaultJndiBindingPolicy.class"/>
+   			<include name="org/jboss/ejb3/Ejb3DeploymentSummary.class"/>
+   		    <exclude name="org/jboss/**/*Impl.class"/>
    		</fileset>
    	</jar>
 

Added: trunk/ejb3/src/main/org/jboss/annotation/ejb/JndiBindingPolicy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/annotation/ejb/JndiBindingPolicy.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/annotation/ejb/JndiBindingPolicy.java	2007-11-04 06:16:16 UTC (rev 66714)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.annotation.ejb;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.jboss.ejb3.jndipolicy.DefaultJndiBindingPolicy;
+
+/**
+ * Annotation for specifying that an EJB should use a 
+ * specified JNDI Binding Policy when determining default 
+ * JNDI names.  This policy may be overridden through optional 
+ * use of @RemoteBinding, @RemoteBindings, @RemoteHomeBinding, 
+ * @LocalBinding, @LocalBindings, @LocalHomeBinding
+ * 
+ * @author <a href="mailto:andrew.rubinger at redhat.com">ALR</a>
+ * @version $Revision: $
+ */
+ at Target(ElementType.TYPE)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface JndiBindingPolicy {
+
+   /**
+    * The JNDI Binding Policy that will be used 
+    * 
+    * @return
+    */
+   Class<? extends DefaultJndiBindingPolicy> policy();
+   
+}


Property changes on: trunk/ejb3/src/main/org/jboss/annotation/ejb/JndiBindingPolicy.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/ejb3/src/main/org/jboss/annotation/ejb/JndiBindingPolicyImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/annotation/ejb/JndiBindingPolicyImpl.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/annotation/ejb/JndiBindingPolicyImpl.java	2007-11-04 06:16:16 UTC (rev 66714)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.annotation.ejb;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.ejb3.jndipolicy.DefaultJndiBindingPolicy;
+
+/**
+ * Implementation of JndiBindingPolicy annotation
+ * 
+ * @author <a href="mailto:andrew.rubinger at redhat.com">ALR</a>
+ * @version $Revision: $
+ */
+public class JndiBindingPolicyImpl implements JndiBindingPolicy
+{
+   
+   // Instance Members
+   private Class<? extends DefaultJndiBindingPolicy> policy;
+   
+   // Contracts
+   
+   public Class<? extends DefaultJndiBindingPolicy> policy(){
+      return policy;
+   }
+   
+   public void setPolicy(Class<? extends DefaultJndiBindingPolicy> policy)
+   {
+      this.policy = policy;
+   }
+   
+   // Required Implementations
+
+   public Class<? extends Annotation> annotationType()
+   {
+      return JndiBindingPolicy.class;
+   }
+
+}


Property changes on: trunk/ejb3/src/main/org/jboss/annotation/ejb/JndiBindingPolicyImpl.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DeploymentSummary.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DeploymentSummary.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DeploymentSummary.java	2007-11-04 06:16:16 UTC (rev 66714)
@@ -0,0 +1,136 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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;
+
+import java.io.Serializable;
+
+/**
+ * Summary of an EJB3 deployment in flat properties; used in 
+ * determining default JNDI Bindings by a JNDI Binding Policy
+ * 
+ * @author <a href="mailto:andrew.rubinger at redhat.com">ALR</a>
+ * @version $Revision: $
+ */
+public class Ejb3DeploymentSummary implements Serializable
+{
+   // Instance Members
+
+   private String deploymentName;
+   
+   private String deploymentScopeBaseName;
+   
+   private String ejbName;
+   
+   private Class<?> beanClass;
+   
+   private boolean isLocal;
+   
+   private boolean isStateful;
+   
+   private boolean isHome;
+   
+   private boolean isService;
+   
+   // Accessors / Mutators
+
+   public String getDeploymentName()
+   {
+      return deploymentName;
+   }
+
+   public void setDeploymentName(String deploymentName)
+   {
+      this.deploymentName = deploymentName;
+   }
+
+   public String getEjbName()
+   {
+      return ejbName;
+   }
+
+   public void setEjbName(String ejbName)
+   {
+      this.ejbName = ejbName;
+   }
+
+   public boolean isLocal()
+   {
+      return isLocal;
+   }
+
+   public void setLocal(boolean isLocal)
+   {
+      this.isLocal = isLocal;
+   }
+
+   public boolean isStateful()
+   {
+      return isStateful;
+   }
+
+   public void setStateful(boolean isStateful)
+   {
+      this.isStateful = isStateful;
+   }
+
+   public boolean isHome()
+   {
+      return isHome;
+   }
+
+   public void setHome(boolean isHome)
+   {
+      this.isHome = isHome;
+   }
+
+   public boolean isService()
+   {
+      return isService;
+   }
+
+   public void setService(boolean isService)
+   {
+      this.isService = isService;
+   }
+
+   public String getDeploymentScopeBaseName()
+   {
+      return deploymentScopeBaseName;
+   }
+
+   public void setDeploymentScopeBaseName(String deploymentScopeBaseName)
+   {
+      this.deploymentScopeBaseName = deploymentScopeBaseName;
+   }
+
+   public Class<?> getBeanClass()
+   {
+      return beanClass;
+   }
+
+   public void setBeanClass(Class<?> beanClass)
+   {
+      this.beanClass = beanClass;
+   }
+   
+   
+}


Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DeploymentSummary.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-11-04 04:21:51 UTC (rev 66713)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-11-04 06:16:16 UTC (rev 66714)
@@ -33,6 +33,7 @@
 import javax.jws.WebService;
 import javax.management.ObjectName;
 
+import org.jboss.annotation.ejb.JndiBindingPolicy;
 import org.jboss.annotation.ejb.LocalBinding;
 import org.jboss.annotation.ejb.LocalHomeBinding;
 import org.jboss.annotation.ejb.RemoteBinding;
@@ -41,8 +42,11 @@
 import org.jboss.aop.Advisor;
 import org.jboss.ejb.LocalImpl;
 import org.jboss.ejb.RemoteImpl;
+import org.jboss.ejb3.jndipolicy.DefaultJndiBindingPolicy;
 import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.service.ServiceContainer;
 import org.jboss.ejb3.session.SessionContainer;
+import org.jboss.ejb3.stateful.StatefulContainer;
 import org.jboss.logging.Logger;
 
 /**
@@ -337,115 +341,122 @@
       return false;
    }
 
-   public static String getHomeJndiName(Container container)
-   {
-      Advisor advisor = (Advisor) container;
-      RemoteHomeBinding binding = (RemoteHomeBinding)advisor.resolveAnnotation(RemoteHomeBinding.class);
-      if (binding != null)
-         return binding.jndiBinding();
-
-      return container.getEjbName() + "/home";
-   }
-
-   public static String getLocalHomeJndiName(Container container)
-   {
-      Advisor advisor = (Advisor) container;
-      LocalHomeBinding binding = (LocalHomeBinding)advisor.resolveAnnotation(LocalHomeBinding.class);
-      if (binding != null)
-         return binding.jndiBinding();
-
-      return container.getEjbName() + "/localHome";
-   }
-
+   /**
+    * Obtains the JNDI name for the specified container; may either be explicitly-defined by 
+    * annotation / XML or will otherwise default to the configured JNDI Binding Policy
+    * 
+    * @param container
+    * @param businessInterface
+    * @return
+    */
    public static String getJndiName(Container container, Class<?> businessInterface)
    {
       assert container != null : "container is null";
       assert businessInterface != null : "businessInterface is null";
-
-      if (!(container instanceof SessionContainer)) return null;
-      Advisor advisor = (Advisor) container;
-      Class<?>[] remotes = getRemoteAndBusinessRemoteInterfaces(container);
+      
+      // Initialize to defaults of remote and not home
+      String jndiName = null;
+      boolean isHome = false;
+      boolean isLocal = false;
+      
+      // Determine if remote
+      Class<?>[] remotes = ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(container);
       for (Class<?> clazz : remotes)
       {
          if (clazz.getName().equals(businessInterface.getName()))
          {
-            RemoteBindings bindings = (RemoteBindings) advisor.resolveAnnotation(RemoteBindings.class);
-            if (bindings == null)
+            // Check for declared @RemoteBindings
+            RemoteBindings bindings = ((EJBContainer)container).getAnnotation(RemoteBindings.class);
+            if (bindings != null)
             {
-               RemoteBinding binding = (RemoteBinding) advisor.resolveAnnotation(RemoteBinding.class);
-               if (binding == null)
-                  throw new RuntimeException("RemoteBindings should not be null: " + container.getEjbName());
-
-               return getRemoteJndiName(container, binding);
+               // Encountered, return
+               return bindings.value()[0].jndiBinding();
             }
-            return getRemoteJndiName(container, bindings.value()[0]);
+            // Check for declared @RemoteBinding 
+            RemoteBinding binding = ((EJBContainer)container).getAnnotation(RemoteBinding.class);
+            if(binding!=null)
+            {
+               // Encountered, return
+               return binding.jndiBinding();
+            }
          }
       }
+      
+      // Determine if remote home
       Class<?> remoteHome = getRemoteHomeInterface(container);
       if (remoteHome != null)
       {
          if (businessInterface.getName().equals(remoteHome.getName()))
          {
-             return getHomeJndiName(container);
+            // Check for declared @RemoteHomeBinding 
+            RemoteHomeBinding binding = ((EJBContainer)container).getAnnotation(RemoteHomeBinding.class);
+            if(binding!=null)
+            {
+               // Encountered, return
+               return binding.jndiBinding();
+            } 
+            
+            // Set home for policy
+            isHome = true;
          }
       }
-      Class<?>[] locals = getLocalAndBusinessLocalInterfaces(container);
-      for (Class<?> clazz : locals)
-      {
-         if (clazz.getName().equals(businessInterface.getName()))
-         {
-            return getLocalJndiName(container);
-         }
-      }
+
+      // Determine if local and home
       Class<?> localHome = getLocalHomeInterface(container);
       if (localHome != null)
       {
          if (businessInterface.getName().equals(localHome.getName()))
          {
-             return getLocalHomeJndiName(container);
+            // Check for declared @LocalHomeBinding 
+            LocalHomeBinding binding = ((EJBContainer)container).getAnnotation(LocalHomeBinding.class);
+            if(binding!=null)
+            {
+               // Encountered, return
+               return binding.jndiBinding();
+            }
+            
+            // Set local and home for policy
+            isHome = true;
+            isLocal = true;
          }
       }
 
-      return null;
-   }
-
-   public static String getLocalJndiName(Container container)
-   {
-      return getLocalJndiName(container, true);
-   }
-
-   private static String getLocalJndiName(Container container, boolean conflictCheck)
-   {
-      Advisor advisor = (Advisor) container;
-      LocalBinding localBinding = (LocalBinding) advisor
-              .resolveAnnotation(LocalBinding.class);
-      if (localBinding == null)
+      // Determine if local
+      Class<?>[] locals = getLocalAndBusinessLocalInterfaces(container);
+      for (Class<?> clazz : locals)
       {
-         String name = container.getEjbName() + "/local";
-         DeploymentScope deploymentScope = ((EJBContainer) container).getDeployment().getEar();
-         if (deploymentScope != null) return deploymentScope.getBaseName() + "/" + name;
-
-         if (conflictCheck)
-            checkForRemoteJndiConflict(container);
-
-         return name;
+         if (clazz.getName().equals(businessInterface.getName()))
+         {
+            // Check for declared @LocalBinding 
+            LocalBinding binding = ((EJBContainer)container).getAnnotation(LocalBinding.class);
+            if(binding!=null)
+            {
+               // Encountered, return
+               return binding.jndiBinding();
+            }
+            
+            // Set local for policy
+            isLocal = true;
+         }
       }
-      else
+      
+      // If JNDI Name has not been explicitly specified, use policy
+      if (jndiName == null)
       {
-         return localBinding.jndiBinding();
+         // Log 
+         log.debug("JNDI name has not been explicitly set for EJB " + container.getEjbName() + ", interface "
+               + businessInterface.getName());
+         
+         // Set JNDI name
+         Ejb3DeploymentSummary summary = ProxyFactoryHelper.getDeploymentSummaryFromContainer(container);
+         summary.setHome(isHome);
+         summary.setLocal(isLocal);
+         jndiName = ProxyFactoryHelper.getJndiBindingPolicy(container).getJndiName(summary);
       }
+      
+      // Return
+      return jndiName;
    }
-
-   private static void checkForRemoteJndiConflict(Container container)
-   {
-      if (((Advisor) container).resolveAnnotation(Remote.class) != null)
-      {
-         String remoteJndiName = getRemoteJndiName(container, false);
-         String ejbName = container.getEjbName();
-         if ((remoteJndiName.equals(ejbName) || remoteJndiName.startsWith(ejbName + "/")) && (!remoteJndiName.equals(ejbName + "/remote")))
-            throw new javax.ejb.EJBException("Conflict between default local jndi name " + ejbName + "/local and remote jndi name " + remoteJndiName + " for ejb-name:" + ejbName + ", bean class=" + container.getBeanClass());
-      }
-   }
    
    /**
     * Returns all local interfaces in the specified container; interfaces
@@ -583,6 +594,91 @@
       return rtn;
    }
 
+   public static String getClientBindUrl(RemoteBinding binding) throws Exception
+   {
+      String clientBindUrl = binding.clientBindUrl();
+      if (clientBindUrl.trim().length() == 0)
+      {
+         ObjectName connectionON = new ObjectName("jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3");
+         KernelAbstraction kernelAbstraction = KernelAbstractionFactory.getInstance();
+         try
+         {
+            clientBindUrl = (String)kernelAbstraction.getAttribute(connectionON, "InvokerLocator");
+            if (clientBindUrl == null)
+               clientBindUrl = RemoteProxyFactory.DEFAULT_CLIENT_BINDING;
+         }
+         catch (Exception e)
+         {
+            clientBindUrl = RemoteProxyFactory.DEFAULT_CLIENT_BINDING;
+         }
+      }
+     
+      return clientBindUrl;
+   }
+   
+   public static String getHomeJndiName(Container container)
+   {
+      // Initialize
+      Advisor advisor = (Advisor) container;
+      
+      // Use explicitly-specified binding, if defined
+      RemoteHomeBinding binding = (RemoteHomeBinding)advisor.resolveAnnotation(RemoteHomeBinding.class);
+      if (binding != null)
+         return binding.jndiBinding();
+      
+      // Use Default JNDI Binding Policy
+      return ProxyFactoryHelper.getJndiBindingPolicy(container).getDefaultRemoteHomeJndiName(
+            ProxyFactoryHelper.getDeploymentSummaryFromContainer(container));
+   }
+
+   public static String getLocalHomeJndiName(Container container)
+   {
+      // Initialize
+      Advisor advisor = (Advisor) container;
+      
+      // Use explicitly-specified binding, if defined
+      LocalHomeBinding binding = (LocalHomeBinding)advisor.resolveAnnotation(LocalHomeBinding.class);
+      if (binding != null)
+         return binding.jndiBinding();
+
+      // Use Default JNDI Binding Policy
+      return ProxyFactoryHelper.getJndiBindingPolicy(container).getDefaultLocalHomeJndiName(
+            ProxyFactoryHelper.getDeploymentSummaryFromContainer(container));
+   }
+   
+   public static String getLocalJndiName(Container container)
+   {
+      return getLocalJndiName(container, true);
+   }
+
+   private static String getLocalJndiName(Container container, boolean conflictCheck)
+   {
+      // Initialize
+      Advisor advisor = (Advisor) container;
+      
+      // See if local binding is explicitly-defined
+      LocalBinding localBinding = (LocalBinding) advisor
+              .resolveAnnotation(LocalBinding.class);
+      
+      // If none specified
+      if (localBinding == null)
+      {
+         // Get JNDI name from policy
+         String name = ProxyFactoryHelper.getJndiBindingPolicy(container).getDefaultLocalJndiName(
+               ProxyFactoryHelper.getDeploymentSummaryFromContainer(container));
+
+         if (conflictCheck)
+            checkForJndiNamingConflict(container);
+
+         return name;
+      }
+      // Local Binding was explicitly-specified, use it
+      else
+      {
+         return localBinding.jndiBinding();
+      }
+   }
+   
    public static String getRemoteJndiName(Container container)
    {
       return getRemoteJndiName(container, true);
@@ -597,14 +693,19 @@
       return getRemoteJndiName(container, binding);
    }
 
-   private static void checkForLocalJndiConflict(Container container)
+   private static void checkForJndiNamingConflict(Container container)
    {
       if (((Advisor) container).resolveAnnotation(Local.class) != null)
       {
-         String localJndiName = getLocalJndiName(container, false);
+         Ejb3DeploymentSummary summary = ProxyFactoryHelper.getDeploymentSummaryFromContainer(container);
+         String localJndiName = ProxyFactoryHelper.getJndiBindingPolicy(container).getDefaultLocalJndiName(summary);
+         String remoteJndiName = ProxyFactoryHelper.getJndiBindingPolicy(container).getDefaultRemoteJndiName(summary);
          String ejbName = container.getEjbName();
-         if ((localJndiName.equals(ejbName) || localJndiName.startsWith(ejbName + "/")) && (!localJndiName.equals(ejbName + "/local")))
-            throw new javax.ejb.EJBException("Conflict between default remote jndi name " + ejbName + "/remote and local jndi name " + localJndiName + " for ejb-name:" + ejbName + ", bean class=" + container.getBeanClass());
+         if ((localJndiName.equals(remoteJndiName)))
+         {
+            throw new javax.ejb.EJBException("Conflict between default jndi name " + remoteJndiName
+                  + " for both remote and local for ejb-name:" + ejbName + ", bean class=" + container.getBeanClass());
+         }
 
       }
    }
@@ -622,7 +723,7 @@
          jndiName = getDefaultRemoteJndiName(container);
 
          if (conflictCheck)
-            checkForLocalJndiConflict(container);
+            checkForJndiNamingConflict(container);
       }
       else
       {
@@ -634,31 +735,53 @@
 
    public static String getDefaultRemoteJndiName(Container container)
    {
-      String name = container.getEjbName() + "/remote";
-      DeploymentScope deploymentScope = ((EJBContainer) container).getDeployment().getEar();
-      if (deploymentScope != null) return deploymentScope.getBaseName() + "/" + name;
-      return name;
+      return ProxyFactoryHelper.getJndiBindingPolicy(container).getDefaultRemoteJndiName(
+            ProxyFactoryHelper.getDeploymentSummaryFromContainer(container));
    }
-
-   public static String getClientBindUrl(RemoteBinding binding) throws Exception
+   
+   /**
+    * Obtains the JNDI Binding Policy for the specified container
+    * 
+    * @param container
+    * @author ALR
+    * @return
+    */
+   private static DefaultJndiBindingPolicy getJndiBindingPolicy(Container container)
    {
-      String clientBindUrl = binding.clientBindUrl();
-      if (clientBindUrl.trim().length() == 0)
+      Class<? extends DefaultJndiBindingPolicy> policy = ((EJBContainer) container).getAnnotation(
+            JndiBindingPolicy.class).policy();
+      log.debug("Obtaining JNDI name from policy " + policy.getName());
+      try
       {
-         ObjectName connectionON = new ObjectName("jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3");
-         KernelAbstraction kernelAbstraction = KernelAbstractionFactory.getInstance();
-         try
+         return policy.newInstance();
+      }
+      catch (InstantiationException e)
+      {
+         throw new RuntimeException("Could not instanciate JNDI Binding Policy: " + policy.getName(), e);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   private static Ejb3DeploymentSummary getDeploymentSummaryFromContainer(Container container)
+   {
+      // Construct Deployment Summary
+      Ejb3DeploymentSummary summary = new Ejb3DeploymentSummary();
+      summary.setEjbName(container.getEjbName());
+      summary.setService(container instanceof ServiceContainer);
+      summary.setStateful(container instanceof StatefulContainer);
+      summary.setDeploymentName(((EJBContainer) container).getDeployment().getName());
+      summary.setBeanClass(container.getBeanClass());
+      if (container instanceof EJBContainer)
+      {
+         DeploymentScope scope = ((EJBContainer) container).getDeployment().getEar();
+         if (scope != null)
          {
-            clientBindUrl = (String)kernelAbstraction.getAttribute(connectionON, "InvokerLocator");
-            if (clientBindUrl == null)
-               clientBindUrl = RemoteProxyFactory.DEFAULT_CLIENT_BINDING;
+            summary.setDeploymentScopeBaseName(scope.getBaseName());
          }
-         catch (Exception e)
-         {
-            clientBindUrl = RemoteProxyFactory.DEFAULT_CLIENT_BINDING;
-         }
       }
-     
-      return clientBindUrl;
+      return summary;
    }
 }
\ No newline at end of file

Added: trunk/ejb3/src/main/org/jboss/ejb3/jndipolicy/DefaultJndiBindingPolicy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/jndipolicy/DefaultJndiBindingPolicy.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/jndipolicy/DefaultJndiBindingPolicy.java	2007-11-04 06:16:16 UTC (rev 66714)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.jndipolicy;
+
+import org.jboss.ejb3.Ejb3DeploymentSummary;
+
+/**
+ * Defines the contract required for implementations of a default JNDI binding policy
+ * 
+ * @author <a href="mailto:andrew.rubinger at redhat.com">ALR</a>
+ * @version $Revision: $
+ */
+public interface DefaultJndiBindingPolicy
+{
+   /**
+    * Returns the JNDI name that should be assigned to this deployment
+    * based on the information contained in the specified summary
+    * 
+    * @param summary
+    * @return
+    */
+   String getJndiName(Ejb3DeploymentSummary summary);
+   
+   String getDefaultRemoteJndiName(Ejb3DeploymentSummary summary);
+
+   String getDefaultRemoteHomeJndiName(Ejb3DeploymentSummary summary);
+
+   String getDefaultLocalHomeJndiName(Ejb3DeploymentSummary summary);
+
+   String getDefaultLocalJndiName(Ejb3DeploymentSummary summary);
+}


Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/jndipolicy/DefaultJndiBindingPolicy.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/ejb3/src/main/org/jboss/ejb3/jndipolicy/PackagingBasedJndiBindingPolicy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/jndipolicy/PackagingBasedJndiBindingPolicy.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/jndipolicy/PackagingBasedJndiBindingPolicy.java	2007-11-04 06:16:16 UTC (rev 66714)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.jndipolicy;
+
+import org.jboss.ejb3.Ejb3DeploymentSummary;
+
+/**
+ * The JBoss Default JNDI Binding Policy
+ * 
+ * Determines JNDI name of EJBs based on packaging structure, 
+ * EJB name, and local/remote designation
+ * 
+ * @author <a href="mailto:andrew.rubinger at redhat.com">ALR</a>
+ * @version $Revision: $
+ */
+public class PackagingBasedJndiBindingPolicy implements DefaultJndiBindingPolicy
+{
+   // Class Members
+
+   private static final String JNDI_SUFFIX_REMOTE = "/remote";
+
+   private static final String JNDI_SUFFIX_LOCAL = "/local";
+
+   private static final String JNDI_SUFFIX_REMOTE_HOME = "/home";
+
+   private static final String JNDI_SUFFIX_LOCAL_HOME = "/localHome";
+
+   // Required Implementations
+
+   public String getJndiName(Ejb3DeploymentSummary summary)
+   {
+      // If Remote / Remote Business
+      if (!summary.isLocal())
+      {
+         // If Home
+         if (summary.isHome())
+         {
+            return this.getDefaultRemoteHomeJndiName(summary);
+         }
+         // Business / Remote
+         else
+         {
+            return this.getDefaultRemoteJndiName(summary);
+         }
+
+      }
+      else
+      {
+         if (summary.isHome())
+         {
+            return this.getDefaultLocalHomeJndiName(summary);
+         }
+         else
+         {
+            return this.getDefaultLocalJndiName(summary);
+         }
+      }
+   }
+
+   public String getDefaultRemoteJndiName(Ejb3DeploymentSummary summary)
+   {
+      
+      String name = summary.getEjbName() + PackagingBasedJndiBindingPolicy.JNDI_SUFFIX_REMOTE;
+      if (summary.getDeploymentScopeBaseName() != null)
+         name = summary.getDeploymentScopeBaseName() + "/" + name;
+      return name;
+   }
+
+   public String getDefaultRemoteHomeJndiName(Ejb3DeploymentSummary summary)
+   {
+      return summary.getEjbName() + PackagingBasedJndiBindingPolicy.JNDI_SUFFIX_REMOTE_HOME;
+   }
+
+   public String getDefaultLocalHomeJndiName(Ejb3DeploymentSummary summary)
+   {
+      return summary.getEjbName() + PackagingBasedJndiBindingPolicy.JNDI_SUFFIX_LOCAL_HOME;
+   }
+
+   public String getDefaultLocalJndiName(Ejb3DeploymentSummary summary)
+   {
+      String name = summary.getEjbName() + PackagingBasedJndiBindingPolicy.JNDI_SUFFIX_LOCAL;
+      if (summary.getDeploymentScopeBaseName() != null)
+         name = summary.getDeploymentScopeBaseName() + "/" + name;
+      return name;
+   }
+
+}


Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/jndipolicy/PackagingBasedJndiBindingPolicy.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/ejb3/src/resources/ejb3-interceptors-aop.xml
===================================================================
--- trunk/ejb3/src/resources/ejb3-interceptors-aop.xml	2007-11-04 04:21:51 UTC (rev 66713)
+++ trunk/ejb3/src/resources/ejb3-interceptors-aop.xml	2007-11-04 06:16:16 UTC (rev 66714)
@@ -110,6 +110,9 @@
       <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
          @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
       </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.JndiBindingPolicy)">
+         @org.jboss.annotation.ejb.JndiBindingPolicy (policy=org.jboss.ejb3.jndipolicy.PackagingBasedJndiBindingPolicy.class)
+      </annotation>
    </domain>
 
    <domain name="JACC Stateless Bean">
@@ -138,6 +141,9 @@
       <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
          @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
       </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.JndiBindingPolicy)">
+         @org.jboss.annotation.ejb.JndiBindingPolicy (policy=org.jboss.ejb3.jndipolicy.PackagingBasedJndiBindingPolicy.class)
+      </annotation>
    </domain>
 
    <domain name="Base Stateful Bean">
@@ -183,6 +189,9 @@
       <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
          @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
       </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.JndiBindingPolicy)">
+         @org.jboss.annotation.ejb.JndiBindingPolicy (policy=org.jboss.ejb3.jndipolicy.PackagingBasedJndiBindingPolicy.class)
+      </annotation>
    </domain>
 
    <domain name="Stateful Bean" extends="Base Stateful Bean" inheritBindings="true">
@@ -245,6 +254,9 @@
       <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
          @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
       </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.JndiBindingPolicy)">
+         @org.jboss.annotation.ejb.JndiBindingPolicy (policy=org.jboss.ejb3.jndipolicy.PackagingBasedJndiBindingPolicy.class)
+      </annotation>
 
       <!-- NON Clustered cache configuration -->
       <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache) AND !class(@org.jboss.annotation.ejb.Clustered)">
@@ -271,6 +283,9 @@
       <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache)">
          @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.NoPassivationCache.class)
       </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.JndiBindingPolicy)">
+         @org.jboss.annotation.ejb.JndiBindingPolicy (policy=org.jboss.ejb3.jndipolicy.PackagingBasedJndiBindingPolicy.class)
+      </annotation>
 
    </domain>
 
@@ -290,6 +305,9 @@
       <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
          @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=15, timeout=10000)
       </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.JndiBindingPolicy)">
+         @org.jboss.annotation.ejb.JndiBindingPolicy (policy=org.jboss.ejb3.jndipolicy.PackagingBasedJndiBindingPolicy.class)
+      </annotation>
    </domain>
 
    <domain name="Consumer Bean">
@@ -311,6 +329,9 @@
       <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
          @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=15, timeout=10000)
       </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.JndiBindingPolicy)">
+         @org.jboss.annotation.ejb.JndiBindingPolicy (policy=org.jboss.ejb3.jndipolicy.PackagingBasedJndiBindingPolicy.class)
+      </annotation>
    </domain>
 
    <domain name="Service Bean">
@@ -336,6 +357,9 @@
       <bind pointcut="execution(public * *->*(..)) AND !execution(* *->create()) AND !execution(* *->start())">
          <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
       </bind>
+      <annotation expr="!class(@org.jboss.annotation.ejb.JndiBindingPolicy)">
+         @org.jboss.annotation.ejb.JndiBindingPolicy (policy=org.jboss.ejb3.jndipolicy.PackagingBasedJndiBindingPolicy.class)
+      </annotation>
    </domain>
 
    <domain name="JACC Service Bean">
@@ -361,6 +385,9 @@
       <bind pointcut="execution(public * *->*(..)) AND !execution(* *->create()) AND !execution(* *->start())">
          <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
       </bind>
+      <annotation expr="!class(@org.jboss.annotation.ejb.JndiBindingPolicy)">
+         @org.jboss.annotation.ejb.JndiBindingPolicy (policy=org.jboss.ejb3.jndipolicy.PackagingBasedJndiBindingPolicy.class)
+      </annotation>
    </domain>
 
 

Modified: trunk/ejb3/src/resources/test/defaultremotebindings/default-ejb3-interceptors-aop.xml
===================================================================
--- trunk/ejb3/src/resources/test/defaultremotebindings/default-ejb3-interceptors-aop.xml	2007-11-04 04:21:51 UTC (rev 66713)
+++ trunk/ejb3/src/resources/test/defaultremotebindings/default-ejb3-interceptors-aop.xml	2007-11-04 06:16:16 UTC (rev 66714)
@@ -39,6 +39,9 @@
          <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
          <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
       </bind>
+      <annotation expr="!class(@org.jboss.annotation.ejb.JndiBindingPolicy)">
+         @org.jboss.annotation.ejb.JndiBindingPolicy (policy=org.jboss.ejb3.jndipolicy.PackagingBasedJndiBindingPolicy.class)
+      </annotation>
       <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
          @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
       </annotation>




More information about the jboss-cvs-commits mailing list