[jboss-cvs] JBossAS SVN: r80925 - in projects/ejb3/trunk/core/src: main/java/org/jboss/ejb3/stateful and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 13 06:31:54 EST 2008


Author: wolfc
Date: 2008-11-13 06:31:54 -0500 (Thu, 13 Nov 2008)
New Revision: 80925

Added:
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolder.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolderBean.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolderHome.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/unit/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/unit/StatefulLocalCreate21TestCase.java
Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
Log:
EJBTHREE-1585: refactored home create method

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java	2008-11-13 11:24:27 UTC (rev 80924)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java	2008-11-13 11:31:54 UTC (rev 80925)
@@ -172,7 +172,7 @@
 
          if (unadvisedMethod != null && isHomeMethod(unadvisedSerializableMethod))
          {
-            return invokeHomeMethod(method, args);
+            return invokeHomeMethod(actualMethod, args);
          }
          else if (unadvisedMethod != null && this.isEjbObjectMethod(unadvisedSerializableMethod))
          {
@@ -347,7 +347,7 @@
     * @return
     * @throws Exception
     */
-   protected Object invokeHomeCreate(SerializableMethod method, Object args[]) throws Exception
+   protected Object invokeHomeCreate(Method method, Object args[]) throws Exception
    {
 
       /*
@@ -361,7 +361,7 @@
       boolean foundInterface = false;
 
       // Name of the EJB2.x Interface Class expected
-      String ejb2xInterface = method.getReturnType();
+      String ejb2xInterface = method.getReturnType().getName();
 
       // Get Metadata
       JBossSessionBeanMetaData smd = this.getMetaData();
@@ -423,7 +423,7 @@
     * TODO: work in progress (refactor both invokeHomeMethod's, localHomeInvoke)
     */
    //TODO
-   private Object invokeHomeMethod(SerializableMethod method, Object args[]) throws Exception
+   private Object invokeHomeMethod(Method method, Object args[]) throws Exception
    {
       if (method.getName().equals(Ejb2xMethodNames.METHOD_NAME_HOME_CREATE))
       {

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java	2008-11-13 11:24:27 UTC (rev 80924)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java	2008-11-13 11:31:54 UTC (rev 80925)
@@ -1140,6 +1140,74 @@
       return isAnnotationPresent(Clustered.class);
    }
 
+   @Override
+   protected Object invokeHomeCreate(Method method, Object[] args) throws Exception
+   {
+      // TODO: this is almost identical to SessionSpecContainer.invokeHomeCreate, so unify
+      
+      // Hold the JNDI Name
+      String jndiName = null;
+
+      // Flag for if we've found the interface
+      boolean foundInterface = false;
+
+      // Name of the EJB2.x Interface Class expected
+      String ejb2xInterface = method.getReturnType().getName();
+
+      // Get Metadata
+      JBossSessionBeanMetaData smd = this.getMetaData();
+
+      /*
+       * Determine if the expected type is found in metadata as a EJB2.x Interface 
+       */
+
+      // Is this a Remote Interface ?
+      boolean isLocal = false;
+      String ejb2xRemoteInterface = smd.getRemote();
+      if (ejb2xInterface.equals(ejb2xRemoteInterface))
+      {
+         // We've found it, it's false
+         foundInterface = true;
+         jndiName = smd.getJndiName();
+      }
+
+      // Is this a local interface?
+      if (!foundInterface)
+      {
+         String ejb2xLocalInterface = smd.getLocal();
+         if (ejb2xInterface.equals(ejb2xLocalInterface))
+         {
+            // Mark as found
+            foundInterface = true;
+            isLocal = true;
+            jndiName = smd.getLocalJndiName();
+         }
+      }
+
+      // If we haven't yet found the interface
+      if (!foundInterface)
+      {
+         throw new RuntimeException("Specified return value for " + method + " notes an EJB 2.x interface: "
+               + ejb2xInterface + "; this could not be found as either a valid remote or local interface for EJB "
+               + this.getEjbName());
+      }
+      
+      // Lookup
+      String proxyFactoryKey = this.getJndiRegistrar().getProxyFactoryRegistryKey(jndiName, smd, isLocal);
+      Object factory = Ejb3RegistrarLocator.locateRegistrar().lookup(proxyFactoryKey);
+      
+      // Cast
+      assert factory instanceof StatefulSessionProxyFactory : "Specified factory " + factory.getClass().getName() + " is not of type "
+         + StatefulSessionProxyFactory.class.getName() + " as required by " + StatefulContainer.class.getName() + ", but was instead " + factory;
+      StatefulSessionProxyFactory statefulFactory = null;
+      statefulFactory = StatefulSessionProxyFactory.class.cast(factory);
+      
+      Serializable sessionId = createSession(method.getParameterTypes(), args);
+      Object proxy = statefulFactory.createProxyEjb2x(sessionId);
+      
+      return proxy;
+   }
+   
    protected InvocationResponse invokeHomeMethod(MethodInfo info,
          StatefulRemoteInvocation statefulInvocation) throws Throwable
    {

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java	2008-11-13 11:24:27 UTC (rev 80924)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java	2008-11-13 11:31:54 UTC (rev 80925)
@@ -683,10 +683,9 @@
       String methodName = unadvisedMethod.getName();
       if (methodName.equals("create"))
       {
-         SerializableMethod method = new SerializableMethod(unadvisedMethod);
          Object[] arguments = invocation.getArguments();
          // EJBTHREE-1512 Pass along the request to the proper home create method
-         Object proxy = this.invokeHomeCreate(method, arguments);
+         Object proxy = this.invokeHomeCreate(unadvisedMethod, arguments);
          return proxy;
       }
       // TODO: should be handled locally

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolder.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolder.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolder.java	2008-11-13 11:31:54 UTC (rev 80925)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1585;
+
+import javax.ejb.EJBLocalObject;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface ValueHolder extends EJBLocalObject
+{
+   String getValue();
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolderBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolderBean.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolderBean.java	2008-11-13 11:31:54 UTC (rev 80925)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1585;
+
+import javax.ejb.Init;
+import javax.ejb.LocalHome;
+import javax.ejb.Stateful;
+
+import org.jboss.ejb3.annotation.LocalHomeBinding;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at LocalHome(ValueHolderHome.class)
+ at LocalHomeBinding(jndiBinding="ValueHolderBean/localHome")
+public class ValueHolderBean
+{
+   private static Logger log = Logger.getLogger(ValueHolderBean.class);
+   
+   private String value;
+   
+   @Init
+   public void ejbCreate(String value)
+   {
+      log.debug("ejbCreate " + value);
+      this.value = value;
+   }
+   
+   public String getValue()
+   {
+      log.debug("getValue " + value);
+      return value;
+   }
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolderHome.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolderHome.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/ValueHolderHome.java	2008-11-13 11:31:54 UTC (rev 80925)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1585;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBLocalHome;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface ValueHolderHome extends EJBLocalHome
+{
+   ValueHolder create(String value) throws CreateException, RemoteException;
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/unit/StatefulLocalCreate21TestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/unit/StatefulLocalCreate21TestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1585/unit/StatefulLocalCreate21TestCase.java	2008-11-13 11:31:54 UTC (rev 80925)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1585.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.core.test.ejbthree1585.ValueHolder;
+import org.jboss.ejb3.core.test.ejbthree1585.ValueHolderBean;
+import org.jboss.ejb3.core.test.ejbthree1585.ValueHolderHome;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class StatefulLocalCreate21TestCase extends AbstractEJB3TestCase
+{
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+      AbstractEJB3TestCase.beforeClass();
+      
+      deploySessionEjb(ValueHolderBean.class);
+   }
+   
+   @Test
+   public void test1() throws Exception
+   {
+      ValueHolderHome home = lookup("ValueHolderBean/localHome", ValueHolderHome.class);
+      ValueHolder bean = home.create("value");
+      String actual = bean.getValue();
+      assertEquals("value", actual);
+   }
+}




More information about the jboss-cvs-commits mailing list