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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 27 01:13:00 EDT 2008


Author: ALRubinger
Date: 2008-03-27 01:13:00 -0400 (Thu, 27 Mar 2008)
New Revision: 71336

Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/BaseSessionProxyFactory.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
Log:
[EJBTHREE-1059] Validate EJB2.1 Views for Home.create<METHOD> to return EJBObject/EJBLocalObject only (no business interfaces)

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/BaseSessionProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2008-03-27 05:11:37 UTC (rev 71335)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2008-03-27 05:13:00 UTC (rev 71336)
@@ -25,6 +25,9 @@
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
 
 import javax.ejb.EJBException;
 import javax.ejb.EJBHome;
@@ -62,6 +65,8 @@
    protected String containerClusterUid;
    protected boolean isClustered = false;
    
+   private static final String METHOD_PREFIX_EJB21_CREATE = "create";
+   
    public BaseSessionProxyFactory()
    {
    }
@@ -172,7 +177,7 @@
     * @param localOrRemoteInterfaces
     * @throws RuntimeException
     */
-   protected void ensureEjb21ViewComplete(Class<?> home,Class<?>[] localOrRemoteInterfaces) throws RuntimeException
+   protected void validateCompleteEjb21View(Class<?> home, Class<?>[] localOrRemoteInterfaces) throws RuntimeException
    {
       // Ensure specified home is EJBHome or EJBLocalHome
       assert (home == null || (EJBHome.class.isAssignableFrom(home) || EJBLocalHome.class.isAssignableFrom(home)));
@@ -183,7 +188,7 @@
          assert (EJBObject.class.isAssignableFrom(localOrRemoteInterface) || EJBLocalObject.class
                .isAssignableFrom(localOrRemoteInterface));
       }
-      
+
       // If home is defined and there are no local/remote interfaces
       if (home != null && localOrRemoteInterfaces.length == 0)
       {
@@ -198,8 +203,106 @@
          throw new RuntimeException("EJBTHREE-1075: " + container.getBeanClassName()
                + " defines local/remote interfaces" + " but provides no home; EJB 2.1 view cannot be realized");
       }
+   }
+   
+   /**
+    * Validates that the specified EJB2.1 Home interface returns only
+    * valid remote/local interfaces from "create<METHOD>" methods.  If no
+    * home is defined, the method will return without further checks
+    * 
+    * @param home
+    */
+   protected void validateHomeReturnsNoBusinessInterfaces(Class<?> home)
+   {
+      // Only perform if home is defined; otherwise no EJB2.1 view
+      if(home==null)
+      {
+         return;
+      }
+      
+      // Sanity checks
+      assert EJBHome.class.isAssignableFrom(home) || EJBLocalHome.class.isAssignableFrom(home) : "Specified home interface, "
+            + home.getName() + ", must be of type " + EJBHome.class.getName() + " or " + EJBLocalHome.class.getName();
+      assert home.isInterface() : "Specified home interface, " + home.getName() + " is not an interface.";
 
+      // Initialize
+      Set<Method> creates = new HashSet<Method>();
+
+      // Obtain all "create<METHOD>" methods
+      Method[] all = home.getDeclaredMethods();
+
+      // For each method
+      for (Method method : all)
+      {
+         // If a "create<METHOD>" method
+         if (method.getName().startsWith(BaseSessionProxyFactory.METHOD_PREFIX_EJB21_CREATE))
+         {
+            // Add to the Set of Creates
+            creates.add(method);
+         }
+      }
+
+      // For all "create<METHOD>" methods
+      for (Method create : creates)
+      {
+         // Init
+         boolean isLocal = true;
+
+         // Set as remote if applicable
+         if (EJBHome.class.isAssignableFrom(home))
+         {
+            isLocal = false;
+         }
+
+         // If local (EJBLocalHome)
+         if (isLocal)
+         {
+            // Validate return type is local interface
+            if (!EJBLocalObject.class.isAssignableFrom(create.getReturnType()))
+            {
+               throw new RuntimeException("EJB 3 Core Specification Section 4.6.10: "
+                     + "The return type for a create<METHOD> method must be"
+                     + " the session bean's local interface type.  " + home.getName() + " has method "
+                     + create.getName() + " which returns " + create.getReturnType().getName() + ". [EJBTHREE-1059]");
+            }
+         }
+         // If remote (EJBHome)
+         else
+         {
+            // Validate return type is remote interface
+            if (!EJBObject.class.isAssignableFrom(create.getReturnType()))
+            {
+               throw new RuntimeException("EJB 3 Core Specification Section 4.6.8: "
+                     + "The return type for a create<METHOD> method "
+                     + "must be the session bean’s remote interface type.  " + home.getName() + " has method "
+                     + create.getName() + " which returns " + create.getReturnType().getName() + ". [EJBTHREE-1059]");
+            }
+         }
+      }
    }
    
