[jboss-cvs] JBossAS SVN: r64133 - in trunk/ejb3/src: main/org/jboss/ejb3 and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 19 08:20:27 EDT 2007


Author: wolfc
Date: 2007-07-19 08:20:27 -0400 (Thu, 19 Jul 2007)
New Revision: 64133

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/session/ProxyDeployer.java
   trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/util/
   trunk/ejb3/src/main/org/jboss/ejb3/util/Debugger.java
Removed:
   trunk/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java
   trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java
Modified:
   trunk/ejb3/src/main/org/jboss/annotation/ejb/Clustered.java
   trunk/ejb3/src/main/org/jboss/annotation/ejb/RemoteBinding.java
   trunk/ejb3/src/main/org/jboss/annotation/ejb/RemoteBindingImpl.java
   trunk/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java
   trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
   trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
   trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
   trunk/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java
   trunk/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/remoting/RemoteProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/remoting/ReplicantsManagerInterceptorFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
   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/BaseStatelessProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.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/bank/TellerRemoteProxyFactory.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulRemoteProxyFactory.java
Log:
Refactored the usage of ProxyDeployer & ProxyFactory

Modified: trunk/ejb3/src/main/org/jboss/annotation/ejb/Clustered.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/annotation/ejb/Clustered.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/annotation/ejb/Clustered.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -38,7 +38,7 @@
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Clustered
 {
-   Class loadBalancePolicy() default LoadBalancePolicy.class;
+   Class<? extends LoadBalancePolicy> loadBalancePolicy() default LoadBalancePolicy.class;
 
    String partition() default "${jboss.partition.name:DefaultPartition}";
 }

Modified: trunk/ejb3/src/main/org/jboss/annotation/ejb/RemoteBinding.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/annotation/ejb/RemoteBinding.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/annotation/ejb/RemoteBinding.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -26,6 +26,8 @@
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+import org.jboss.ejb3.remoting.RemoteProxyFactory;
+
 /**
  * Annotation for specifying the remote jndi binding for a bean as well
  * as the client interceptor stack, which is a stack-ref in JBoss AOP
@@ -45,5 +47,5 @@
 
    String clientBindUrl() default "";
 
-   Class factory() default org.jboss.ejb3.remoting.RemoteProxyFactory.class;
+   Class<? extends RemoteProxyFactory> factory() default RemoteProxyFactory.class;
 }

Modified: trunk/ejb3/src/main/org/jboss/annotation/ejb/RemoteBindingImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/annotation/ejb/RemoteBindingImpl.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/annotation/ejb/RemoteBindingImpl.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -28,6 +28,8 @@
 import javax.ejb.MessageDriven;
 
 import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.util.Debugger;
 
 /**
  * Comment
@@ -40,22 +42,28 @@
    private String jndi;
    private String stack;
    private String bindUrl;
-   private Class proxyFactory;
+   private Class<? extends RemoteProxyFactory> proxyFactory;
    
+   private StackTraceElement constructionPoint;
+   
    public RemoteBindingImpl()
    {
       jndi = "";
       stack = "";
       bindUrl = "";
       proxyFactory = org.jboss.ejb3.remoting.RemoteProxyFactory.class;
+      
+      this.constructionPoint = Debugger.constructionPoint();
    }
 
-   public RemoteBindingImpl(String jndi, String stack, String bindUrl, Class proxyFactory)
+   public RemoteBindingImpl(String jndi, String stack, String bindUrl, Class<? extends RemoteProxyFactory> proxyFactory)
    {
       this.jndi = jndi;
       this.stack = stack;
       this.bindUrl = bindUrl;
       this.proxyFactory = proxyFactory;
+      
+      this.constructionPoint = Debugger.constructionPoint();
    }
    
    public void setStack(String stack)
@@ -63,7 +71,7 @@
       this.stack = stack;
    }
    
-   public void setFactory(Class factory)
+   public void setFactory(Class<? extends RemoteProxyFactory> factory)
    {
       this.proxyFactory = factory;
    }
@@ -93,7 +101,7 @@
       return bindUrl;
    }
 
-   public Class factory()
+   public Class<? extends RemoteProxyFactory> factory()
    {
       return proxyFactory;
    }
@@ -127,6 +135,7 @@
       sb.append(", stack=" + stack);
       sb.append(", bindUrl=" + bindUrl);
       sb.append(", proxyFactory=" + proxyFactory);
+      sb.append(", constructionPoint=" + constructionPoint);
       sb.append(']');
       return sb.toString();
    }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -53,6 +53,7 @@
 import org.jboss.annotation.security.SecurityDomain;
 import org.jboss.aop.Advisor;
 import org.jboss.ejb3.security.SecurityDomainManager;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.ejb3.stateless.StatelessBeanContext;
 import org.jboss.ejb3.tx.TxUtil;
 import org.jboss.ejb3.tx.UserTransactionImpl;

Modified: trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -365,16 +365,6 @@
    }
    
    /**
-    * EJBContainer has finished with all metadata initialization from XML files and such.
-    * this is really a hook to do some processing after XML has been set up and before
-    * and processing of dependencies and such.
-    */
-   public void instantiated()
-   {
-
-   }
-
-   /**
     * introspects EJB container to find all dependencies
     * and initialize any extra metadata.
     * <p/>
@@ -997,6 +987,12 @@
       return deployment.resolveMessageDestination(link);
    }
    
+   @SuppressWarnings("unchecked")
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+   {
+      return (T) resolveAnnotation(annotationType);
+   }
+   
    public <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz)
    {
       if (clazz == this.getBeanClass())

Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -481,7 +481,7 @@
             // EJBContainer has finished with all metadata initialization from XML files and such.
             // this is really a hook to do some processing after XML has been set up and before
             // and processing of dependencies and such.
-            ((EJBContainer)con).instantiated();
+//            ((EJBContainer)con).instantiated();
             this.ejbContainers.put(con.getObjectName(), con);
             Ejb3Registry.register(con);
          }
@@ -508,7 +508,7 @@
             // EJBContainer has finished with all metadata initialization from XML files and such.
             // this is really a hook to do some processing after XML has been set up and before
             // and processing of dependencies and such.
-            ((EJBContainer)con).instantiated();
+//            ((EJBContainer)con).instantiated();
             this.ejbContainers.put(con.getObjectName(), con);
             Ejb3Registry.register(con);
          }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -160,6 +160,7 @@
 import org.jboss.ejb3.metamodel.SecurityIdentity;
 import org.jboss.ejb3.metamodel.SessionEnterpriseBean;
 import org.jboss.ejb3.metamodel.XmlAnnotation;
+import org.jboss.ejb3.remoting.RemoteProxyFactory;
 import org.jboss.ejb3.service.ServiceContainer;
 import org.jboss.ejb3.stateful.StatefulContainer;
 import org.jboss.logging.Logger;
@@ -1662,7 +1663,7 @@
             bindingAnnotation.setStack(binding.getInterceptorStack());
 
          if (binding.getProxyFactory() != null)
-            bindingAnnotation.setFactory(di.getClassLoader().loadClass(binding.getProxyFactory()));
+            bindingAnnotation.setFactory((Class<? extends RemoteProxyFactory>) di.getClassLoader().loadClass(binding.getProxyFactory()));
 
          bindingAnnotationsList.add(bindingAnnotation);
 

Deleted: trunk/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -1,196 +0,0 @@
-/*
- * 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;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.annotation.ejb.Clustered;
-import org.jboss.annotation.ejb.LocalBinding;
-import org.jboss.annotation.ejb.LocalBindingImpl;
-import org.jboss.annotation.ejb.RemoteBinding;
-import org.jboss.annotation.ejb.RemoteBindingImpl;
-import org.jboss.annotation.ejb.RemoteBindings;
-import org.jboss.annotation.ejb.RemoteBindingsImpl;
-import org.jboss.aop.Advisor;
-import org.jboss.ejb3.remoting.RemoteProxyFactory;
-import org.jboss.ejb3.service.ServiceContainer;
-import org.jboss.ejb3.service.ServiceLocalProxyFactory;
-import org.jboss.ejb3.service.ServiceRemoteProxyFactory;
-import org.jboss.ejb3.stateful.StatefulClusterProxyFactory;
-import org.jboss.ejb3.stateful.StatefulContainer;
-import org.jboss.ejb3.stateful.StatefulLocalProxyFactory;
-import org.jboss.ejb3.stateful.StatefulRemoteProxyFactory;
-import org.jboss.ejb3.stateless.StatelessClusterProxyFactory;
-import org.jboss.ejb3.stateless.StatelessLocalProxyFactory;
-import org.jboss.ejb3.stateless.StatelessRemoteProxyFactory;
-import org.jboss.logging.Logger;
-
-/**
- * Delegatee of a SessionContainer for managing proxy factories.
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class ProxyDeployer
-{
-   private static final Logger log = Logger.getLogger(ProxyDeployer.class);
-   private SessionContainer container;
-   private ArrayList<ProxyFactory> proxyFactories = new ArrayList<ProxyFactory>();
-   private RemoteBindings remoteBindings;
-   private LocalBinding localBinding;
-
-   public ProxyDeployer(SessionContainer container)
-   {
-      assert container != null : "container is null";
-      
-      this.container = container;
-   }
-
-   public List<ProxyFactory> getProxyFactories() { return proxyFactories; }
-
-   public void start() throws Exception
-   {
-      if (remoteBindings != null)
-      {
-         RemoteBinding[] list = remoteBindings.value();
-         for (int i = 0; i < list.length; i++)
-         {
-            Class factoryClass = list[i].factory();
-            if (factoryClass.equals(RemoteProxyFactory.class)) factoryClass = getDefaultRemoteProxyFactory();
-            RemoteProxyFactory factory = (RemoteProxyFactory) factoryClass.newInstance();
-            factory.setRemoteBinding(list[i]);
-            factory.setContainer(container);
-            factory.start();
-            proxyFactories.add(factory);
-         }
-      }
-
-      if (localBinding != null)
-      {
-         ProxyFactory factory = null;
-         if (container instanceof StatefulContainer)
-         {
-            factory = new StatefulLocalProxyFactory();
-         }
-         else if (container instanceof ServiceContainer)
-         {
-            factory = new ServiceLocalProxyFactory();
-         }
-         else
-         {
-            factory = new StatelessLocalProxyFactory();
-         }
-
-         factory.setContainer(container);
-         factory.start();
-         proxyFactories.add(factory);
-      }
-   }
-
-   public void initializeLocalBindingMetadata()
-   {
-      localBinding = (LocalBinding) container.resolveAnnotation(LocalBinding.class);
-      if (localBinding == null)
-      {
-         if (ProxyFactoryHelper.getLocalInterfaces(container).length > 0)
-         {
-            localBinding = new LocalBindingImpl(ProxyFactoryHelper.getLocalJndiName(container));
-            container.getAnnotations().addClassAnnotation(LocalBinding.class, localBinding);
-         }
-      }
-   }
-
-   public void initializeRemoteBindingMetadata()
-   {
-      remoteBindings = (RemoteBindings) container.resolveAnnotation(RemoteBindings.class);
-      if (remoteBindings == null)
-      {
-         RemoteBinding binding = (RemoteBinding) container.resolveAnnotation(RemoteBinding.class);
-         if (binding == null)
-         {
-            log.debug("no declared remote bindings for : " + container.getEjbName());
-            if (ProxyFactoryHelper.getRemoteInterfaces(container).length > 0)
-            {
-               log.debug("there is remote interfaces for " + container.getEjbName());
-               String jndiName = ProxyFactoryHelper.getDefaultRemoteJndiName(container);
-               log.debug("default remote binding has jndiName of " + jndiName);
-               String uri = ""; // use the default
-               Class factory = null;
-               factory = getDefaultRemoteProxyFactory();
-               RemoteBinding[] list = {new RemoteBindingImpl(jndiName, "", uri, factory)};
-               remoteBindings = new RemoteBindingsImpl(list);
-               container.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings);
-            }
-         }
-         else
-         {
-            RemoteBinding[] list = {binding};
-            remoteBindings = new RemoteBindingsImpl(list);
-            container.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings);
-         }
-      }
-   }
-
-   private Class getDefaultRemoteProxyFactory()
-   {
-      Class factory;
-      if (container instanceof StatefulContainer)
-      {
-         if (container.resolveAnnotation(Clustered.class) != null)
-         {
-            factory = StatefulClusterProxyFactory.class;
-         }
-         else
-         {
-            factory = StatefulRemoteProxyFactory.class;
-         }
-      }
-      else if (container instanceof ServiceContainer)
-      {
-         //TODO Implement clustering
-         factory = ServiceRemoteProxyFactory.class;
-      }
-      else
-      {
-         if (container.resolveAnnotation(Clustered.class) != null)
-         {
-            factory = StatelessClusterProxyFactory.class;
-         }
-         else
-         {
-            factory = StatelessRemoteProxyFactory.class;
-         }
-      }
-      return factory;
-   }
-
-
-   public void stop() throws Exception
-   {
-      for (int i = 0; i < proxyFactories.size(); i++)
-      {
-         ProxyFactory factory = (ProxyFactory) proxyFactories.get(i);
-         factory.stop();
-      }
-   }
-}

Modified: trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -29,8 +29,6 @@
  */
 public interface ProxyFactory
 {
-   public void setContainer(Container container);
-
    public Object createHomeProxy();
    
    public Object createProxy();

Modified: trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -31,6 +31,7 @@
 import org.jboss.ejb.RemoteImpl;
 import org.jboss.logging.Logger;
 import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.session.SessionContainer;
 
 import javax.ejb.Local;
 import javax.ejb.LocalHome;
@@ -165,6 +166,15 @@
       return li.value();
    }
 
