[jboss-cvs] JBossAS SVN: r61304 - in trunk/ejb3/src: main/org/jboss/ejb3/stateless and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 13 15:34:36 EDT 2007


Author: bdecoste
Date: 2007-03-13 15:34:36 -0400 (Tue, 13 Mar 2007)
New Revision: 61304

Added:
   trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/DuplicateStatefulBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/DuplicateStatelessBean.java
Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/Test.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/TestBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/unit/HomeTestCase.java
Log:
[JBCTS-540] merged changes from 4.2 - home and business interfaces can be bound to same name which creates one proxy

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2007-03-13 19:33:29 UTC (rev 61303)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2007-03-13 19:34:36 UTC (rev 61304)
@@ -42,14 +42,36 @@
    protected Class[] getInterfaces()
    {
       Class[] interfaces;
-
+      
+      StatefulContainer statefulContainer = (StatefulContainer) container;
+      LocalHome localHome = (LocalHome) statefulContainer.resolveAnnotation(LocalHome.class);
+      
+      boolean bindTogether = false;
+      
+      if (localHome != null && bindHomeAndBusinessTogether(statefulContainer))
+         bindTogether = true;
+      
       Class[] localInterfaces = ProxyFactoryHelper.getLocalInterfaces(container);
-      interfaces = new Class[localInterfaces.length + 2];
+      if (bindTogether)
+         interfaces = new Class[localInterfaces.length + 3];
+      else
+         interfaces = new Class[localInterfaces.length + 2];
+      
       System.arraycopy(localInterfaces, 0, interfaces, 0, localInterfaces.length);
       interfaces[localInterfaces.length] = JBossProxy.class;
       interfaces[localInterfaces.length + 1] = javax.ejb.EJBLocalObject.class;
+      
+      if (bindTogether)
+         interfaces[localInterfaces.length + 2] = localHome.value();
+      
       return interfaces;
+
    }
+   
+   protected boolean bindHomeAndBusinessTogether(StatefulContainer container)
+   {
+      return ProxyFactoryHelper.getLocalHomeJndiName(container).equals(ProxyFactoryHelper.getLocalJndiName(container));
+   }
 
    protected void initializeJndiName()
    {
@@ -71,8 +93,9 @@
          throw namingException;
       }
 
+      StatefulContainer statefulContainer = (StatefulContainer) container;
       LocalHome localHome = (LocalHome) ((EJBContainer) container).resolveAnnotation(LocalHome.class);
