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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Jun 1 02:49:47 EDT 2008


Author: ALRubinger
Date: 2008-06-01 02:49:47 -0400 (Sun, 01 Jun 2008)
New Revision: 73879

Modified:
   projects/ejb3/trunk/core/pom.xml
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java
   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
   projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-beans.xml
Log:
[EJBTHREE-1385] Refactored SessionSpecContainers in EJB3 Core to use Proxy Component

Modified: projects/ejb3/trunk/core/pom.xml
===================================================================
--- projects/ejb3/trunk/core/pom.xml	2008-06-01 04:29:40 UTC (rev 73878)
+++ projects/ejb3/trunk/core/pom.xml	2008-06-01 06:49:47 UTC (rev 73879)
@@ -108,13 +108,6 @@
     </dependency>
     
     <dependency>
-      <groupId>hsqldb</groupId>
-      <artifactId>hsqldb</artifactId>
-      <version>1.8.0.7</version> <!-- Only used here, for Unit Tests -->
-      <scope>test</scope>
-    </dependency>
-    
-    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>
@@ -334,6 +327,12 @@
     
     <dependency>
       <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-proxy</artifactId>
+      <version>0.1.0-SNAPSHOT</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-test</artifactId>
       <version>0.1.0-SNAPSHOT</version>
       <scope>test</scope>
@@ -344,7 +343,7 @@
       <artifactId>jboss-ejb3-transactions</artifactId>
       <version>0.13.0</version>
     </dependency>
-    
+
     <dependency>
       <groupId>org.jboss.embedded</groupId>
       <artifactId>jboss-embedded</artifactId>

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java	2008-06-01 04:29:40 UTC (rev 73878)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java	2008-06-01 06:49:47 UTC (rev 73879)
@@ -61,6 +61,7 @@
 import org.jboss.ejb3.proxy.factory.SessionProxyFactory;
 import org.jboss.ejb3.proxy.factory.service.ServiceLocalProxyFactory;
 import org.jboss.ejb3.proxy.factory.service.ServiceRemoteProxyFactory;
+import org.jboss.ejb3.proxy.lang.SerializableMethod;
 import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
 import org.jboss.ejb3.timerservice.TimerServiceFactory;