+   /**
+    * Resolve the business interfaces on an enterprise bean.
+    * 
+    * Note: for normal operation call container.getBusinessInterfaces().
+    * 
+    * @param beanClass
+    * @return
+    * @see      org.jboss.ejb3.EJBContainer#getBusinessInterfaces()
+    */
    public static ArrayList<Class> getBusinessInterfaces(Class beanClass)
    {
       ArrayList<Class> interfaces = new ArrayList<Class>(Arrays.asList(beanClass.getInterfaces()));
@@ -311,7 +321,7 @@
       return getLocalJndiName(container, true);
    }
 
-   public static String getLocalJndiName(Container container, boolean conflictCheck)
+   private static String getLocalJndiName(Container container, boolean conflictCheck)
    {
       Advisor advisor = (Advisor) container;
       LocalBinding localBinding = (LocalBinding) advisor
@@ -416,7 +426,7 @@
       }
    }
 
-   public static String getRemoteJndiName(Container container, RemoteBinding binding)
+   private static String getRemoteJndiName(Container container, RemoteBinding binding)
    {
       return getRemoteJndiName(container, binding, true);
    }

Deleted: trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -1,432 +0,0 @@
-/*
- * 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;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.EJBObject;
-import javax.ejb.Handle;
-import javax.ejb.LocalHome;
-import javax.ejb.RemoteHome;
-
-import org.jboss.aop.AspectManager;
-import org.jboss.aop.Dispatcher;
-import org.jboss.aop.MethodInfo;
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.InvocationResponse;
-import org.jboss.aop.util.MethodHashing;
-import org.jboss.aspects.asynch.FutureHolder;
-import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
-import org.jboss.ejb3.remoting.IsLocalInterceptor;
-import org.jboss.ejb3.stateful.StatefulContainerInvocation;
-import org.jboss.logging.Logger;
-import org.jboss.serial.io.MarshalledObjectForLocalCalls;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public abstract class SessionContainer extends EJBContainer
-{
-   @SuppressWarnings("unused")
-   private static final Logger log = Logger.getLogger(SessionContainer.class);
-
-   protected ProxyDeployer proxyDeployer;
-   protected Map clusterFamilies = new HashMap();
-
-   public class InvokedMethod
-   {
-      public InvokedMethod(boolean localInterface, Method method)
-      {
-         isLocalInterface = localInterface;
-         this.method = method;
-      }
-
-      public boolean isLocalInterface;
-      public Method method;
-   }
-   
-   public abstract Object createLocalProxy(Object id) throws Exception;
-   
-   public abstract Object createRemoteProxy(Object id) throws Exception;
-
-   protected ThreadLocalStack<InvokedMethod> invokedMethod = new ThreadLocalStack<InvokedMethod>();
-
-   public SessionContainer(ClassLoader cl, String beanClassName, String ejbName, AspectManager manager,
-                           Hashtable ctxProperties, InterceptorInfoRepository interceptorRepository,
-                           Ejb3Deployment deployment)
-   {
-      super(Ejb3Module.BASE_EJB3_JMX_NAME + ",name=" + ejbName, manager, cl, beanClassName, ejbName, ctxProperties, interceptorRepository, deployment);
-      proxyDeployer = new ProxyDeployer(this);
-   }
-
-   public Class getInvokedBusinessInterface()
-   {
-      InvokedMethod 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.getRemoteInterfaces(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()");
-   }
-
-   @Override
-   public void instantiated()
-   {
-      super.instantiated();
-      proxyDeployer.initializeRemoteBindingMetadata();
-      proxyDeployer.initializeLocalBindingMetadata();
-   }
-
-   protected List<Class<?>> resolveBusinessInterfaces()
-   {
-      List<Class<?>> list = new ArrayList<Class<?>>();
-      list.addAll(Arrays.asList(ProxyFactoryHelper.getLocalInterfaces(this)));
-      list.addAll(Arrays.asList(ProxyFactoryHelper.getRemoteInterfaces(this)));
-      return list;
-   }
-   
-   public void start() throws Exception
-   {
-      super.start();
-      // So that Remoting layer can reference this container easily.
-      Dispatcher.singleton.registerTarget(getObjectName().getCanonicalName(), this);
-      proxyDeployer.start();
-   }
-
-   public Map getClusterFamilies()
-   {
-      return clusterFamilies;
-   }
-
-   public void stop() throws Exception
-   {
-      try
-      {
-         proxyDeployer.stop();
-      }
-      catch (Exception ignore)
-      {
-         log.trace("Proxy deployer stop failed", ignore);
-      }
-      try
-      {
-         Dispatcher.singleton.unregisterTarget(getObjectName().getCanonicalName());
-      }
-      catch (Exception ignore)
-      {
-         log.trace("Dispatcher unregister target failed", ignore);
-      }
-      super.stop();
-   }
-
-   protected void createMethodMap()
-   {
-      super.createMethodMap();
-      try
-      {
-         RemoteHome home = (RemoteHome) resolveAnnotation(RemoteHome.class);
-         if (home != null)
-         {
-            Method[] declaredMethods = home.value().getMethods();
-            for (int i = 0; i < declaredMethods.length; i++)
-            {
-               long hash = MethodHashing.methodHash(declaredMethods[i]);
-               advisedMethods.put(hash, declaredMethods[i]);
-            }
-
-            declaredMethods = javax.ejb.EJBObject.class.getMethods();
-            for (int i = 0; i < declaredMethods.length; i++)
-            {
-               long hash = MethodHashing.methodHash(declaredMethods[i]);
-               advisedMethods.put(hash, declaredMethods[i]);
-            }
-         }
-
-         LocalHome localHome = (LocalHome) resolveAnnotation(LocalHome.class);
-         if (localHome != null)
-         {
-            Method[] declaredMethods = localHome.value().getMethods();
-            for (int i = 0; i < declaredMethods.length; i++)
-            {
-               long hash = MethodHashing.methodHash(declaredMethods[i]);
-               advisedMethods.put(hash, declaredMethods[i]);
-            }
-
-            declaredMethods = javax.ejb.EJBLocalObject.class.getMethods();
-            for (int i = 0; i < declaredMethods.length; i++)
-            {
-               long hash = MethodHashing.methodHash(declaredMethods[i]);
-               advisedMethods.put(hash, declaredMethods[i]);
-            }
-         }
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-
-   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("javax.ejb.EJBObject"))
-         return true;
-
-      if (method.getDeclaringClass().getName().equals("javax.ejb.EJBLocalObject"))
-         return true;
-
-      return false;
-   }
-
-   protected boolean isHandleMethod(Method method)
-   {
-      if (method.getDeclaringClass().getName().equals("javax.ejb.Handle"))
-         return true;
-
-      return false;
-   }
-
-   public static InvocationResponse marshallException(Invocation invocation, Throwable exception, Map responseContext) throws Throwable
-   {
-      if (!invocation.getMetaData().hasTag(IsLocalInterceptor.IS_LOCAL)) throw exception;
-
-      InvocationResponse response = new InvocationResponse();
-      response.setContextInfo(responseContext);
-
-      response.addAttachment(IsLocalInterceptor.IS_LOCAL_EXCEPTION, new MarshalledObjectForLocalCalls(exception));
-
-      return response;
-   }
-
-   public static InvocationResponse marshallResponse(Invocation invocation, Object rtn, Map responseContext)
-           throws java.io.IOException
-   {
-      InvocationResponse response;
-      // marshall return value
-      if (rtn != null && invocation.getMetaData().hasTag(IsLocalInterceptor.IS_LOCAL))
-      {
-         response = new InvocationResponse(new MarshalledObjectForLocalCalls(rtn));
-      }
-      else
-      {
-         response = new InvocationResponse(rtn);
-      }
-      response.setContextInfo(responseContext);
-      return response;
-   }
-   
-   /**
-    * Invoke a method on the virtual EJB bean. The method must be one of the methods defined in one
-    * of the business interfaces (or home interface) of the bean.
-    * 
-    * TODO: work in progress
-    * 
-    * @param factory    the originating end point
-    * @param id         unique identifier (primary key), can be null for stateless
-    * @param method     the business or home method to invoke
-    * @param args       the arguments for the method
-    * @param provider   for asynchronous usage
-    */
-   public Object invoke(ProxyFactory factory, Object id, Method method, Object args[], FutureHolder provider) throws Throwable
-   {
-      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
-      pushEnc();
-      try
-      {
-         long hash = MethodHashing.calculateHash(method);
-         MethodInfo info = (MethodInfo) methodInterceptors.get(hash);
-         if (info == null)
-         {
-            throw new RuntimeException(
-                    "Could not resolve beanClass method from proxy call: "
-                            + method.toString());
-         }
-
-         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);
-         }
-
-         // FIXME: Ahem, stateful container invocation works on all.... (violating contract though)
-         EJBContainerInvocation nextInvocation = new StatefulContainerInvocation(info, id);
-         nextInvocation.setAdvisor(this);
-         nextInvocation.setArguments(args);
-         
-         // allow a container to supplement information into an invocation
-         nextInvocation = populateInvocation(nextInvocation);
-
-         ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
-         try
-         {
-            invokedMethod.push(new InvokedMethod(true, method));
-            return nextInvocation.invokeNext();
-         }
-         finally
-         {
-            invokedMethod.pop();
-         }
-      }
-      finally
-      {
-         Thread.currentThread().setContextClassLoader(oldLoader);
-         popEnc();
-      }
-   }
-   
-   /**
-    * TODO: work in progress (refactor both invokeHomeMethod's, localHomeInvoke)
-    */
-   private Object invokeHomeMethod(ProxyFactory factory, MethodInfo info, Object args[]) throws Exception
-   {
-      Method unadvisedMethod = info.getUnadvisedMethod();
-      if (unadvisedMethod.getName().equals("create"))
-      {
-         Class[] initParameterTypes = {};
-         Object[] initParameterValues = {};
-         if (unadvisedMethod.getParameterTypes().length > 0)
-         {
-            initParameterTypes = unadvisedMethod.getParameterTypes();
-            initParameterValues = args;
-         }
-
-         Object id = createSession(initParameterTypes, initParameterValues);
-         
-         Object proxy = factory.createProxy(id);
-
-         return proxy;
-      }
-      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);
-      }
-   }
-   
-   /**
-    * Create session to an EJB bean.
-    * 
-    * @param initParameterTypes     the parameter types used by the home's create method
-    * @param initParameterValues    the arguments for the home's create method
-    * @return   the identifier of the session
-    */
-   abstract protected Object createSession(Class initParameterTypes[], Object initParameterValues[]);
-   
-   /**
-    * Destroy a created session.
-    * 
-    * @param id     the identifier of the session
-    */
-   protected void destroySession(Object id)
-   {
-      throw new RuntimeException("NYI");
-   }
-   
-   protected Object invokeEJBObjectMethod(ProxyFactory factory, Object id, MethodInfo info, Object args[]) throws Exception
-   {
-      Method unadvisedMethod = info.getUnadvisedMethod();
-      if(unadvisedMethod.getName().equals("getEJBHome"))
-      {
-         return factory.createHomeProxy();
-      }
-      if(unadvisedMethod.getName().equals("getPrimaryKey"))
-      {
-         return id;
-      }
-      if(unadvisedMethod.getName().equals("isIdentical"))
-      {
-         // object has no identity
-         if(id == null)
-            return false;
-         
-         EJBObject bean = (EJBObject) args[0];
-
-         Object primaryKey = bean.getPrimaryKey();
-         if(primaryKey == null)
-            return false;
-
-         boolean isIdentical = id.equals(primaryKey);
-
-         return isIdentical;
-      }
-      if (unadvisedMethod.getName().equals("remove"))
-      {
-         destroySession(id);
-
-         return null;
-      }
-      throw new RuntimeException("NYI");
-   }
-   
-   /**
-    * Allow a container sub class to supplement an invocation. Per default nothing to supplement.
-    * 
-    * @param invocation
-    * @return
-    */
-   protected EJBContainerInvocation populateInvocation(EJBContainerInvocation invocation)
-   {
-      return invocation;
-   }
-   
-   abstract protected void removeHandle(Handle handle) throws Exception;
-}
\ No newline at end of file