-      if (localHome != null)
+      if (localHome != null && !bindHomeAndBusinessTogether(statefulContainer))
       {
          Class[] interfaces = {localHome.value()};
          Object homeProxy = java.lang.reflect.Proxy.newProxyInstance(container.getBeanClass().getClassLoader(),
@@ -85,8 +108,9 @@
    {
       super.stop();
       NonSerializableFactory.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME);
+      StatefulContainer statefulContainer = (StatefulContainer) container;
       LocalHome localHome = (LocalHome) ((EJBContainer) container).resolveAnnotation(LocalHome.class);
-      if (localHome != null)
+      if (localHome != null && !bindHomeAndBusinessTogether(statefulContainer))
       {
          NonSerializableFactory.unbind(container.getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(container));
       }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-03-13 19:33:29 UTC (rev 61303)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-03-13 19:34:36 UTC (rev 61304)
@@ -59,15 +59,35 @@
    protected Class[] getInterfaces()
    {
       Class[] interfaces;
-
+      
+      StatefulContainer statefulContainer = (StatefulContainer) container;
+      RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
+      
+      boolean bindTogether = false;
+      
+      if (remoteHome != null && bindHomeAndBusinessTogether(statefulContainer))
+         bindTogether = true;
+      
       Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
+      if (bindTogether)
+         interfaces = new Class[remoteInterfaces.length + 3];
+      else
          interfaces = new Class[remoteInterfaces.length + 2];
 
       System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length);
       interfaces[remoteInterfaces.length] = JBossProxy.class;
       interfaces[remoteInterfaces.length + 1] = javax.ejb.EJBObject.class;
+      if (bindTogether)
+         interfaces[remoteInterfaces.length + 2] = remoteHome.value();
+         
       return interfaces;
+
    }
+   
+   protected boolean bindHomeAndBusinessTogether(StatefulContainer container)
+   {
+      return ProxyFactoryHelper.getHomeJndiName(container).equals(ProxyFactoryHelper.getRemoteJndiName(container));
+   }
 
    protected void initializeJndiName()
    {
@@ -102,7 +122,7 @@
 
       StatefulContainer statefulContainer = (StatefulContainer) container;
       RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
-      if (remoteHome != null)
+      if (remoteHome != null && !bindHomeAndBusinessTogether(statefulContainer))
       {
          Object homeProxy = createHomeProxy(remoteHome.value());
          Util.rebind(container.getInitialContext(), ProxyFactoryHelper.getHomeJndiName(container), homeProxy);
@@ -115,7 +135,7 @@
       Dispatcher.singleton.unregisterTarget(jndiName + PROXY_FACTORY_NAME);
       StatefulContainer statefulContainer = (StatefulContainer) container;
       RemoteHome remoteHome = (RemoteHome) statefulContainer.resolveAnnotation(RemoteHome.class);
-      if (remoteHome != null)
+      if (remoteHome != null && !bindHomeAndBusinessTogether(statefulContainer))
       {
          Util.unbind(container.getInitialContext(), ProxyFactoryHelper.getHomeJndiName(container));
       }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2007-03-13 19:33:29 UTC (rev 61303)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2007-03-13 19:34:36 UTC (rev 61304)
@@ -41,17 +41,36 @@
    protected Class[] getInterfaces()
    {
       Class[] interfaces;
-
+      
+      EJBContainer statelessContainer = (EJBContainer) container;
+      LocalHome localHome = (LocalHome) statelessContainer.resolveAnnotation(LocalHome.class);
+      
+      boolean bindTogether = false;
+      
+      if (localHome != null && bindHomeAndBusinessTogether(statelessContainer))
+         bindTogether = true;
+      
       Class[] localInterfaces = ProxyFactoryHelper.getLocalInterfaces(container);
-      EJBContainer statelessContainer = (EJBContainer) container;
-      interfaces = new Class[localInterfaces.length + 2];
+      
+      if (bindTogether)
+         interfaces = new Class[localInterfaces.length + 3];
+      else
+         interfaces = new Class[localInterfaces.length + 2];
 
       System.arraycopy(localInterfaces, 0, interfaces, 0, localInterfaces.length);
       interfaces[localInterfaces.length] = JBossProxy.class;
       interfaces[localInterfaces.length + 1] = javax.ejb.EJBLocalObject.class;
+      if (bindTogether)
+         interfaces[localInterfaces.length + 2] = localHome.value();
 
       return interfaces;
+
    }
+   
+   protected boolean bindHomeAndBusinessTogether(EJBContainer container)
+   {
+      return ProxyFactoryHelper.getLocalHomeJndiName(container).equals(ProxyFactoryHelper.getLocalJndiName(container));
+   }
 
    protected void initializeJndiName()
    {
@@ -64,7 +83,7 @@
       super.start();
       EJBContainer statelessContainer = (EJBContainer) container;
       LocalHome localHome = (LocalHome) statelessContainer.resolveAnnotation(LocalHome.class);
-      if (localHome != null)
+      if (localHome != null && !bindHomeAndBusinessTogether(statelessContainer))
       {
          Class[] interfaces = {localHome.value()};
          Object homeProxy = java.lang.reflect.Proxy.newProxyInstance(container.getBeanClass().getClassLoader(),
@@ -79,7 +98,7 @@
       super.stop();
       EJBContainer statelessContainer = (EJBContainer) container;
       LocalHome localHome = (LocalHome) statelessContainer.resolveAnnotation(LocalHome.class);
-      if (localHome != null)
+      if (localHome != null && !bindHomeAndBusinessTogether(statelessContainer))
       {
          NonSerializableFactory.unbind(container.getInitialContext(), ProxyFactoryHelper.getLocalHomeJndiName(container));
       }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2007-03-13 19:33:29 UTC (rev 61303)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2007-03-13 19:34:36 UTC (rev 61304)
@@ -57,16 +57,38 @@
    protected Class[] getInterfaces()
    {
       Class[] interfaces;
-
+      
+      StatelessContainer statelessContainer = (StatelessContainer) container;
+      RemoteHome remoteHome = (RemoteHome) statelessContainer.resolveAnnotation(RemoteHome.class);
+      
+      boolean bindTogether = false;
+      
+      if (remoteHome != null && bindHomeAndBusinessTogether(statelessContainer))
+         bindTogether = true;
+      
       Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
-      interfaces = new Class[remoteInterfaces.length + 2];
-
-      System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length);
+      
+      if (bindTogether)
+         interfaces = new Class[remoteInterfaces.length + 3];
+      else
+         interfaces = new Class[remoteInterfaces.length + 2];
+      
+      System.arraycopy(remoteInterfaces, 0, interfaces, 0,
+            remoteInterfaces.length);
       interfaces[remoteInterfaces.length] = JBossProxy.class;
       interfaces[remoteInterfaces.length + 1] = javax.ejb.EJBObject.class;
+      
+      if (bindTogether)
+         interfaces[remoteInterfaces.length + 2] = remoteHome.value();
 
       return interfaces;
+
    }
+   
+   protected boolean bindHomeAndBusinessTogether(EJBContainer container)
+   {
+      return ProxyFactoryHelper.getHomeJndiName(container).equals(ProxyFactoryHelper.getRemoteJndiName(container));
+   }
 
    protected void initializeJndiName()
    {
@@ -85,7 +107,7 @@
       super.start();
       EJBContainer statelessContainer = (EJBContainer) container;
       RemoteHome remoteHome = (RemoteHome) statelessContainer.resolveAnnotation(RemoteHome.class);
-      if (remoteHome != null)
+      if (remoteHome != null && !bindHomeAndBusinessTogether(statelessContainer))
       {
          Object homeProxy = createHomeProxy(remoteHome.value());
          try
@@ -107,7 +129,7 @@
       super.stop();
       EJBContainer statelessContainer = (EJBContainer) container;
       RemoteHome remoteHome = (RemoteHome) statelessContainer.resolveAnnotation(RemoteHome.class);
-      if (remoteHome != null)
+      if (remoteHome != null && !bindHomeAndBusinessTogether(statelessContainer))
       {
          Util.unbind(container.getInitialContext(), ProxyFactoryHelper.getHomeJndiName(container));
       }

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/DuplicateStatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/DuplicateStatefulBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/DuplicateStatefulBean.java	2007-03-13 19:34:36 UTC (rev 61304)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.homeinterface;
+
+import javax.ejb.Local;
+import javax.ejb.LocalHome;
+import javax.ejb.Remote;
+import javax.ejb.RemoteHome;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.LocalHomeBinding;
+import org.jboss.annotation.ejb.RemoteHomeBinding;
+import org.jboss.annotation.ejb.LocalBinding;
+import org.jboss.annotation.ejb.RemoteBinding;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful
+ at Remote(RemoteInterface.class)
+ at RemoteBinding(jndiBinding="DuplicateStateful")
+ at RemoteHomeBinding(jndiBinding="DuplicateStateful")
+ at RemoteHome(Home.class)
+ at Local(LocalInterface.class)
+ at LocalBinding(jndiBinding="DuplicateStatefulLocal")
+ at LocalHomeBinding(jndiBinding="DuplicateStatefulLocal")
+ at LocalHome(org.jboss.ejb3.test.homeinterface.LocalHome.class)
+public class DuplicateStatefulBean implements RemoteInterface, LocalInterface
+{
+   private static final Logger log = Logger.getLogger(DuplicateStatefulBean.class);
+    
+   public void test() 
+   {
+   }
+   
+   public void testLocal() 
+   {
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/DuplicateStatelessBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/DuplicateStatelessBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/DuplicateStatelessBean.java	2007-03-13 19:34:36 UTC (rev 61304)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.homeinterface;
+
+import javax.ejb.Local;
+import javax.ejb.LocalHome;
+import javax.ejb.Remote;
+import javax.ejb.RemoteHome;
+import javax.ejb.Stateless;
+
+import org.jboss.annotation.ejb.LocalHomeBinding;
+import org.jboss.annotation.ejb.RemoteHomeBinding;
+import org.jboss.annotation.ejb.LocalBinding;
+import org.jboss.annotation.ejb.RemoteBinding;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateless
+ at Remote(RemoteInterface.class)
+ at RemoteBinding(jndiBinding="DuplicateStateless")
+ at RemoteHomeBinding(jndiBinding="DuplicateStateless")
+ at RemoteHome(Home.class)
+ at Local(LocalInterface.class)
+ at LocalBinding(jndiBinding="DuplicateStatelessLocal")
+ at LocalHomeBinding(jndiBinding="DuplicateStatelessLocal")
+ at LocalHome(org.jboss.ejb3.test.homeinterface.LocalHome.class)
+public class DuplicateStatelessBean implements RemoteInterface, LocalInterface
+{
+   private static final Logger log = Logger.getLogger(DuplicateStatelessBean.class);
+    
+   public void test() 
+   {
+   }
+   
+   public void testLocal() 
+   {
+   }
+}

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/Test.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/Test.java	2007-03-13 19:33:29 UTC (rev 61303)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/Test.java	2007-03-13 19:34:36 UTC (rev 61304)
@@ -37,4 +37,9 @@
    void testExplicitStatefulLocal() throws Exception;
    
    void testDescriptorStatefulLocal() throws Exception;
+   
+   void testDuplicateStatelessLocal() throws Exception;
+   
+   void testDuplicateStatefulLocal() throws Exception;
+
 }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/TestBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/TestBean.java	2007-03-13 19:33:29 UTC (rev 61303)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/TestBean.java	2007-03-13 19:34:36 UTC (rev 61304)
@@ -108,4 +108,27 @@
       local = (LocalInterface)jndiContext.lookup("DescriptorStatefulBean/local");
       local.testLocal();
    }
+   
+   public void testDuplicateStatelessLocal() throws Exception
+   {
+      InitialContext jndiContext = new InitialContext();
+      LocalHome home = (LocalHome)jndiContext.lookup("DuplicateStatelessLocal");
+      LocalInterface local = home.create();
+      local.testLocal();
+      
+      local = (LocalInterface)jndiContext.lookup("DuplicateStatelessLocal");
+      local.testLocal();
+   }
+   
+   public void testDuplicateStatefulLocal() throws Exception
+   {
+      InitialContext jndiContext = new InitialContext();
+      LocalHome home = (LocalHome)jndiContext.lookup("DuplicateStatefulLocal");
+      LocalInterface local = home.create();
+      local.testLocal();
+      
+      local = (LocalInterface)jndiContext.lookup("DuplicateStatefulLocal");
+      local.testLocal();
+   }
+
 }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/unit/HomeTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/unit/HomeTestCase.java	2007-03-13 19:33:29 UTC (rev 61303)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/homeinterface/unit/HomeTestCase.java	2007-03-13 19:34:36 UTC (rev 61304)
@@ -126,6 +126,35 @@
       test.testDescriptorStatefulLocal();
    }
    
+   public void testDuplicateStateful() throws Exception
+   {
+      InitialContext jndiContext = new InitialContext();
+      Home home = (Home)jndiContext.lookup("DuplicateStateful");
+      RemoteInterface remote = home.create();
+      remote.test();
+      
+      remote = (RemoteInterface)jndiContext.lookup("DuplicateStateful");
+      remote.test();
+      
+      Test test = (Test)jndiContext.lookup("TestBean/remote");
+      test.testDuplicateStatefulLocal();
+   }
+   
+   public void testDuplicateStateless() throws Exception
+   {
+      InitialContext jndiContext = new InitialContext();
+      Home home = (Home)jndiContext.lookup("DuplicateStateless");
+      RemoteInterface remote = home.create();
+      remote.test();
+      
+      remote = (RemoteInterface)jndiContext.lookup("DuplicateStateless");
+      remote.test();
+      
+      Test test = (Test)jndiContext.lookup("TestBean/remote");
+      test.testDuplicateStatelessLocal();
+   }
+
+   
    public static junit.framework.Test suite() throws Exception
    {
       return getDeploySetup(HomeTestCase.class, "homeinterface-test.jar");




More information about the jboss-cvs-commits mailing list