@@ -206,6 +207,7 @@
    public void start() throws Exception
    {
       super.start();
+      proxyDeployer.start();
 
       try
       {
@@ -231,7 +233,7 @@
    }
 
    public void stop() throws Exception
-   {
+   {      
       invokeOptionalMethod("stop");
       
       if (timerService != null)
@@ -247,6 +249,15 @@
       beanContext = null;
       
       super.stop();
+      
+      try
+      {
+         proxyDeployer.stop();
+      }
+      catch (Exception ignore)
+      {
+         log.debug("Proxy deployer stop failed", ignore);
+      }
    }
 
    public void destroy() throws Exception
@@ -524,21 +535,6 @@
       return delegate.invoke(actionName, params, signature);
    }
 
-   @Override
-   protected Object invokeEJBObjectMethod(ProxyFactory factory, Object id, MethodInfo info, Object[] args) throws Exception
-   {
-      throw new RuntimeException("NYI");
-   }
-   
-
-   //TODO This shouldn't be required of @Service
-   @Override
-   protected Object invokeHomeCreate(SessionProxyFactory factory, Method unadvisedMethod, Object args[])
-         throws Exception
-   {
-      throw new NotImplementedException("Invalid for " + ServiceContainer.class.getName());
-   }
-
    public MBeanInfo getMBeanInfo()
    {
       return delegate.getMBeanInfo();

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java	2008-06-01 04:29:40 UTC (rev 73878)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java	2008-06-01 06:49:47 UTC (rev 73879)
@@ -29,7 +29,6 @@
 import java.util.List;
 import java.util.Map;
 
-import javax.ejb.EJBLocalObject;
 import javax.ejb.EJBObject;
 import javax.ejb.Handle;
 import javax.ejb.LocalHome;
@@ -55,6 +54,7 @@
 import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
 import org.jboss.ejb3.proxy.factory.RemoteProxyFactory;
 import org.jboss.ejb3.proxy.factory.SessionProxyFactory;
+import org.jboss.ejb3.proxy.lang.SerializableMethod;
 import org.jboss.ejb3.remoting.IsLocalInterceptor;
 import org.jboss.ejb3.stateful.StatefulContainerInvocation;
 import org.jboss.ha.framework.server.HATarget;
@@ -75,18 +75,6 @@
 
    protected ProxyDeployer proxyDeployer;
    private Map<String, HATarget> clusterFamilies;
-
-   public class InvokedMethod
-   {
-      public InvokedMethod(boolean localInterface, Method method)
-      {
-         isLocalInterface = localInterface;
-         this.method = method;
-      }
-
-      public boolean isLocalInterface;
-      public Method method;
-   }
    
    /**
     * Returns a remote binding for this container
@@ -108,7 +96,10 @@
       return binding;
    }
 
-   protected ThreadLocalStack<InvokedMethod> invokedMethod = new ThreadLocalStack<InvokedMethod>();
+   //TODO This should be available in ThreadLocal Scope via an Interceptor
+   // http://jira.jboss.com/jira/browse/EJBTHREE-1269
+   // http://jira.jboss.com/jira/browse/EJBTHREE-1268
+   protected ThreadLocalStack<SerializableMethod> invokedMethod = new ThreadLocalStack<SerializableMethod>();
 
    public SessionContainer(ClassLoader cl, String beanClassName, String ejbName, Domain domain,
                            Hashtable ctxProperties, Ejb3Deployment deployment, JBossSessionBeanMetaData beanMetaData) throws ClassNotFoundException
@@ -135,24 +126,14 @@
    
    public Class<?> getInvokedBusinessInterface()
    {
-      InvokedMethod method = invokedMethod.get();
+      
+      SerializableMethod method = invokedMethod.get();
       if (method == null) throw new IllegalStateException("getInvokedBusinessInterface() being invoked outside of a business invocation");
-      if (method.method == null) throw new IllegalStateException("getInvokedBusinessInterface() being invoked outside of a business invocation");
-      if (method.isLocalInterface) return method.method.getDeclaringClass();
-      Class<?>[] remoteInterfaces = ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(this);
-      for (Class<?> intf : remoteInterfaces)
-      {
-         try
-         {
-            intf.getMethod(method.method.getName(), method.method.getParameterTypes());
-            return intf;
-         }
-         catch (NoSuchMethodException ignored)
-         {
-            // continue
-         }
-      }
-      throw new IllegalStateException("Unable to find geInvokedBusinessInterface()");
+      if (method.getName() == null || method.getName().equals("")) throw new IllegalStateException("getInvokedBusinessInterface() being invoked outside of a business invocation");
+      
+      Class<?> invokedBusinessInterface = null;
+      
+      return invokedBusinessInterface;
    }
 
    protected JBossSessionBeanMetaData getMetaData()
@@ -185,7 +166,9 @@
       super.start();
       // So that Remoting layer can reference this container easily.
       Dispatcher.singleton.registerTarget(getObjectName().getCanonicalName(), new ClassProxyHack(this));
-      proxyDeployer.start();
+      
+      //TODO Remove
+      //      proxyDeployer.start();
    }
 
    /**
@@ -210,16 +193,17 @@
 
    public void stop() throws Exception
    {
+      //TODO Remove
+//      try
+//      {
+//         proxyDeployer.stop();
+//      }
+//      catch (Exception ignore)
+//      {
+//         log.debug("Proxy deployer stop failed", ignore);
+//      }
       try
       {
-         proxyDeployer.stop();
-      }
-      catch (Exception ignore)
-      {
-         log.debug("Proxy deployer stop failed", ignore);
-      }
-      try
-      {
          Dispatcher.singleton.unregisterTarget(getObjectName().getCanonicalName());
       }
       catch (Exception ignore)
@@ -316,32 +300,6 @@
    }
    */
 
-   protected boolean isHomeMethod(Method method)
-   {
-      if (javax.ejb.EJBHome.class.isAssignableFrom(method.getDeclaringClass())) return true;
-      if (javax.ejb.EJBLocalHome.class.isAssignableFrom(method.getDeclaringClass())) return true;
-      return false;
-   }
-
-   protected boolean isEJBObjectMethod(Method method)
-   {
-      if (method.getDeclaringClass().getName().equals(EJBObject.class.getName()))
-         return true;
-
-      if (method.getDeclaringClass().getName().equals(EJBLocalObject.class.getName()))
-         return true;
-
-      return false;
-   }
-
-   protected boolean isHandleMethod(Method method)
-   {
-      if (method.getDeclaringClass().getName().equals(Handle.class.getName()))
-         return true;
-
-      return false;
-   }
-
    public static InvocationResponse marshallException(Invocation invocation, Throwable exception, Map responseContext) throws Throwable
    {
       if (invocation.getMetaData(IsLocalInterceptor.IS_LOCAL,IsLocalInterceptor.IS_LOCAL) == null) throw exception;
@@ -382,7 +340,9 @@
     * @param method     the business or home method to invoke
     * @param args       the arguments for the method
     * @param provider   for asynchronous usage
+    * @deprecated Use "invoke" as defined by InvokableContext
     */
+   @Deprecated
    public Object invoke(SessionProxyFactory factory, Object id, Method method, Object args[], FutureHolder provider) throws Throwable
    {
       ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
@@ -398,17 +358,18 @@
                             + method.toString());
          }
 
-         Method unadvisedMethod = info.getUnadvisedMethod();
+         
+         // Handled now by SessionSpecContainer
+         //Method unadvisedMethod = info.getUnadvisedMethod();
+//         if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
+//         {
+//            return invokeHomeMethod(factory, info, args);
+//         }
+//         else if (unadvisedMethod != null && isEJBObjectMethod(unadvisedMethod))
+//         {
+//            return invokeEJBObjectMethod(factory, id, info, args);
+//         }
 
-         if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
-         {
-            return invokeHomeMethod(factory, info, args);
-         }
-         else if (unadvisedMethod != null && isEJBObjectMethod(unadvisedMethod))
-         {
-            return invokeEJBObjectMethod(factory, id, info, args);
-         }
-
          // FIXME: Ahem, stateful container invocation works on all.... (violating contract though)
          EJBContainerInvocation nextInvocation = new StatefulContainerInvocation(info, id);
          nextInvocation.setAdvisor(getAdvisor());
@@ -420,7 +381,7 @@
          ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
          try
          {
-            invokedMethod.push(new InvokedMethod(true, method));
+            invokedMethod.push(new SerializableMethod(method));
             return nextInvocation.invokeNext();
          }
          finally
@@ -436,46 +397,6 @@
    }
    
    /**
-    * TODO: work in progress (refactor both invokeHomeMethod's, localHomeInvoke)
-    * TODO: Move this to SessionSpecContainer
-    */
-   //TODO
-   private Object invokeHomeMethod(SessionProxyFactory factory, MethodInfo info, Object args[]) throws Exception
-   {
-      Method unadvisedMethod = info.getUnadvisedMethod();
-      if (unadvisedMethod.getName().equals("create"))
-      {
-         return this.invokeHomeCreate(factory, unadvisedMethod, args);
-      }
-      else if (unadvisedMethod.getName().equals("remove"))
-      {
-         if(args[0] instanceof Handle)
-            removeHandle((Handle) args[0]);
-         else
-            destroySession(args[0]);
-
-         return null;
-      }
-      else
-      {
-         throw new IllegalArgumentException("illegal home method " + unadvisedMethod);
-      }
-   }
-   
-   /**
-    * Provides implementation for this bean's EJB 2.1 Home.create() method 
-    * 
-    * @param factory
-    * @param unadvisedMethod
-    * @param args
-    * @return
-    * @throws Exception
-    */
-   //TODO Move this to SessionSpecContainer
-   protected abstract Object invokeHomeCreate(SessionProxyFactory factory, Method unadvisedMethod, Object args[])
-         throws Exception;
-   
-   /**
     * Create session to an EJB bean.
     * 
     * @param initParameterTypes     the parameter types used by the home's create method
@@ -512,12 +433,12 @@
       return proxyDeployer.hasJNDIBinding(jndiName);
    }
    
-   protected Object invokeEJBObjectMethod(ProxyFactory factory, Object id, MethodInfo info, Object args[]) throws Exception
+   protected Object invokeEJBObjectMethod(Object id, MethodInfo info, Object args[]) throws Exception
    {
       Method unadvisedMethod = info.getUnadvisedMethod();
       if(unadvisedMethod.getName().equals("getEJBHome"))
       {
-         return factory.createHomeProxy();
+         return this.getInitialContext().lookup(this.getMetaData().getHomeJndiName());
       }
       if(unadvisedMethod.getName().equals("getPrimaryKey"))
       {

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-06-01 04:29:40 UTC (rev 73878)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java	2008-06-01 06:49:47 UTC (rev 73879)
@@ -1,11 +1,33 @@
 package org.jboss.ejb3.session;
 
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.util.Hashtable;
 
+import javax.ejb.EJBLocalObject;
+import javax.ejb.EJBObject;
+import javax.ejb.Handle;
+
+import org.jboss.aop.Dispatcher;
 import org.jboss.aop.Domain;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.util.MethodHashing;
+import org.jboss.beans.metadata.api.annotations.Start;
+import org.jboss.beans.metadata.api.annotations.Stop;
+import org.jboss.ejb3.EJBContainerInvocation;
 import org.jboss.ejb3.Ejb3Deployment;
 import org.jboss.ejb3.annotation.LocalBinding;
 import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.common.registrar.spi.NotBoundException;
+import org.jboss.ejb3.interceptors.container.ContainerMethodInvocation;
+import org.jboss.ejb3.proxy.container.InvokableContext;
+import org.jboss.ejb3.proxy.handler.session.stateful.StatefulProxyInvocationHandler;
+import org.jboss.ejb3.proxy.jndiregistrar.JndiSessionRegistrarBase;
+import org.jboss.ejb3.proxy.lang.SerializableMethod;
+import org.jboss.ejb3.stateful.StatefulContainerInvocation;
+import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
 
 /**
@@ -18,17 +40,31 @@
  * @version $Revision: $
  */
 public abstract class SessionSpecContainer extends SessionContainer
+      implements
+         InvokableContext<ContainerMethodInvocation>
 {
-   
-   // Constructor
-   
+
+   // ------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(SessionSpecContainer.class);
+
+   // ------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   // ------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
    public SessionSpecContainer(ClassLoader cl, String beanClassName, String ejbName, Domain domain,
          Hashtable ctxProperties, Ejb3Deployment deployment, JBossSessionBeanMetaData beanMetaData)
          throws ClassNotFoundException
    {
       super(cl, beanClassName, ejbName, domain, ctxProperties, deployment, beanMetaData);
    }
-   
+
    /**
     * Create a remote proxy (EJBObject) for an enterprise bean identified by id
     * 
@@ -74,4 +110,295 @@
     * @throws Exception
     */
    public abstract Object createProxyLocalEjb21(LocalBinding binding, String businessInterfaceType) throws Exception;
+
+   /**
+    * Obtains the JndiSessionRegistrarBase from MC, null if not found
+    * 
+    * @return
+    */
+   protected JndiSessionRegistrarBase getJndiRegistrar()
+   {
+      // Initialize
+      String jndiRegistrarBindName = this.getJndiRegistrarBindName();
+
+      // Lookup
+      Object obj = null;
+      try
+      {
+         obj = Ejb3RegistrarLocator.locateRegistrar().lookup(jndiRegistrarBindName);
+      }
+      // If not installed, warn and return null
+      catch (NotBoundException e)
+      {
+         log.warn("No " + JndiSessionRegistrarBase.class.getName()
+               + " was found installed in the ObjectStore (Registry) at " + jndiRegistrarBindName);
+         return null;
+
+      }
+
+      // Cast
+      JndiSessionRegistrarBase registrar = (JndiSessionRegistrarBase) obj;
+
+      // Return
+      return registrar;
+   }
+
+   /**
+    * Invokes the method described by the specified serializable method
+    * as called from the specified proxy, using the specified arguments
+    * 
+    * @param proxy The proxy making the invocation
+    * @param method The method to be invoked
+    * @param args The arguments to the invocation
+    * @throws Throwable A possible exception thrown by the invocation
+    * @return
+    */
+   public Object invoke(Object proxy, SerializableMethod method, Object[] args) throws Throwable
+   {
+      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+      pushEnc();
+      try
+      {
+         Method clMethod = method.toMethod(this.getClassloader());
+         long hash = MethodHashing.calculateHash(clMethod);
+         MethodInfo info = getAdvisor().getMethodInfo(hash);
+         if (info == null)
+         {
+            throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
+         }
+
+         Method unadvisedMethod = info.getUnadvisedMethod();
+
+         //TODO Use Polymorphism to have sessions only in StatefulContainer
+         InvocationHandler handler = Proxy.getInvocationHandler(proxy);
+         Object sessionId = null;
+         if (handler instanceof StatefulProxyInvocationHandler)
+         {
+            sessionId = ((StatefulProxyInvocationHandler) handler).getSessionId();
+         }
+
+         if (unadvisedMethod != null && isHomeMethod(method))
+         {
+            return invokeHomeMethod(method, args);
+         }
+         else if (unadvisedMethod != null && this.isEjbObjectMethod(method))
+         {
+            return invokeEJBObjectMethod(sessionId, info, args);
+         }
+
+         // FIXME: Ahem, stateful container invocation works on all.... (violating contract though)
+         EJBContainerInvocation nextInvocation = new StatefulContainerInvocation(info, sessionId);
+         nextInvocation.setAdvisor(getAdvisor());
+         nextInvocation.setArguments(args);
+
+         // allow a container to supplement information into an invocation
+         nextInvocation = populateInvocation(nextInvocation);
+
+         //TODO Support Async Invocation
+         //         ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
+         try
+         {
+            invokedMethod.push(method);
+            return nextInvocation.invokeNext();
+         }
+         finally
+         {
+            invokedMethod.pop();
+         }
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(oldLoader);
+         popEnc();
+      }
+   }
+
+   /**
+    * Provides implementation for this bean's EJB 2.1 Home.create() method 
+    * 
+    * @param method
+    * @param args
+    * @return
+    * @throws Exception
+    */
+   protected abstract Object invokeHomeCreate(SerializableMethod method, Object args[]) throws Exception;
+
+   /**
+    * TODO: work in progress (refactor both invokeHomeMethod's, localHomeInvoke)
+    * TODO: Move this to SessionSpecContainer
+    */
+   //TODO
+   private Object invokeHomeMethod(SerializableMethod method, Object args[]) throws Exception
+   {
+      if (method.getName().equals("create"))
+      {
+         return this.invokeHomeCreate(method, args);
+      }
+      else if (method.getName().equals("remove"))
+      {
+         if (args[0] instanceof Handle)
+            removeHandle((Handle) args[0]);
+         else
+            destroySession(args[0]);
+
+         return null;
+      }
+      else
+      {
+         throw new IllegalArgumentException("illegal home method " + method);
+      }
+   }
+
+   /**
+    * @deprecated Use isHomeMethod(SerializableMethod method) in SessionSpecContainer
+    */
+   @Deprecated
+   protected boolean isHomeMethod(Method method)
+   {
+      if (javax.ejb.EJBHome.class.isAssignableFrom(method.getDeclaringClass()))
+         return true;
+      if (javax.ejb.EJBLocalHome.class.isAssignableFrom(method.getDeclaringClass()))
+         return true;
+      return false;
+   }
+
+   /**
+    * Determines whether the specified method is an EJB2.x Home Method
+    * 
+    * @param method
+    * @return
+    */
+   protected boolean isHomeMethod(SerializableMethod method)
+   {
+      // Get the Method
+      Method invokingMethod = method.toMethod(this.getClassloader());
+
+      // Use legacy
+      return this.isHomeMethod(invokingMethod);
+   }
+
+   /**
+    * @param method
+    * @return
+    * @deprecated Use isEjbObjectMethod(SerializableMethod method)
+    */
+   @Deprecated
+   protected boolean isEJBObjectMethod(Method method)
+   {
+      if (method.getDeclaringClass().getName().equals(EJBObject.class.getName()))
+         return true;
+
+      if (method.getDeclaringClass().getName().equals(EJBLocalObject.class.getName()))
+         return true;
+
+      return false;
+   }
+
+   /**
+    * Determines whether the specified method is an EJB2.x Local 
+    * or Remote Method
+    * 
+    * @param method
+    * @return
+    */
+   protected boolean isEjbObjectMethod(SerializableMethod method)
+   {
+      // Get the Method
+      Method invokingMethod = method.toMethod(this.getClassloader());
+
+      // Use legacy
+      return this.isEJBObjectMethod(invokingMethod);
+   }
+
+   /**
+    * 
+    * @param method
+    * @return
+    * @deprecated Use isHandleMethod(SerializableMethod method)
+    */
+   @Deprecated
+   protected boolean isHandleMethod(Method method)
+   {
+      if (method.getDeclaringClass().getName().equals(Handle.class.getName()))
+         return true;
+
+      return false;
+   }
+
+   /**
+    * Determines if the specified Method is a Handle Method
+    * @param method
+    * @return
+    */
+   protected boolean isHandleMethod(SerializableMethod method)
+   {
+      // Get the Method
+      Method invokingMethod = method.toMethod(this.getClassloader());
+
+      // Use legacy
+      return this.isHandleMethod(invokingMethod);
+   }
+
+   // ------------------------------------------------------------------------------||
+   // Lifecycle Methods ------------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   /**
+    * Lifecycle Start
+    */
+   @Start
+   @Override
+   public void start() throws Exception
+   {
+      log.info("Starting " + this);
+      
+      super.start();
+
+      // Register with Remoting
+      Dispatcher.singleton.registerTarget(this.getName(), this);
+
+      // Obtain registrar
+      JndiSessionRegistrarBase registrar = this.getJndiRegistrar();
+
+      // Bind all appropriate references/factories to Global JNDI for Client access, if a JNDI Registrar is present
+      if (registrar != null)
+      {
+         registrar.bindEjb(this.getMetaData(), this.getClassloader(), this.getName());
+      }
+      else
+      {
+         log.warn("No " + JndiSessionRegistrarBase.class.getSimpleName()
+               + " was found; byassing binding of Proxies to " + this.getName() + " in Global JNDI.");
+      }
+   }
+
+   /**
+    * Lifecycle Stop
+    */
+   @Override
+   @Stop
+   public void stop() throws Exception
+   {
+      log.info("Stopping " + this);
+      
+      super.stop();
+
+      // Deregister with Remoting
+      Dispatcher.singleton.unregisterTarget(this.getName());
+
+      //TODO We need to unbind the EJB, something like:
+      //JndiSessionRegistrarBase.unbindEjb(this.metaData);
+      // or some key by which the registrar will keep track of all bindings
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Contracts ----------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Returns the name under which the JNDI Registrar for this container is bound
+    * 
+    * @return
+    */
+   protected abstract String getJndiRegistrarBindName();
 }

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-06-01 04:29:40 UTC (rev 73878)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java	2008-06-01 06:49:47 UTC (rev 73879)
@@ -27,8 +27,10 @@
 import java.lang.reflect.Modifier;
 import java.rmi.NoSuchObjectException;
 import java.rmi.RemoteException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Map;
 
 import javax.ejb.EJBHome;
@@ -49,6 +51,7 @@
 import org.jboss.aop.joinpoint.InvocationResponse;
 import org.jboss.aop.util.MethodHashing;
 import org.jboss.aspects.asynch.FutureHolder;
+import org.jboss.beans.metadata.api.annotations.Stop;
 import org.jboss.ejb3.BeanContext;
 import org.jboss.ejb3.EJBContainerInvocation;
 import org.jboss.ejb3.Ejb3Deployment;
@@ -65,13 +68,14 @@
 import org.jboss.ejb3.proxy.ProxyFactory;
 import org.jboss.ejb3.proxy.ProxyUtils;
 import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
-import org.jboss.ejb3.proxy.factory.SessionProxyFactory;
 import org.jboss.ejb3.proxy.factory.stateful.BaseStatefulRemoteProxyFactory;
 import org.jboss.ejb3.proxy.factory.stateful.StatefulClusterProxyFactory;
 import org.jboss.ejb3.proxy.factory.stateful.StatefulProxyFactory;
 import org.jboss.ejb3.proxy.factory.stateful.StatefulRemoteProxyFactory;
 import org.jboss.ejb3.proxy.impl.EJBMetaDataImpl;
 import org.jboss.ejb3.proxy.impl.HomeHandleImpl;
+import org.jboss.ejb3.proxy.lang.SerializableMethod;
+import org.jboss.ejb3.proxy.objectstore.ObjectStoreBindings;
 import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.ejb3.session.SessionSpecContainer;
 import org.jboss.injection.Injector;
@@ -299,6 +303,8 @@
 
    }
 
+   @Stop
+   @Override
    public void stop() throws Exception
    {
       super.stop();
@@ -324,6 +330,16 @@
    {
       return this.getDeployment().getCacheFactoryRegistry();
    }
+   
+   /**
+    * Returns the name under which the JNDI Registrar for this container is bound
+    * 
+    * @return
+    */
+   protected String getJndiRegistrarBindName()
+   {
+      return ObjectStoreBindings.OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR_SFSB;
+   }
 
    /**
     * Performs a synchronous local invocation
@@ -406,7 +422,7 @@
             
             ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
             
-            invokedMethod.push(new InvokedMethod(true, method));
+            invokedMethod.push(new SerializableMethod(method));
             return nextInvocation.invokeNext();
          }
          finally
@@ -524,7 +540,7 @@
    
                Object rtn = null;
                  
-               invokedMethod.push(new InvokedMethod(false, unadvisedMethod));
+               invokedMethod.push(new SerializableMethod(unadvisedMethod));
                rtn = newSi.invokeNext();
 
                response = marshallResponse(invocation, rtn, newSi.getResponseContextInfo());
@@ -959,10 +975,13 @@
     * @throws Exception
     */
    @Override
-   protected Object invokeHomeCreate(SessionProxyFactory factory, Method unadvisedMethod, Object args[])
+   protected Object invokeHomeCreate(SerializableMethod method, Object args[])
          throws Exception
    {
       
+      // Lookup
+      Object factory = this.getInitialContext().lookup(this.getMetaData().getHomeJndiName());
+      
       // Cast
       String errorMessage = "Specified factory " + factory.getClass().getName() + " is not of type "
             + StatefulProxyFactory.class.getName() + " as required by " + StatefulContainer.class.getName();
@@ -981,15 +1000,21 @@
       {};
       Object[] initParameterValues =
       {};
-      if (unadvisedMethod.getParameterTypes().length > 0)
+      if (method.getArgumentTypes().length > 0)
       {
-         initParameterTypes = unadvisedMethod.getParameterTypes();
+         List<Class<?>> argTypes = new ArrayList<Class<?>>();
+         for(String argTypeName : method.getArgumentTypes())
+         {
+            argTypes.add(this.getClassloader().loadClass(argTypeName));
+         }
+         
+         initParameterTypes = argTypes.toArray(new Class<?>[]{});
          initParameterValues = args;
       }
 
       Object id = createSession(initParameterTypes, initParameterValues);
 
-      Object proxy = statefulFactory.createProxyBusiness(id, unadvisedMethod.getReturnType().getName());
+      Object proxy = statefulFactory.createProxyBusiness(id, method.getReturnType());
 
       return proxy;
    }

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-06-01 04:29:40 UTC (rev 73878)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java	2008-06-01 06:49:47 UTC (rev 73879)
@@ -22,6 +22,17 @@
 package org.jboss.ejb3.stateless;
 
 
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.ejb.EJBContext;
+import javax.ejb.EJBException;
+import javax.ejb.Handle;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.naming.NamingException;
+
 import org.jboss.aop.Domain;
 import org.jboss.aop.MethodInfo;
 import org.jboss.aop.joinpoint.Invocation;
@@ -44,6 +55,8 @@
 import org.jboss.ejb3.proxy.factory.stateless.StatelessClusterProxyFactory;
 import org.jboss.ejb3.proxy.factory.stateless.StatelessLocalProxyFactory;
 import org.jboss.ejb3.proxy.factory.stateless.StatelessRemoteProxyFactory;
+import org.jboss.ejb3.proxy.lang.SerializableMethod;
+import org.jboss.ejb3.proxy.objectstore.ObjectStoreBindings;
 import org.jboss.ejb3.session.SessionSpecContainer;
 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
 import org.jboss.ejb3.timerservice.TimerServiceFactory;
@@ -61,13 +74,7 @@
 import org.jboss.wsf.spi.invocation.integration.InvocationContextCallback;
 import org.jboss.wsf.spi.invocation.integration.ServiceEndpointContainer;
 
-import javax.ejb.*;
-import javax.naming.NamingException;
-import java.lang.reflect.Method;
-import java.util.Hashtable;
-import java.util.Map;
 
-
 /**
  * Comment
  *
@@ -310,7 +317,7 @@
          {
             invokeStats.callIn();
             
-            invokedMethod.push(new InvokedMethod(true, unadvisedMethod));
+            invokedMethod.push(new SerializableMethod(unadvisedMethod));
 
             if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
             {
@@ -365,7 +372,7 @@
          {
             invokeStats.callIn();
             
-            invokedMethod.push(new InvokedMethod(false, unadvisedMethod));
+            invokedMethod.push(new SerializableMethod(unadvisedMethod));
             Map responseContext = null;
             Object rtn = null;
             if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
@@ -472,11 +479,14 @@
     * @throws Exception
     */
    @Override
-   protected Object invokeHomeCreate(SessionProxyFactory factory, Method unadvisedMethod, Object args[])
+   protected Object invokeHomeCreate(SerializableMethod unadvisedMethod, Object args[])
          throws Exception
    {   
+      // Lookup factory
+      Object factory = this.getInitialContext().lookup(this.getMetaData().getHomeJndiName());
+      SessionProxyFactory proxyFactory = SessionProxyFactory.class.cast(factory);
 
-      Object proxy = factory.createProxyBusiness(unadvisedMethod.getReturnType().getName());
+      Object proxy = proxyFactory.createProxyBusiness(unadvisedMethod.getReturnType());
 
       return proxy;
    }
@@ -588,6 +598,16 @@
       return name;
    }
    
+   /**
+    * Returns the name under which the JNDI Registrar for this container is bound
+    * 
+    * @return
+    */
+   protected String getJndiRegistrarBindName()
+   {
+      return ObjectStoreBindings.OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR_SLSB;
+   }
+   
    static class WSCallbackImpl implements BeanContextLifecycleCallback
    {
       private ExtensibleWebServiceContext jaxwsContext;

Modified: projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-beans.xml
===================================================================
--- projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-beans.xml	2008-06-01 04:29:40 UTC (rev 73878)
+++ projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-beans.xml	2008-06-01 06:49:47 UTC (rev 73879)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <!--
-    JCA Deployers
+    EJB3 Deployers
 -->
 <deployment xmlns="urn:jboss:bean-deployer:2.0">
 
@@ -270,6 +270,51 @@
    <!-- Persistence Unit deployers -->
    <bean name="PersistenceUnitParsingDeployer" class="org.jboss.ejb3.deployers.PersistenceUnitParsingDeployer">
       <property name="type">car</property>
-   </bean>
+   </bean>
+   
+   <!-- 
+    
+    JNDI Registrars
+    
+    
+    The JNDI Registrar is responsible for all JNDI Bindings for
+    an EJB.  Its constructor takes the following arguments, in order:
+    
+    javax.naming.Context (JNDI Context into which to bind objects)
+    org.jboss.ejb3.proxy.spi.registry.ProxyFactoryRegistry (Implementation of ProxyFactoryRegistry)
+    String statelessSessionProxyObjectFactoryType The JNDI ObjectFactory implementation to use for SLSB
+    ...more later when SFSB, @Service, MDB Implemented
+    
+  -->
+
+  <!-- SLSB JNDI Registrar -->
+  <bean name="org.jboss.ejb3.JndiRegistrar.Session.SLSBJndiRegistrar"
+    class="org.jboss.ejb3.proxy.jndiregistrar.JndiStatelessSessionRegistrar">
+    <constructor>
+      <parameter>
+        <inject bean="org.jboss.ejb3.JndiContext" />
+      </parameter>
+      <parameter>
+        org.jboss.ejb3.proxy.objectfactory.session.stateless.StatelessSessionProxyObjectFactory
+      </parameter>
+    </constructor>
+  </bean>
+
+  <!-- SFSB JNDI Registrar -->
+  <bean name="org.jboss.ejb3.JndiRegistrar.Session.SFSBJndiRegistrar"
+    class="org.jboss.ejb3.proxy.jndiregistrar.JndiStatefulSessionRegistrar">
+    <constructor>
+      <parameter>
+        <inject bean="org.jboss.ejb3.JndiContext" />
+      </parameter>
+      <parameter>
+        org.jboss.ejb3.proxy.objectfactory.session.stateful.StatefulSessionProxyObjectFactory
+      </parameter>
+    </constructor>
+  </bean>
+
+  <!-- JNDI Registrar Configuration -->
+  <bean name="org.jboss.ejb3.JndiContext"
+    class="javax.naming.InitialContext" />
    
 </deployment>




More information about the jboss-cvs-commits mailing list