Modified: trunk/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -29,7 +29,7 @@
 import javax.transaction.TransactionManager;
 
 import org.jboss.ejb3.Container;
-import org.jboss.ejb3.SessionContainer;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.ejb3.stateful.StatefulContainer;
 import org.jboss.ejb3.stateless.StatelessContainer;
 import org.jboss.iiop.CorbaORB;

Modified: trunk/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -41,8 +41,8 @@
 import org.jboss.ejb3.InitialContextFactory;
 import org.jboss.ejb3.NonSerializableFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
-import org.jboss.ejb3.SessionContainer;
 import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.iiop.CorbaORBService;
 import org.jboss.iiop.codebase.CodebasePolicy;
 import org.jboss.iiop.csiv2.CSIv2Policy;
@@ -92,8 +92,7 @@
 {
    private static final Logger log = Logger.getLogger(IORFactory.class);
    
-   private Container container;
-   private Advisor advisor;
+   private SessionContainer container;
    private RemoteBinding binding;
    private String webServiceName = "jboss:service=WebService"; // TODO: make webServiceName configurable
    
@@ -111,6 +110,15 @@
    private ReferenceFactory referenceFactory;
    private ReferenceFactory homeReferenceFactory;
 
+   public IORFactory(SessionContainer container, RemoteBinding binding)
+   {
+      assert container != null : "container is null";
+      assert binding != null : "binding is null";
+      
+      this.container = container;
+      this.binding = binding;
+   }
+   
    // TODO: create a default IIOP annotation
    private static final IIOP defaultIIOP = new IIOP()
    {
@@ -181,7 +189,7 @@
    
    private IIOP getIIOP()
    {
-      IIOP iiop = (IIOP) advisor.resolveAnnotation(IIOP.class);
+      IIOP iiop = container.getAnnotation(IIOP.class);
       if(iiop != null)
          return iiop;
       
@@ -233,17 +241,6 @@
       getWebServer().removeClassLoader(wcl);
    }
    
-   public void setContainer(Container container)
-   {
-      this.container = container;
-      this.advisor = (Advisor) container; // TODO: why the cast?
-   }
-   
-   public void setRemoteBinding(RemoteBinding binding)
-   {
-      this.binding = binding;
-   }
-   
    public void setWebServiceName(String name)
    {
       this.webServiceName = name;

Modified: trunk/ejb3/src/main/org/jboss/ejb3/remoting/RemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/remoting/RemoteProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/remoting/RemoteProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -34,5 +34,5 @@
 {
    public static final String DEFAULT_CLIENT_BINDING = "socket://0.0.0.0:3873";
 
-   public void setRemoteBinding(RemoteBinding binding);
+//   public void setRemoteBinding(RemoteBinding binding);
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/remoting/ReplicantsManagerInterceptorFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/remoting/ReplicantsManagerInterceptorFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/remoting/ReplicantsManagerInterceptorFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -26,7 +26,7 @@
 import org.jboss.aop.advice.AspectFactory;
 import org.jboss.aop.joinpoint.Joinpoint;
 import org.jboss.aspects.remoting.ReplicantsManagerInterceptor;
-import org.jboss.ejb3.SessionContainer;
+import org.jboss.ejb3.session.SessionContainer;
 
 /**
  * Comment

Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -23,11 +23,10 @@
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
+
 import javax.naming.Context;
 import javax.naming.NamingException;
 
-import org.jboss.aop.Advisor;
-import org.jboss.ejb3.Container;
 import org.jboss.ejb3.ProxyFactory;
 import org.jboss.naming.Util;
 
@@ -37,14 +36,19 @@
  */
 public abstract class BaseServiceProxyFactory implements ProxyFactory
 {
-
-   protected Class proxyClass;
-   protected Constructor proxyConstructor;
-   protected Context proxyFactoryContext;
+   protected Constructor<?> proxyConstructor;
    protected String jndiName;
-   protected Container container;
-   protected Advisor advisor;
+   protected ServiceContainer container;
 
+   protected BaseServiceProxyFactory(ServiceContainer container, String jndiName)
+   {
+      assert container != null : "container is null";
+      assert jndiName != null : "jndiName is null";
+      
+      this.container = container;
+      this.jndiName = jndiName;
+   }
+   
    public Object createHomeProxy()
    {
       throw new UnsupportedOperationException("service can't have a home interface");
@@ -59,12 +63,9 @@
    
    public void start() throws Exception
    {
-      initializeJndiName();
       Class[] interfaces = getInterfaces();
-      Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
-      final Class[] constructorParams =
-              {InvocationHandler.class};
-      proxyConstructor = proxyClass.getConstructor(constructorParams);
+      Class<?> proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
+      proxyConstructor = proxyClass.getConstructor(InvocationHandler.class);
 
       try
       {
@@ -84,12 +85,5 @@
 
    protected abstract Class[] getInterfaces();
 
-   protected abstract void initializeJndiName();
-
-   public void setContainer(Container container)
-   {
-      this.container = container;
-      this.advisor = (Advisor) container;
-   }
-
+   protected final void initializeJndiName() {};
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -21,7 +21,9 @@
  */
 package org.jboss.ejb3.service;
 
+import org.jboss.annotation.ejb.LocalBinding;
 import org.jboss.annotation.ejb.Management;
+import org.jboss.annotation.ejb.RemoteBinding;
 import org.jboss.annotation.ejb.Service;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.MethodInfo;
@@ -38,9 +40,10 @@
 import org.jboss.ejb3.EJBContainerInvocation;
 import org.jboss.ejb3.Ejb3Deployment;
 import org.jboss.ejb3.ProxyFactory;
-import org.jboss.ejb3.SessionContainer;
 import org.jboss.ejb3.asynchronous.AsynchronousInterceptor;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
+import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
 import org.jboss.ejb3.timerservice.TimerServiceFactory;
 import org.jboss.injection.Injector;
@@ -113,6 +116,19 @@
       }
    }
 
+   @Override
+   protected ProxyFactory createProxyFactory(LocalBinding binding)
+   {
+      return new ServiceLocalProxyFactory(this, binding);
+   }
+   
+   @Override
+   protected RemoteProxyFactory createRemoteProxyFactory(RemoteBinding binding)
+   {
+      // TODO Implement clustering
+      return new ServiceRemoteProxyFactory(this, binding);
+   }
+   
    protected Object createSession(Class initTypes[], Object initArgs[])
    {
 //      if((initTypes != null && initTypes.length > 0) || (initArgs != null && initArgs.length > 0))
@@ -496,18 +512,16 @@
       return delegate.getMBeanInfo();
    }
 
-   public Object createLocalProxy(Object id) throws Exception
+   public Object createLocalProxy(Object id, LocalBinding binding) throws Exception
    {
-      ServiceLocalProxyFactory factory = new ServiceLocalProxyFactory();
-      factory.setContainer(this);
+      ServiceLocalProxyFactory factory = new ServiceLocalProxyFactory(this, binding);
 
       return factory.createProxy(id);
    }
    
-   public Object createRemoteProxy(Object id) throws Exception
+   public Object createRemoteProxy(Object id, RemoteBinding binding) throws Exception
    {
-      ServiceRemoteProxyFactory factory = new ServiceRemoteProxyFactory();
-      factory.setContainer(this);
+      ServiceRemoteProxyFactory factory = new ServiceRemoteProxyFactory(this, binding);
 
       return factory.createProxy(id);
    }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceLocalProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -22,6 +22,8 @@
 package org.jboss.ejb3.service;
 
 import java.lang.reflect.InvocationTargetException;
+
+import org.jboss.annotation.ejb.LocalBinding;
 import org.jboss.ejb3.JBossProxy;
 import org.jboss.ejb3.ProxyFactoryHelper;
 
@@ -32,6 +34,11 @@
  */
 public class ServiceLocalProxyFactory extends BaseServiceProxyFactory
 {
+   protected ServiceLocalProxyFactory(ServiceContainer container, LocalBinding binding)
+   {
+      super(container, binding.jndiBinding());
+   }
+
    protected Class[] getInterfaces()
    {
       Class[] localInterfaces = ProxyFactoryHelper.getLocalInterfaces(container);
@@ -41,11 +48,6 @@
       return interfaces;
    }
 
-   protected void initializeJndiName()
-   {
-      jndiName = ProxyFactoryHelper.getLocalJndiName(container);
-   }
-
    public Object createProxy()
    {
       try
@@ -55,19 +57,19 @@
       }
       catch (InstantiationException e)
       {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e);
       }
       catch (IllegalAccessException e)
       {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e);
       }
       catch (IllegalArgumentException e)
       {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e);
       }
       catch (InvocationTargetException e)
       {
-         throw new RuntimeException(e.getTargetException());  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e.getTargetException());
       }
    }
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -41,11 +41,18 @@
    private RemoteBinding binding;
    private InvokerLocator locator;
 
-   public void setRemoteBinding(RemoteBinding binding)
+   protected ServiceRemoteProxyFactory(ServiceContainer container, RemoteBinding binding)
    {
+      super(container, binding.jndiBinding());
+      
       this.binding = binding;
    }
 
+//   public void setRemoteBinding(RemoteBinding binding)
+//   {
+//      this.binding = binding;
+//   }
+
    protected Class[] getInterfaces()
    {
       Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
@@ -55,11 +62,6 @@
       return interfaces;
    }
 
-   protected void initializeJndiName()
-   {
-      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
-   }
-
    public void start() throws Exception
    {
       String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
@@ -83,19 +85,19 @@
       }
       catch (InstantiationException e)
       {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e);
       }
       catch (IllegalAccessException e)
       {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e);
       }
       catch (IllegalArgumentException e)
       {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e);
       }
       catch (InvocationTargetException e)
       {
-         throw new RuntimeException(e.getTargetException());  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e.getTargetException());
       }
    }
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -26,15 +26,14 @@
 import javax.ejb.HomeHandle;
 import javax.ejb.Remote;
 import javax.ejb.RemoteHome;