-   protected abstract void ensureEjb21ViewComplete();
+   /**
+    * Validates that any EJB2.1 Views associated with this ProxyFactory 
+    * are valid
+    * 
+    * @param home
+    * @param localOrRemoteInterfaces
+    * @throws RuntimeException
+    */
+   protected void validateEjb21Views(Class<?> home,Class<?>[] localOrRemoteInterfaces) throws RuntimeException
+   {
+      // Ensure EJB2.1 Views are complete (EJBTHREE-1075)
+      this.validateCompleteEjb21View(home, localOrRemoteInterfaces);
+      
+      // Ensure EJB2.1 Home returns only local/remote interfaces
+      this.validateHomeReturnsNoBusinessInterfaces(home);
+   }
+   
+   
+   
+   /**
+    * Validates that any EJB2.1 Views associated with this ProxyFactory 
+    * are valid
+    */
+   protected abstract void validateEjb21Views();
 }

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2008-03-27 05:11:37 UTC (rev 71335)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2008-03-27 05:13:00 UTC (rev 71336)
@@ -27,9 +27,12 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.ejb.EJBLocalObject;
+import javax.ejb.EJBObject;
 import javax.naming.Context;
 import javax.naming.Name;
 import javax.naming.NamingException;
@@ -162,7 +165,7 @@
    public void init() throws Exception
    {
       // Ensure EJB2.1 View is Complete
-      this.ensureEjb21ViewComplete();
+      this.validateEjb21Views();
       
       // Create the Proxy Constructors
       this.createProxyConstructors();
@@ -247,7 +250,7 @@
       SessionContainer container = this.getContainer();
 
       // Initialize array of interfaces
-      Class<?>[] intfs = null;
+      Set<Class<?>> intfs = new HashSet<Class<?>>();
 
       // If Local
       if (accessType.equals(ProxyAccessType.LOCAL))
@@ -256,12 +259,16 @@
          // If business
          if (specType.equals(SpecificationInterfaceType.EJB30_BUSINESS))
          {
-            intfs = ProxyFactoryHelper.getLocalBusinessInterfaces(container);
+            intfs.addAll(Arrays.asList(ProxyFactoryHelper.getLocalBusinessInterfaces(container)));
          }
          // If EJBLocalObject
          else
          {
-            intfs = ProxyFactoryHelper.getLocalInterfaces(container);
+            // Add local interfaces
+            intfs.addAll(Arrays.asList(ProxyFactoryHelper.getLocalInterfaces(container)));
+            
+            // Add EJBLocalObject
+            intfs.add(EJBLocalObject.class);
          }
       }
       // If remote
@@ -270,12 +277,16 @@
          // If business
          if (specType.equals(SpecificationInterfaceType.EJB30_BUSINESS))
          {
-            intfs = ProxyFactoryHelper.getRemoteBusinessInterfaces(container);
+            intfs.addAll(Arrays.asList(ProxyFactoryHelper.getRemoteBusinessInterfaces(container)));
          }
          // If EJBObject
          else
          {
-            intfs = ProxyFactoryHelper.getRemoteInterfaces(container);
+            // Add remote interfaces
+            intfs.addAll(Arrays.asList(ProxyFactoryHelper.getRemoteInterfaces(container)));
+            
+            // Add EJBObject
+            intfs.add(EJBObject.class);
          }
       }
 

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2008-03-27 05:11:37 UTC (rev 71335)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2008-03-27 05:13:00 UTC (rev 71336)
@@ -96,7 +96,7 @@
       return ProxyAccessType.REMOTE;
    }
    
-   protected void ensureEjb21ViewComplete()
+   protected void validateEjb21Views()
    { 
       // Obtain Container
       SessionContainer container = this.getContainer();
@@ -105,7 +105,7 @@
       RemoteHome remoteHome = container.getAnnotation(RemoteHome.class);
 
       // Ensure that if EJB 2.1 Components are defined, they're complete
-      this.ensureEjb21ViewComplete(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
+      this.validateEjb21Views(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
             .getRemoteInterfaces(container));
 
    }

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2008-03-27 05:11:37 UTC (rev 71335)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2008-03-27 05:13:00 UTC (rev 71336)
@@ -75,7 +75,7 @@
       return ProxyAccessType.LOCAL;
    }
    