+
 import org.jboss.annotation.ejb.RemoteBinding;
-import org.jboss.aop.Advisor;
-import org.jboss.ejb3.Container;
 import org.jboss.ejb3.EJBContainer;
 import org.jboss.ejb3.ProxyFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
-import org.jboss.logging.Logger;
 import org.jboss.ejb3.proxy.EJBMetaDataImpl;
 import org.jboss.ejb3.proxy.handle.HomeHandleImpl;
+import org.jboss.logging.Logger;
 
 /**
  * Comment
@@ -44,20 +43,21 @@
  */
 public abstract class BaseSessionProxyFactory implements ProxyFactory
 {
+   @SuppressWarnings("unused")
    private static final Logger log = Logger.getLogger(BaseSessionProxyFactory.class);
    
-   protected Container container;
-   protected Advisor advisor;
-  
-   public Object createHomeProxy()
+   protected SessionContainer container;
+   
+   protected BaseSessionProxyFactory(SessionContainer container)
    {
-      throw new RuntimeException("NYI");
+      assert container != null : "container is null";
+      
+      this.container = container;
    }
    
-   public void setContainer(Container container)
+   public Object createHomeProxy()
    {
-      this.container = container;
-      this.advisor = (Advisor) container;
+      throw new RuntimeException("NYI");
    }
    
    protected void setEjb21Objects(BaseSessionRemoteProxy proxy)
@@ -104,6 +104,5 @@
       EJBMetaDataImpl metadata = new EJBMetaDataImpl(remote, home, pkClass, true, false, homeHandle);
       
       return metadata;
-   }
-   
+   }   
 }

Copied: trunk/ejb3/src/main/org/jboss/ejb3/session/ProxyDeployer.java (from rev 64131, trunk/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/session/ProxyDeployer.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/session/ProxyDeployer.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -0,0 +1,177 @@
+/*
+ * 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.session;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.LocalBinding;
+import org.jboss.annotation.ejb.LocalBindingImpl;
+import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.annotation.ejb.RemoteBindingImpl;
+import org.jboss.annotation.ejb.RemoteBindings;
+import org.jboss.annotation.ejb.RemoteBindingsImpl;
+import org.jboss.aop.Advisor;
+import org.jboss.ejb3.ProxyFactory;
+import org.jboss.ejb3.ProxyFactoryHelper;
+import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.service.ServiceContainer;
+import org.jboss.ejb3.service.ServiceLocalProxyFactory;
+import org.jboss.ejb3.service.ServiceRemoteProxyFactory;
+import org.jboss.ejb3.stateful.StatefulClusterProxyFactory;
+import org.jboss.ejb3.stateful.StatefulContainer;
+import org.jboss.ejb3.stateful.StatefulLocalProxyFactory;
+import org.jboss.ejb3.stateful.StatefulRemoteProxyFactory;
+import org.jboss.ejb3.stateless.StatelessClusterProxyFactory;
+import org.jboss.ejb3.stateless.StatelessLocalProxyFactory;
+import org.jboss.ejb3.stateless.StatelessRemoteProxyFactory;
+import org.jboss.logging.Logger;
+
+/**
+ * Delegatee of a SessionContainer for managing proxy factories.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class ProxyDeployer
+{
+   private static final Logger log = Logger.getLogger(ProxyDeployer.class);
+   private SessionContainer container;
+   private ArrayList<ProxyFactory> proxyFactories = new ArrayList<ProxyFactory>();
+   private RemoteBindings remoteBindings;
+   private LocalBinding localBinding;
+
+   public ProxyDeployer(SessionContainer container)
+   {
+      assert container != null : "container is null";
+      
+      this.container = container;
+   }
+
+   public List<ProxyFactory> getProxyFactories() { return proxyFactories; }
+
+   public void start() throws Exception
+   {
+      if (remoteBindings != null)
+      {
+         RemoteBinding[] list = remoteBindings.value();
+         for(RemoteBinding binding : list)
+         {
+            assert binding.jndiBinding().length() != 0 : "jndiBinding not set on binding " + binding;
+            
+            RemoteProxyFactory factory;
+            Class<? extends RemoteProxyFactory> factoryClass = binding.factory();
+            if (factoryClass.equals(RemoteProxyFactory.class))
+            {
+               factory = container.createRemoteProxyFactory(binding);
+            }
+            else
+            {
+               Constructor<? extends RemoteProxyFactory> constructor = factoryClass.getConstructor(SessionContainer.class, RemoteBinding.class);
+               factory = constructor.newInstance(container, binding);
+            }
+            factory.start();
+            proxyFactories.add(factory);
+         }
+      }
+
+      if (localBinding != null)
+      {
+         ProxyFactory factory = container.createProxyFactory(localBinding);
+         factory.start();
+         proxyFactories.add(factory);
+      }
+   }
+
+   public void initializeLocalBindingMetadata()
+   {
+      localBinding = (LocalBinding) container.resolveAnnotation(LocalBinding.class);
+      if (localBinding == null)
+      {
+         if (ProxyFactoryHelper.getLocalInterfaces(container).length > 0)
+         {
+            localBinding = new LocalBindingImpl(ProxyFactoryHelper.getLocalJndiName(container));
+            container.getAnnotations().addClassAnnotation(LocalBinding.class, localBinding);
+         }
+      }
+   }
+
+   
+   private RemoteBinding initializeRemoteBinding(RemoteBinding binding)
+   {
+      if(binding.jndiBinding().length() == 0)
+      {
+         return new RemoteBindingImpl(ProxyFactoryHelper.getDefaultRemoteJndiName(container), binding.interceptorStack(), binding.clientBindUrl(), binding.factory());
+      }
+      return binding;
+   }
+   
+   public void initializeRemoteBindingMetadata()
+   {
+      remoteBindings = (RemoteBindings) container.resolveAnnotation(RemoteBindings.class);
+      if (remoteBindings == null)
+      {
+         RemoteBinding binding = (RemoteBinding) container.resolveAnnotation(RemoteBinding.class);
+         if (binding == null)
+         {
+            log.debug("no declared remote bindings for : " + container.getEjbName());
+            if (ProxyFactoryHelper.getRemoteInterfaces(container).length > 0)
+            {
+               log.debug("there is remote interfaces for " + container.getEjbName());
+               String jndiName = ProxyFactoryHelper.getDefaultRemoteJndiName(container);
+               log.debug("default remote binding has jndiName of " + jndiName);
+               String uri = ""; // use the default
+               RemoteBinding[] list = {new RemoteBindingImpl(jndiName, "", uri, RemoteProxyFactory.class)};
+               remoteBindings = new RemoteBindingsImpl(list);
+               container.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings);
+            }
+         }
+         else
+         {
+            RemoteBinding[] list = {initializeRemoteBinding(binding)};
+            remoteBindings = new RemoteBindingsImpl(list);
+            container.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings);
+         }
+      }
+      else
+      {
+         List<RemoteBinding> list = new ArrayList<RemoteBinding>();
+         for(RemoteBinding binding : remoteBindings.value())
+         {
+            list.add(initializeRemoteBinding(binding));
+         }
+         remoteBindings = new RemoteBindingsImpl(list);
+         container.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings);
+      }
+   }
+
+   public void stop() throws Exception
+   {
+      for (int i = 0; i < proxyFactories.size(); i++)
+      {
+         ProxyFactory factory = (ProxyFactory) proxyFactories.get(i);
+         factory.stop();
+      }
+   }
+}

Copied: trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContainer.java (from rev 64131, trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContainer.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContainer.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -0,0 +1,506 @@
+/*
+ * 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.session;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.EJBObject;
+import javax.ejb.Handle;
+import javax.ejb.LocalHome;
+import javax.ejb.RemoteHome;
+
+import org.jboss.annotation.ejb.LocalBinding;
+import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.annotation.ejb.RemoteBindings;
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Dispatcher;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.InvocationResponse;
+import org.jboss.aop.util.MethodHashing;
+import org.jboss.aspects.asynch.FutureHolder;
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.EJBContainerInvocation;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.Ejb3Module;
+import org.jboss.ejb3.ProxyFactory;
+import org.jboss.ejb3.ProxyFactoryHelper;
+import org.jboss.ejb3.ProxyUtils;
+import org.jboss.ejb3.ThreadLocalStack;
+import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
+import org.jboss.ejb3.remoting.IsLocalInterceptor;
+import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.stateful.StatefulContainerInvocation;
+import org.jboss.logging.Logger;
+import org.jboss.serial.io.MarshalledObjectForLocalCalls;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public abstract class SessionContainer extends EJBContainer
+{
+   @SuppressWarnings("unused")
+   private static final Logger log = Logger.getLogger(SessionContainer.class);
+
+   protected ProxyDeployer proxyDeployer;
+   protected Map clusterFamilies = new HashMap();
+
+   public class InvokedMethod
+   {
+      public InvokedMethod(boolean localInterface, Method method)
+      {
+         isLocalInterface = localInterface;
+         this.method = method;
+      }
+
+      public boolean isLocalInterface;
+      public Method method;
+   }
+   
+   /**
+    * @param id
+    * @return
+    * @throws Exception
+    * @deprecated       the binding on which this proxy is bound is unspecified
+    */
+   public Object createLocalProxy(Object id) throws Exception
+   {
+      LocalBinding binding = getAnnotation(LocalBinding.class);
+      return createLocalProxy(id, binding);
+   }
+   
+   /**
+    * Create a local proxy for an enterprise bean identified by id on a given binding.
+    * 
+    * @param id             the identifier of the enterprise bean (null for stateless)
+    * @param binding        the binding of the proxy
+    * @return               a proxy to an enterprise bean
+    * @throws Exception
+    */
+   public abstract Object createLocalProxy(Object id, LocalBinding binding) throws Exception;
+   
+   /**
+    * @param id
+    * @return
+    * @throws Exception
+    * @deprecated       the binding on which this proxy is bound is unspecified
+    */
+   @Deprecated
+   public Object createRemoteProxy(Object id) throws Exception
+   {
+      RemoteBinding binding = null;
+      RemoteBindings bindings = getAnnotation(RemoteBindings.class);
+      if (bindings != null)
+         binding = bindings.value()[0];
+      else
+         binding = getAnnotation(RemoteBinding.class);
+      
+      return createRemoteProxy(id, binding);
+   }
+   /**
+    * Create a remote proxy for an enterprise bean identified by id on a given binding.
+    * 
+    * @param id             the identifier of the enterprise bean (null for stateless)
+    * @param binding        the binding of the proxy
+    * @return               a proxy to an enterprise bean
+    * @throws Exception
+    */
+   public abstract Object createRemoteProxy(Object id, RemoteBinding binding) throws Exception;
+
+   protected ThreadLocalStack<InvokedMethod> invokedMethod = new ThreadLocalStack<InvokedMethod>();
+
+   public SessionContainer(ClassLoader cl, String beanClassName, String ejbName, AspectManager manager,
+                           Hashtable ctxProperties, InterceptorInfoRepository interceptorRepository,
+                           Ejb3Deployment deployment)
+   {
+      super(Ejb3Module.BASE_EJB3_JMX_NAME + ",name=" + ejbName, manager, cl, beanClassName, ejbName, ctxProperties, interceptorRepository, deployment);
+      proxyDeployer = new ProxyDeployer(this);
+   }
+
+   /**
+    * Create a local proxy factory.
+    * @return
+    */
+   protected abstract ProxyFactory createProxyFactory(LocalBinding binding);
+   
+   /**
+    * Create a remote proxy factory on the given binding.
+    * 
+    * The jndiBinding is set to a value, the factory is set to it's default value.
+    * 
+    * @param binding
+    * @return
+    */
+   protected abstract RemoteProxyFactory createRemoteProxyFactory(RemoteBinding binding);
+   
+   public Class getInvokedBusinessInterface()
+   {
+      InvokedMethod 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.getRemoteInterfaces(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()");
+   }
+
+   @Override
+   public void processMetadata()
+   {
+      super.processMetadata();
+      proxyDeployer.initializeRemoteBindingMetadata();
+      proxyDeployer.initializeLocalBindingMetadata();
+   }
+
+   protected List<Class<?>> resolveBusinessInterfaces()
+   {
+      List<Class<?>> list = new ArrayList<Class<?>>();
+      list.addAll(Arrays.asList(ProxyFactoryHelper.getLocalInterfaces(this)));
+      list.addAll(Arrays.asList(ProxyFactoryHelper.getRemoteInterfaces(this)));
+      return list;
+   }
+   
+   public void start() throws Exception
+   {
+      super.start();
+      // So that Remoting layer can reference this container easily.
+      Dispatcher.singleton.registerTarget(getObjectName().getCanonicalName(), this);
+      proxyDeployer.start();
+   }
+
+   public Map getClusterFamilies()
+   {
+      return clusterFamilies;
+   }
+
+   public void stop() throws Exception
+   {
+      try
+      {
+         proxyDeployer.stop();
+      }
+      catch (Exception ignore)
+      {
+         log.trace("Proxy deployer stop failed", ignore);
+      }
+      try
+      {
+         Dispatcher.singleton.unregisterTarget(getObjectName().getCanonicalName());
+      }
+      catch (Exception ignore)
+      {
+         log.trace("Dispatcher unregister target failed", ignore);
+      }
+      super.stop();
+   }
+
+   protected void createMethodMap()
+   {
+      super.createMethodMap();
+      try
+      {
+         RemoteHome home = (RemoteHome) resolveAnnotation(RemoteHome.class);
+         if (home != null)
+         {
+            Method[] declaredMethods = home.value().getMethods();
+            for (int i = 0; i < declaredMethods.length; i++)
+            {
+               long hash = MethodHashing.methodHash(declaredMethods[i]);
+               advisedMethods.put(hash, declaredMethods[i]);
+            }
+
+            declaredMethods = javax.ejb.EJBObject.class.getMethods();
+            for (int i = 0; i < declaredMethods.length; i++)
+            {
+               long hash = MethodHashing.methodHash(declaredMethods[i]);
+               advisedMethods.put(hash, declaredMethods[i]);
+            }
+         }
+
+         LocalHome localHome = (LocalHome) resolveAnnotation(LocalHome.class);
+         if (localHome != null)
+         {
+            Method[] declaredMethods = localHome.value().getMethods();
+            for (int i = 0; i < declaredMethods.length; i++)
+            {
+               long hash = MethodHashing.methodHash(declaredMethods[i]);
+               advisedMethods.put(hash, declaredMethods[i]);
+            }
+
+            declaredMethods = javax.ejb.EJBLocalObject.class.getMethods();
+            for (int i = 0; i < declaredMethods.length; i++)
+            {
+               long hash = MethodHashing.methodHash(declaredMethods[i]);
+               advisedMethods.put(hash, declaredMethods[i]);
+            }
+         }
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   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("javax.ejb.EJBObject"))
+         return true;
+
+      if (method.getDeclaringClass().getName().equals("javax.ejb.EJBLocalObject"))
+         return true;
+
+      return false;
+   }
+
+   protected boolean isHandleMethod(Method method)
+   {
+      if (method.getDeclaringClass().getName().equals("javax.ejb.Handle"))
+         return true;
+
+      return false;
+   }
+
+   public static InvocationResponse marshallException(Invocation invocation, Throwable exception, Map responseContext) throws Throwable
+   {
+      if (!invocation.getMetaData().hasTag(IsLocalInterceptor.IS_LOCAL)) throw exception;
+
+      InvocationResponse response = new InvocationResponse();
+      response.setContextInfo(responseContext);
+
+      response.addAttachment(IsLocalInterceptor.IS_LOCAL_EXCEPTION, new MarshalledObjectForLocalCalls(exception));
+
+      return response;
+   }
+
+   public static InvocationResponse marshallResponse(Invocation invocation, Object rtn, Map responseContext)
+           throws java.io.IOException
+   {
+      InvocationResponse response;
+      // marshall return value
+      if (rtn != null && invocation.getMetaData().hasTag(IsLocalInterceptor.IS_LOCAL))
+      {
+         response = new InvocationResponse(new MarshalledObjectForLocalCalls(rtn));
+      }
+      else
+      {
+         response = new InvocationResponse(rtn);
+      }
+      response.setContextInfo(responseContext);
+      return response;
+   }
+   
+   /**
+    * Invoke a method on the virtual EJB bean. The method must be one of the methods defined in one
+    * of the business interfaces (or home interface) of the bean.
+    * 
+    * TODO: work in progress
+    * 
+    * @param factory    the originating end point
+    * @param id         unique identifier (primary key), can be null for stateless
+    * @param method     the business or home method to invoke
+    * @param args       the arguments for the method
+    * @param provider   for asynchronous usage
+    */
+   public Object invoke(ProxyFactory factory, Object id, Method method, Object args[], FutureHolder provider) throws Throwable
+   {
+      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+      pushEnc();
+      try
+      {
+         long hash = MethodHashing.calculateHash(method);
+         MethodInfo info = (MethodInfo) methodInterceptors.get(hash);
+         if (info == null)
+         {
+            throw new RuntimeException(
+                    "Could not resolve beanClass method from proxy call: "
+                            + method.toString());
+         }
+
+         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);
+         }
+
+         // FIXME: Ahem, stateful container invocation works on all.... (violating contract though)
+         EJBContainerInvocation nextInvocation = new StatefulContainerInvocation(info, id);
+         nextInvocation.setAdvisor(this);
+         nextInvocation.setArguments(args);
+         
+         // allow a container to supplement information into an invocation
+         nextInvocation = populateInvocation(nextInvocation);
+
+         ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
+         try
+         {
+            invokedMethod.push(new InvokedMethod(true, method));
+            return nextInvocation.invokeNext();
+         }
+         finally
+         {
+            invokedMethod.pop();
+         }
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(oldLoader);
+         popEnc();
+      }
+   }
+   
+   /**
+    * TODO: work in progress (refactor both invokeHomeMethod's, localHomeInvoke)
+    */
+   private Object invokeHomeMethod(ProxyFactory factory, MethodInfo info, Object args[]) throws Exception
+   {
+      Method unadvisedMethod = info.getUnadvisedMethod();
+      if (unadvisedMethod.getName().equals("create"))
+      {
+         Class[] initParameterTypes = {};
+         Object[] initParameterValues = {};
+         if (unadvisedMethod.getParameterTypes().length > 0)
+         {
+            initParameterTypes = unadvisedMethod.getParameterTypes();
+            initParameterValues = args;
+         }
+
+         Object id = createSession(initParameterTypes, initParameterValues);
+         
+         Object proxy = factory.createProxy(id);
+
+         return proxy;
+      }
+      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);
+      }
+   }
+   
+   /**
+    * Create session to an EJB bean.
+    * 
+    * @param initParameterTypes     the parameter types used by the home's create method
+    * @param initParameterValues    the arguments for the home's create method
+    * @return   the identifier of the session
+    */
+   abstract protected Object createSession(Class initParameterTypes[], Object initParameterValues[]);
+   
+   /**
+    * Destroy a created session.
+    * 
+    * @param id     the identifier of the session
+    */
+   protected void destroySession(Object id)
+   {
+      throw new RuntimeException("NYI");
+   }
+   
+   protected Object invokeEJBObjectMethod(ProxyFactory factory, Object id, MethodInfo info, Object args[]) throws Exception
+   {
+      Method unadvisedMethod = info.getUnadvisedMethod();
+      if(unadvisedMethod.getName().equals("getEJBHome"))
+      {
+         return factory.createHomeProxy();
+      }
+      if(unadvisedMethod.getName().equals("getPrimaryKey"))
+      {
+         return id;
+      }
+      if(unadvisedMethod.getName().equals("isIdentical"))
+      {
+         // object has no identity
+         if(id == null)
+            return false;
+         
+         EJBObject bean = (EJBObject) args[0];
+
+         Object primaryKey = bean.getPrimaryKey();
+         if(primaryKey == null)
+            return false;
+
+         boolean isIdentical = id.equals(primaryKey);
+
+         return isIdentical;
+      }
+      if (unadvisedMethod.getName().equals("remove"))
+      {
+         destroySession(id);
+
+         return null;
+      }
+      throw new RuntimeException("NYI");
+   }
+   
+   /**
+    * Allow a container sub class to supplement an invocation. Per default nothing to supplement.
+    * 
+    * @param invocation
+    * @return
+    */
+   protected EJBContainerInvocation populateInvocation(EJBContainerInvocation invocation)
+   {
+      return invocation;
+   }
+   
+   abstract protected void removeHandle(Handle handle) throws Exception;
+}
\ No newline at end of file

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -31,6 +31,7 @@
 import javax.naming.StringRefAddr;
 import org.jboss.ejb3.JndiProxyFactory;
 import org.jboss.ejb3.ProxyFactory;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.logging.Logger;
 import org.jboss.naming.Util;
 