-   protected void ensureEjb21ViewComplete()
+   protected void validateEjb21Views()
    { 
       // Obtain Container
       SessionContainer container = this.getContainer();
@@ -84,7 +84,7 @@
       LocalHome localHome = container.getAnnotation(LocalHome.class);
 
       // Ensure that if EJB 2.1 Components are defined, they're complete
-      this.ensureEjb21ViewComplete(localHome == null ? null : localHome.value(), ProxyFactoryHelper
+      this.validateEjb21Views(localHome == null ? null : localHome.value(), ProxyFactoryHelper
             .getLocalInterfaces(container));
 
    }

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2008-03-27 05:11:37 UTC (rev 71335)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2008-03-27 05:13:00 UTC (rev 71336)
@@ -79,7 +79,7 @@
       return ProxyAccessType.REMOTE;
    }
    
-   protected void ensureEjb21ViewComplete()
+   protected void validateEjb21Views()
    { 
       // Obtain Container
       SessionContainer container = this.getContainer();
@@ -88,7 +88,7 @@
       RemoteHome remoteHome = container.getAnnotation(RemoteHome.class);
 
       // Ensure that if EJB 2.1 Components are defined, they're complete
-      this.ensureEjb21ViewComplete(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
+      this.validateEjb21Views(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
             .getRemoteInterfaces(container));
 
    }

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2008-03-27 05:11:37 UTC (rev 71335)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2008-03-27 05:13:00 UTC (rev 71336)
@@ -177,7 +177,7 @@
    {
       initializeJndiName();
       Class<?>[] interfaces = getInterfaces();
-      this.ensureEjb21ViewComplete();
+      this.validateEjb21Views();
       
       
       /* plain jdk */
@@ -241,7 +241,7 @@
 
    protected abstract Class<?>[] getInterfaces();
    
-   protected abstract void ensureEjb21ViewComplete();
+   protected abstract void validateEjb21Views();
 
    protected final void initializeJndiName() {};
 

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java	2008-03-27 05:11:37 UTC (rev 71335)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java	2008-03-27 05:13:00 UTC (rev 71336)
@@ -103,7 +103,7 @@
       return interfaces.toArray(new Class[]{});
    }
    
-   protected void ensureEjb21ViewComplete()
+   protected void validateEjb21Views()
    { 
       // Obtain Container
       SessionContainer container = this.getContainer();
@@ -112,7 +112,7 @@
       RemoteHome remoteHome = container.getAnnotation(RemoteHome.class);
 
       // Ensure that if EJB 2.1 Components are defined, they're complete
-      this.ensureEjb21ViewComplete(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
+      this.validateEjb21Views(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
             .getRemoteInterfaces(container));
 
    }

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2008-03-27 05:11:37 UTC (rev 71335)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2008-03-27 05:13:00 UTC (rev 71336)
@@ -88,14 +88,14 @@
       {});
    }
    
-   protected void ensureEjb21ViewComplete(){
+   protected void validateEjb21Views(){
       
       EJBContainer container = this.getContainer();
       
       LocalHome localHome = container.getAnnotation(LocalHome.class);
       
       // Ensure that if EJB 2.1 Components are defined, they're complete
-      this.ensureEjb21ViewComplete(localHome == null ? null : localHome.value(), ProxyFactoryHelper
+      this.validateEjb21Views(localHome == null ? null : localHome.value(), ProxyFactoryHelper
             .getLocalInterfaces(container));
    }
    

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2008-03-27 05:11:37 UTC (rev 71335)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2008-03-27 05:13:00 UTC (rev 71336)
@@ -98,7 +98,7 @@
       {});
    }
    
-   protected void ensureEjb21ViewComplete()
+   protected void validateEjb21Views()
    {
       // Obtain Container
       EJBContainer container = this.getContainer();
@@ -107,7 +107,7 @@
       RemoteHome remoteHome = container.getAnnotation(RemoteHome.class);
 
       // Ensure that if EJB 2.1 Components are defined, they're complete
-      this.ensureEjb21ViewComplete(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
+      this.validateEjb21Views(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
             .getRemoteInterfaces(container));
    }
    




More information about the jboss-cvs-commits mailing list