@@ -42,23 +43,30 @@
  */
 public abstract class BaseStatefulProxyFactory extends org.jboss.ejb3.session.BaseSessionProxyFactory implements ProxyFactory
 {
+   @SuppressWarnings("unused")
    private static final Logger log = Logger.getLogger(BaseStatefulProxyFactory.class);
 
-   protected Class proxyClass;
+//   protected Class proxyClass;
    protected Constructor proxyConstructor;
-   protected Context proxyFactoryContext;
+//   protected Context proxyFactoryContext;
    protected String jndiName;
 
    public static final String PROXY_FACTORY_NAME = "StatefulProxyFactory";
 
+   public BaseStatefulProxyFactory(SessionContainer container, String jndiName)
+   {
+      super(container);
+      
+      assert jndiName != null : "jndiName is null";
+      
+      this.jndiName = jndiName;
+   }
+   
    public void init() throws Exception
    {
-      initializeJndiName();
       Class[] interfaces = getInterfaces();
       Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
-      final Class[] constructorParams =
-              {InvocationHandler.class};
-      proxyConstructor = proxyClass.getConstructor(constructorParams);
+      proxyConstructor = proxyClass.getConstructor(InvocationHandler.class);
    }
 
    public void start() throws Exception
@@ -89,5 +97,5 @@
 
    protected abstract Class[] getInterfaces();
 
-   protected abstract void initializeJndiName();
+   protected final void initializeJndiName() {};
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -39,6 +39,7 @@
 import org.jboss.ejb3.ProxyFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.ha.framework.interfaces.ClusteringTargetsRepository;
 import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
 import org.jboss.ha.framework.interfaces.FirstAvailable;
@@ -66,6 +67,7 @@
 //   public static final String FACTORY_ATTRIBUTE = ",element=ProxyFactory,partition=";
    
    private RemoteBinding binding;
+   private Clustered clustered;
    private InvokerLocator locator;
    private DistributedReplicantManager drm;
    private HATarget hatarget;
@@ -73,9 +75,14 @@
    private LoadBalancePolicy lbPolicy;
    private FamilyWrapper wrapper;
 
-   public void setRemoteBinding(RemoteBinding binding)
+   public StatefulClusterProxyFactory(StatefulContainer container, RemoteBinding binding, Clustered clustered)
    {
+      super(container, binding.jndiBinding());
+      
+      assert clustered != null : "clustered is null";
+      
       this.binding = binding;
+      this.clustered = clustered;
    }
 
    protected Class[] getInterfaces()
@@ -87,17 +94,10 @@
       return interfaces;
    }
 
-   protected void initializeJndiName()
-   {
-      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
-   }
-
    public void start() throws Exception
    {
       String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
-      Clustered clustered = (Clustered) advisor.resolveAnnotation(Clustered.class);
-      if (clustered == null) throw new RuntimeException("Could not find @Clustered annotation.  Cannot deploy.");
       String partitionName = ((StatefulContainer) container).getPartitionName();
       proxyFamilyName = ((StatefulContainer) container).getDeploymentQualifiedName() + locator.getProtocol() + partitionName;
       HAPartition partition = (HAPartition) container.getInitialContext().lookup("/HAPartition/" + partitionName);
@@ -110,7 +110,7 @@
       }
       else
       {
-         lbPolicy = (LoadBalancePolicy) clustered.loadBalancePolicy().newInstance();
+         lbPolicy = clustered.loadBalancePolicy().newInstance();
       }
       wrapper = new FamilyWrapper(proxyFamilyName, hatarget.getReplicants());
       
@@ -155,19 +155,19 @@
       }
       catch (InstantiationException e)
       {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e);
       }
       catch (IllegalAccessException e)
       {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e);
       }
       catch (IllegalArgumentException e)
       {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e);
       }
       catch (InvocationTargetException e)
       {
-         throw new RuntimeException(e.getTargetException());  //To change body of catch statement use Options | File Templates.
+         throw new RuntimeException(e.getTargetException());
       }
    }
 
@@ -189,7 +189,7 @@
    protected StatefulHandleImpl getHandle()
    {
       StatefulHandleImpl handle = new StatefulHandleImpl();
-      RemoteBinding remoteBinding = (RemoteBinding)advisor.resolveAnnotation(RemoteBinding.class);
+      RemoteBinding remoteBinding = (RemoteBinding)container.resolveAnnotation(RemoteBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
  

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -38,6 +38,7 @@
 import javax.ejb.RemoteHome;
 import javax.ejb.TimerService;
 
+import org.jboss.annotation.ejb.Clustered;
 import org.jboss.annotation.ejb.LocalBinding;
 import org.jboss.annotation.ejb.RemoteBinding;
 import org.jboss.annotation.ejb.RemoteBindings;
@@ -54,11 +55,12 @@
 import org.jboss.ejb3.ProxyFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.ProxyUtils;
-import org.jboss.ejb3.SessionContainer;
 import org.jboss.ejb3.cache.StatefulCache;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
 import org.jboss.ejb3.proxy.EJBMetaDataImpl;
 import org.jboss.ejb3.proxy.handle.HomeHandleImpl;
+import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.injection.Injector;
 import org.jboss.injection.JndiFieldInjector;
 import org.jboss.logging.Logger;
@@ -83,6 +85,26 @@
       beanContextClass = StatefulBeanContext.class;
    }
 
+   @Override
+   protected ProxyFactory createProxyFactory(LocalBinding binding)
+   {
+      return new StatefulLocalProxyFactory(this, binding);
+   }
+   
+   @Override
+   protected RemoteProxyFactory createRemoteProxyFactory(RemoteBinding binding)
+   {
+      Clustered clustered = getAnnotation(Clustered.class);
+      if (clustered != null)
+      {
+         return new StatefulClusterProxyFactory(this, binding, clustered);
+      }
+      else
+      {
+         return new StatefulRemoteProxyFactory(this, binding);
+      }
+   }
+   
    public void start() throws Exception
    {
       try
@@ -604,10 +626,8 @@
          }
 
          LocalBinding binding = (LocalBinding) resolveAnnotation(LocalBinding.class);
-         ;
 
-         StatefulLocalProxyFactory factory = new StatefulLocalProxyFactory();
-         factory.setContainer(this);
+         StatefulLocalProxyFactory factory = new StatefulLocalProxyFactory(this, binding);
          factory.init();
 
          Object proxy = factory.createProxy(initParameterTypes,
@@ -629,27 +649,24 @@
       }
    }
    
-   public Object createLocalProxy(Object id) throws Exception
+   public Object createLocalProxy(Object id, LocalBinding binding) throws Exception
    {
-      StatefulLocalProxyFactory factory = new StatefulLocalProxyFactory();
-      factory.setContainer(this);
+      StatefulLocalProxyFactory factory = new StatefulLocalProxyFactory(this, binding);
       factory.init();
 
       return factory.createProxy(id);
    }
    
-   public Object createRemoteProxy(Object id) throws Exception
+   public Object createRemoteProxy(Object id, RemoteBinding binding) throws Exception
    {
-      RemoteBinding binding = null;
-      RemoteBindings bindings = (RemoteBindings) resolveAnnotation(RemoteBindings.class);
-      if (bindings != null)
-         binding = bindings.value()[0];
-      else
-         binding = (RemoteBinding) resolveAnnotation(RemoteBinding.class);
+//      RemoteBinding binding = null;
+//      RemoteBindings bindings = (RemoteBindings) resolveAnnotation(RemoteBindings.class);
+//      if (bindings != null)
+//         binding = bindings.value()[0];
+//      else
+//         binding = (RemoteBinding) resolveAnnotation(RemoteBinding.class);
       
-      StatefulRemoteProxyFactory factory = new StatefulRemoteProxyFactory();
-      factory.setContainer(this);
-      factory.setRemoteBinding(binding);
+      StatefulRemoteProxyFactory factory = new StatefulRemoteProxyFactory(this, binding);
       factory.init();
 
       if (id != null)
@@ -685,9 +702,7 @@
                  info, statefulInvocation, initParameterTypes,
                  initParameterValues);
 
-         StatefulRemoteProxyFactory factory = new StatefulRemoteProxyFactory();
-         factory.setContainer(this);
-         factory.setRemoteBinding(binding);
+         StatefulRemoteProxyFactory factory = new StatefulRemoteProxyFactory(this, binding);
          factory.init();
 
          Object proxy = null;

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -29,6 +29,7 @@
 import org.jboss.ejb3.JBossProxy;
 import org.jboss.ejb3.NonSerializableFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
+import org.jboss.ejb3.session.SessionContainer;
 
 
 /**
@@ -39,6 +40,11 @@
  */
 public class StatefulLocalProxyFactory extends BaseStatefulProxyFactory
 {
+   public StatefulLocalProxyFactory(SessionContainer container, LocalBinding binding)
+   {
+      super(container, binding.jndiBinding());
+   }
+
    protected Class[] getInterfaces()
    {
       Class[] interfaces;
@@ -70,14 +76,9 @@
    
    protected boolean bindHomeAndBusinessTogether(StatefulContainer container)
    {
-      return ProxyFactoryHelper.getLocalHomeJndiName(container).equals(ProxyFactoryHelper.getLocalJndiName(container));
+      return ProxyFactoryHelper.getLocalHomeJndiName(container).equals(jndiName);
    }
 
-   protected void initializeJndiName()
-   {
-      jndiName = ProxyFactoryHelper.getLocalJndiName(container);
-   }
-
    public void start() throws Exception
    {
       super.start();
@@ -200,7 +201,7 @@
    protected StatefulHandleImpl getHandle()
    {
       StatefulHandleImpl handle = new StatefulHandleImpl();
-      LocalBinding remoteBinding = (LocalBinding) advisor.resolveAnnotation(LocalBinding.class);
+      LocalBinding remoteBinding = (LocalBinding) container.resolveAnnotation(LocalBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -39,6 +39,7 @@
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.remoting.IsLocalProxyFactoryInterceptor;
 import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.logging.Logger;
 import org.jboss.naming.Util;
 import org.jboss.remoting.InvokerLocator;
@@ -60,8 +61,10 @@
    private RemoteBinding binding;
    private InvokerLocator locator;
 
-   public void setRemoteBinding(RemoteBinding binding)
+   public StatefulRemoteProxyFactory(SessionContainer container, RemoteBinding binding)
    {
+      super(container, binding.jndiBinding());
+      
       this.binding = binding;
    }
 
@@ -97,11 +100,6 @@
       return ProxyFactoryHelper.getHomeJndiName(container).equals(ProxyFactoryHelper.getRemoteJndiName(container));
    }
 
-   protected void initializeJndiName()
-   {
-      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
-   }
-
    public void init() throws Exception
    {
       super.init();
@@ -220,9 +218,7 @@
    protected StatefulHandleImpl getHandle()
    {
       StatefulHandleImpl handle = new StatefulHandleImpl();
-      RemoteBinding remoteBinding = (RemoteBinding) advisor.resolveAnnotation(RemoteBinding.class);
-      if (remoteBinding != null)
-         handle.jndiName = remoteBinding.jndiBinding();
+      handle.jndiName = jndiName;
 
       return handle;
    }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -37,6 +37,7 @@
 import org.jboss.aop.Advisor;
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.ProxyFactory;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.logging.Logger;
 import org.jboss.naming.Util;
 
@@ -51,14 +52,20 @@
    private static final Logger log = Logger.getLogger(BaseStatelessProxyFactory.class);
 
 //   protected Class proxyClass;
-//   protected Constructor proxyConstructor;
-   protected Context proxyFactoryContext;
+//   protected Context proxyFactoryContext;
    protected String jndiName;
    
-   private javassist.util.proxy.ProxyFactory proxyFactory;
-   private Class proxyClass;
    private Constructor proxyConstructor;
    
+   public BaseStatelessProxyFactory(SessionContainer container, String jndiName)
+   {
+      super(container);
+      
+      assert jndiName != null : "jndiName is null";
+      
+      this.jndiName = jndiName;
+   }
+   
    /**
     * Adapt the JDK to cglib.
     * 
@@ -232,7 +239,7 @@
 
    protected abstract Class[] getInterfaces();
 
-   protected abstract void initializeJndiName();
+   protected final void initializeJndiName() {};
 
    protected void bindProxy(Object proxy) throws NamingException
    {
@@ -247,11 +254,4 @@
          throw namingException;
       }
    }
-   
-   public void setContainer(Container container)
-   {
-      this.container = container;
-      this.advisor = (Advisor) container;
-   }
-
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -21,7 +21,6 @@
  */
 package org.jboss.ejb3.stateless;
 
-import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -34,7 +33,7 @@
 import org.jboss.ejb3.JBossProxy;
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.remoting.RemoteProxyFactory;
-import org.jboss.ejb3.stateful.StatefulContainer;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.ha.framework.interfaces.ClusteringTargetsRepository;
 import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
 import org.jboss.ha.framework.interfaces.HAPartition;
@@ -57,6 +56,7 @@
    private static final Logger log = Logger.getLogger(StatelessClusterProxyFactory.class);
 
    private RemoteBinding binding;
+   private Clustered clustered;
    private InvokerLocator locator;
    private DistributedReplicantManager drm;
    private HATarget hatarget;
@@ -65,9 +65,14 @@
    private FamilyWrapper wrapper;
    private Object proxy;
 
-   public void setRemoteBinding(RemoteBinding binding)
+   public StatelessClusterProxyFactory(SessionContainer container, RemoteBinding binding, Clustered clustered)
    {
+      super(container, binding.jndiBinding());
+      
+      assert clustered != null : "clustered is null";
+      
       this.binding = binding;
+      this.clustered = clustered;
    }
 
    protected Class[] getInterfaces()
@@ -79,17 +84,10 @@
       return interfaces;
    }
 
-   protected void initializeJndiName()
-   {
-      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
-   }
-
    public void start() throws Exception
    {
       String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
-      Clustered clustered = (Clustered) advisor.resolveAnnotation(Clustered.class);
-      if (clustered == null) throw new RuntimeException("Could not find @Clustered annotation.  Cannot deploy.");
       String partitionName = ((StatelessContainer) container).getPartitionName();
       proxyFamilyName = ((StatelessContainer) container).getDeploymentQualifiedName() + locator.getProtocol() + partitionName;
       HAPartition partition = (HAPartition) container.getInitialContext().lookup("/HAPartition/" + partitionName);
@@ -102,7 +100,7 @@
       }
       else
       {
-         lbPolicy = (LoadBalancePolicy) clustered.loadBalancePolicy().newInstance();
+         lbPolicy = clustered.loadBalancePolicy().newInstance();
       }
       wrapper = new FamilyWrapper(proxyFamilyName, hatarget.getReplicants());
       
@@ -165,9 +163,7 @@
    protected StatelessHandleImpl getHandle()
    {
       StatelessHandleImpl handle = new StatelessHandleImpl();
-      RemoteBinding remoteBinding = (RemoteBinding)advisor.resolveAnnotation(RemoteBinding.class);
-      if (remoteBinding != null)
-         handle.jndiName = remoteBinding.jndiBinding();
+      handle.jndiName = binding.jndiBinding();
  
       return handle;
    }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -32,6 +32,7 @@
 import javax.ejb.TimerService;
 import javax.naming.NamingException;
 
+import org.jboss.annotation.ejb.Clustered;
 import org.jboss.annotation.ejb.LocalBinding;
 import org.jboss.annotation.ejb.RemoteBinding;
 import org.jboss.annotation.ejb.RemoteBindings;
@@ -47,10 +48,12 @@
 import org.jboss.ejb3.BeanContextLifecycleCallback;
 import org.jboss.ejb3.EJBContainerInvocation;
 import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.ProxyFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.ProxyUtils;
-import org.jboss.ejb3.SessionContainer;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
+import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
 import org.jboss.ejb3.timerservice.TimerServiceFactory;
 import org.jboss.logging.Logger;
@@ -78,6 +81,22 @@
       beanContextClass = StatelessBeanContext.class;
    }
 
+   @Override
+   protected ProxyFactory createProxyFactory(LocalBinding binding)
+   {
+      return new StatelessLocalProxyFactory(this, binding);
+   }
+   
+   @Override
+   protected RemoteProxyFactory createRemoteProxyFactory(RemoteBinding binding)
+   {
+      Clustered clustered = getAnnotation(Clustered.class);
+      if(clustered != null)
+         return new StatelessClusterProxyFactory(this, binding, clustered);
+      else
+         return new StatelessRemoteProxyFactory(this, binding);
+   }
+   
    public Object createSession(Class initTypes[], Object initArgs[])
    {
       if((initTypes != null && initTypes.length > 0) || (initArgs != null && initArgs.length > 0))
@@ -356,9 +375,10 @@
       if (unadvisedMethod.getName().equals("create"))
       {
          LocalBinding binding = (LocalBinding) resolveAnnotation(LocalBinding.class);
-
-         StatelessLocalProxyFactory factory = new StatelessLocalProxyFactory();
-         factory.setContainer(this);
+         
+         // FIXME: why this binding? Could be another one. (there is only one local binding, but that's another bug)
+         
+         StatelessLocalProxyFactory factory = new StatelessLocalProxyFactory(this, binding);
          factory.init();
 
          Object proxy = factory.createProxy();
@@ -371,10 +391,9 @@
       }
    }
    
-   public Object createLocalProxy(Object id) throws Exception
+   public Object createLocalProxy(Object id, LocalBinding binding) throws Exception
    {
-      StatelessLocalProxyFactory factory = new StatelessLocalProxyFactory();
-      factory.setContainer(this);
+      StatelessLocalProxyFactory factory = new StatelessLocalProxyFactory(this, binding);
       factory.init();
 
       Object proxy = factory.createProxy();
@@ -382,19 +401,17 @@
       return proxy;
    }
    
-   public Object createRemoteProxy(Object id) throws Exception
+   public Object createRemoteProxy(Object id, RemoteBinding binding) throws Exception
    {
-      RemoteBinding binding = null;
+//      RemoteBinding binding = null;
+//
+//      RemoteBindings bindings = (RemoteBindings) resolveAnnotation(RemoteBindings.class);
+//      if (bindings != null)
+//         binding = bindings.value()[0];
+//      else
+//         binding = (RemoteBinding) resolveAnnotation(RemoteBinding.class);
 
-      RemoteBindings bindings = (RemoteBindings) resolveAnnotation(RemoteBindings.class);
-      if (bindings != null)
-         binding = bindings.value()[0];
-      else
-         binding = (RemoteBinding) resolveAnnotation(RemoteBinding.class);
-
-      StatelessRemoteProxyFactory factory = new StatelessRemoteProxyFactory();
-      factory.setContainer(this);
-      factory.setRemoteBinding(binding);
+      StatelessRemoteProxyFactory factory = new StatelessRemoteProxyFactory(this, binding);
       factory.init();
 
       return factory.createProxy();
@@ -413,9 +430,9 @@
          else
             binding = (RemoteBinding) resolveAnnotation(RemoteBinding.class);
 
-         StatelessRemoteProxyFactory factory = new StatelessRemoteProxyFactory();
-         factory.setContainer(this);
-         factory.setRemoteBinding(binding);
+         // FIXME: why this binding? Better select the proper one.
+         
+         StatelessRemoteProxyFactory factory = new StatelessRemoteProxyFactory(this, binding);
          factory.init();
 
          return factory.createProxy();

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -28,6 +28,7 @@
 import org.jboss.ejb3.JBossProxy;
 import org.jboss.ejb3.NonSerializableFactory;
 import org.jboss.ejb3.ProxyFactoryHelper;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.logging.Logger;
 
 
@@ -41,6 +42,11 @@
 {
    private static final Logger log = Logger.getLogger(StatelessLocalProxyFactory.class);
    
+   public StatelessLocalProxyFactory(SessionContainer container, LocalBinding binding)
+   {
+      super(container, binding.jndiBinding());
+   }
+
    protected Class[] getInterfaces()
    {
       Class[] interfaces;
@@ -79,14 +85,9 @@
    
    protected boolean bindHomeAndBusinessTogether(EJBContainer container)
    {
-      return ProxyFactoryHelper.getLocalHomeJndiName(container).equals(ProxyFactoryHelper.getLocalJndiName(container));
+      return ProxyFactoryHelper.getLocalHomeJndiName(container).equals(jndiName);
    }
 
-   protected void initializeJndiName()
-   {
-      jndiName = ProxyFactoryHelper.getLocalJndiName(container);
-   }
-
    @Override
    public void start() throws Exception
    {
@@ -146,7 +147,7 @@
    protected StatelessHandleImpl getHandle()
    {
       StatelessHandleImpl handle = new StatelessHandleImpl();
-      LocalBinding remoteBinding = (LocalBinding) advisor.resolveAnnotation(LocalBinding.class);
+      LocalBinding remoteBinding = (LocalBinding) container.resolveAnnotation(LocalBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding();
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -31,6 +31,7 @@
 import org.jboss.ejb3.JBossProxy;
 import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.logging.Logger;
 import org.jboss.remoting.InvokerLocator;
 import org.jboss.naming.Util;
@@ -49,8 +50,10 @@
    protected RemoteBinding binding;
    protected InvokerLocator locator;
 
-   public void setRemoteBinding(RemoteBinding binding)
+   public StatelessRemoteProxyFactory(SessionContainer container, RemoteBinding binding)
    {
+      super(container, binding.jndiBinding());
+      
       this.binding = binding;
    }
 
@@ -98,11 +101,6 @@
       return ProxyFactoryHelper.getHomeJndiName(container).equals(ProxyFactoryHelper.getRemoteJndiName(container));
    }
 
-   protected void initializeJndiName()
-   {
-      jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
-   }
-
    public void init() throws Exception
    {
       super.init();
@@ -146,7 +144,7 @@
    protected StatelessHandleImpl getHandle()
    {
       StatelessHandleImpl handle = new StatelessHandleImpl();
-      RemoteBinding remoteBinding = (RemoteBinding) advisor.resolveAnnotation(RemoteBinding.class);
+      RemoteBinding remoteBinding = (RemoteBinding) container.resolveAnnotation(RemoteBinding.class);
       if (remoteBinding != null)
          handle.jndiName = remoteBinding.jndiBinding() ;
 

Added: trunk/ejb3/src/main/org/jboss/ejb3/util/Debugger.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/util/Debugger.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/util/Debugger.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.util;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class Debugger
+{
+   public static StackTraceElement constructionPoint()
+   {
+      return new Exception().getStackTrace()[2];
+   }
+}


Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/util/Debugger.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/bank/TellerRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/bank/TellerRemoteProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/bank/TellerRemoteProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.test.bank;
 
+import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.logging.Logger;
 
 /**
@@ -33,6 +35,11 @@
 {
    private static final Logger log = Logger.getLogger(TellerRemoteProxyFactory.class);
    
+   public TellerRemoteProxyFactory(SessionContainer container, RemoteBinding binding)
+   {
+      super(container, binding);
+   }
+
    protected Class[] getInterfaces()
    {
       Class[] remoteInterfaces = super.getInterfaces();

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulRemoteProxyFactory.java	2007-07-19 11:33:24 UTC (rev 64132)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulRemoteProxyFactory.java	2007-07-19 12:20:27 UTC (rev 64133)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.test.stateful;
 
+import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.logging.Logger;
 
 /**
@@ -31,8 +33,14 @@
  */
 public class StatefulRemoteProxyFactory extends org.jboss.ejb3.stateful.StatefulRemoteProxyFactory
 {
+   @SuppressWarnings("unused")
    private static final Logger log = Logger.getLogger(StatefulRemoteProxyFactory.class);
    
+   public StatefulRemoteProxyFactory(SessionContainer container, RemoteBinding binding)
+   {
+      super(container, binding);
+   }
+
    protected Class[] getInterfaces()
    {
       Class[] remoteInterfaces = super.getInterfaces();




More information about the jboss-cvs-commits mailing list