[jboss-cvs] JBossAS SVN: r67998 - in projects/metadata/trunk/src: main/java/org/jboss/metadata/annotation/creator/ejb and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 6 12:58:35 EST 2007


Author: wolfc
Date: 2007-12-06 12:58:35 -0500 (Thu, 06 Dec 2007)
New Revision: 67998

Added:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/lang/
   projects/metadata/trunk/src/main/java/org/jboss/metadata/lang/ClassHelper.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultInterface.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultLocalInterfaceBean.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultRemoteInterfaceBean.java
Modified:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/LocalProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/RemoteProcessor.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/AnnotationEjb3UnitTestCase.java
Log:
JBAS-4506: fixes for empty local & remote and EJB 2.1 view

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/LocalProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/LocalProcessor.java	2007-12-06 16:56:42 UTC (rev 67997)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/LocalProcessor.java	2007-12-06 17:58:35 UTC (rev 67998)
@@ -23,6 +23,7 @@
 
 import java.lang.reflect.AnnotatedElement;
 
+import javax.ejb.EJBLocalObject;
 import javax.ejb.Local;
 
 import org.jboss.metadata.annotation.creator.AbstractFinderUser;
@@ -30,9 +31,10 @@
 import org.jboss.metadata.annotation.finder.AnnotationFinder;
 import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
 import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
+import org.jboss.metadata.lang.ClassHelper;
 
 /**
- * Comment
+ * Local annotation processor.
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
  * @version $Revision$
@@ -44,6 +46,25 @@
       super(finder);
    }
    
+   protected void addBusinessInterface(SessionBeanMetaData metaData, Class<?> businessInterface)
+   {
+      // Although this is not explicitly allowed by the spec, we accept it
+      // EJB 3 4.6.9
+      if(EJBLocalObject.class.isAssignableFrom(businessInterface))
+      {
+         if(metaData.getLocal() != null)
+            throw new IllegalArgumentException("2.1 bean " + metaData.getEjbName() + " already has a local interface " + metaData.getLocal() + ", can't add " + businessInterface.getName());
+         metaData.setLocal(businessInterface.getName());
+      }
+      else
+      {
+         if(metaData.getBusinessLocals() == null)
+            metaData.setBusinessLocals(new BusinessLocalsMetaData());
+         
+         metaData.getBusinessLocals().add(businessInterface.getName());
+      }
+   }
+   
    public void process(SessionBeanMetaData metaData, Class<?> type)
    {
       Local local = finder.getAnnotation(type, Local.class);
@@ -52,46 +73,20 @@
       
       if(type.isInterface())
       {
-         if(metaData.getLocalHome() != null)
-         {
-            if(metaData.getLocal() != null)
-               throw new IllegalArgumentException("2.1 bean " + metaData.getEjbName() + " already has a local interface " + metaData.getLocal() + ", can't add " + type.getName());
-            metaData.setLocal(type.getName());
-         }
-         else
-         {
-            if(metaData.getBusinessLocals() == null)
-               metaData.setBusinessLocals(new BusinessLocalsMetaData());
-            
-            metaData.getBusinessLocals().add(type.getName());
-         }
+         addBusinessInterface(metaData, type);
       }
       else
       {
-         /*
-          * Annotation values is not enough to determine this case, 
-          * interfaces may be defaulted by LocalHome return value of 
-          * "create" or if only one interface is present on the bean
-          * 
          if(local.value() == null || local.value().length == 0)
-            throw new IllegalArgumentException("Empty @Local on bean class " + type.getName() + " is not allowed");
-         */
-         if(metaData.getLocalHome() != null)
          {
-            if(metaData.getLocal() != null)
-               throw new IllegalArgumentException("2.1 bean " + metaData.getEjbName() + " already has a local interface " + metaData.getLocal() + ", can't add " + type.getName());
-            if(local.value().length > 1)
-               throw new IllegalArgumentException("2.1 bean " + type.getName() + " has more than one local interface defined");
-            metaData.setLocal(local.value()[0].getName());
+            Class<?> businessInterface = ClassHelper.getDefaultInterface(type);
+            addBusinessInterface(metaData, businessInterface);
          }
          else
          {
-            if(metaData.getBusinessLocals() == null)
-               metaData.setBusinessLocals(new BusinessLocalsMetaData());
-            
             for(Class<?> businessInterface : local.value())
             {
-               metaData.getBusinessLocals().add(businessInterface.getName());
+               addBusinessInterface(metaData, businessInterface);
             }
          }
       }

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/RemoteProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/RemoteProcessor.java	2007-12-06 16:56:42 UTC (rev 67997)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/RemoteProcessor.java	2007-12-06 17:58:35 UTC (rev 67998)
@@ -23,6 +23,7 @@
 
 import java.lang.reflect.AnnotatedElement;
 
+import javax.ejb.EJBObject;
 import javax.ejb.Remote;
 
 import org.jboss.metadata.annotation.creator.AbstractFinderUser;
@@ -30,12 +31,13 @@
 import org.jboss.metadata.annotation.finder.AnnotationFinder;
 import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
 import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
+import org.jboss.metadata.lang.ClassHelper;
 
 /**
  * Remote annotation processor.
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
  */
 public class RemoteProcessor extends AbstractFinderUser implements Processor<SessionBeanMetaData, Class<?>>
 {  
@@ -43,6 +45,25 @@
    {
       super(finder);
    }
+
+   protected void addBusinessInterface(SessionBeanMetaData metaData, Class<?> businessInterface)
+   {
+      // Although this is not explicitly allowed by the spec, we accept it
+      // EJB 3 4.6.7
+      if(EJBObject.class.isAssignableFrom(businessInterface))
+      {
+         if(metaData.getRemote() != null)
+            throw new IllegalArgumentException("2.1 bean " + metaData.getEjbName() + " already has a remote interface " + metaData.getRemote() + ", can't add " + businessInterface.getName());
+         metaData.setRemote(businessInterface.getName());
+      }
+      else
+      {
+         if(metaData.getBusinessRemotes() == null)
+            metaData.setBusinessRemotes(new BusinessRemotesMetaData());
+         
+         metaData.getBusinessRemotes().add(businessInterface.getName());
+      }
+   }
    
    public void process(SessionBeanMetaData metaData, Class<?> type)
    {
@@ -52,43 +73,20 @@
       
       if(type.isInterface())
       {
-         if(metaData.getHome() != null)
-         {
-            if(metaData.getRemote() != null)
-               throw new IllegalArgumentException("2.1 bean " + metaData.getEjbName() + " already has a remote interface " + metaData.getRemote() + ", can't add " + type.getName());
-            metaData.setRemote(type.getName());
-         }
-         else
-         {
-            if(metaData.getBusinessRemotes() == null)
-               metaData.setBusinessRemotes(new BusinessRemotesMetaData());
-            
-            metaData.getBusinessRemotes().add(type.getName());
-         }
+         addBusinessInterface(metaData, type);
       }
       else
       {
-         /* This condition cannot be validated alone
          if(remote.value() == null || remote.value().length == 0)
-            throw new IllegalArgumentException("Empty @Remote on bean class " + type.getName() + " is not allowed");
-         */
-
-         if(metaData.getHome() != null)
          {
-            if(metaData.getRemote() != null)
-               throw new IllegalArgumentException("2.1 bean " + metaData.getEjbName() + " already has a remote interface " + metaData.getRemote() + ", can't add " + type.getName());
-            if(remote.value().length > 1)
-               throw new IllegalArgumentException("2.1 bean " + type.getName() + " has more than one remote interface defined");
-            metaData.setRemote(remote.value()[0].getName());
+            Class<?> businessInterface = ClassHelper.getDefaultInterface(type);
+            addBusinessInterface(metaData, businessInterface);
          }
          else
          {
-            if(metaData.getBusinessRemotes() == null)
-               metaData.setBusinessRemotes(new BusinessRemotesMetaData());
-            
             for(Class<?> businessInterface : remote.value())
             {
-               metaData.getBusinessRemotes().add(businessInterface.getName());
+               addBusinessInterface(metaData, businessInterface);
             }
          }
       }

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/lang/ClassHelper.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/lang/ClassHelper.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/lang/ClassHelper.java	2007-12-06 17:58:35 UTC (rev 67998)
@@ -0,0 +1,68 @@
+/*
+ * 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.metadata.lang;
+
+
+/**
+ * Useful methods on classes.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ClassHelper
+{
+   private static Class<?> findDefaultInterface(Class<?> cls)
+   {
+      if(cls == null)
+         return null;
+      
+      Class<?> interfaces[] = cls.getInterfaces();
+      switch(interfaces.length)
+      {
+         case 0:
+            return findDefaultInterface(cls.getSuperclass());
+         case 1:
+            return interfaces[0];
+         default:
+            // TODO: maybe an exception?
+            return null;
+      }
+   }
+   
+   /**
+    * Find the default interface of a class. If a class implements one interface,
+    * that interface is considered the default interface. If it does not implement
+    * an interface it's super class is considered. If it implements multiple
+    * interfaces or no interface can be found an IllegalArgumentException is thrown.
+    * 
+    * @param cls    the class to scan
+    * @return       the default interface as defined above
+    * @throws IllegalArgumentException  if the class does not implement a default interface
+    */
+   public static Class<?> getDefaultInterface(Class<?> cls)
+   {
+      Class<?> defaultInterface = findDefaultInterface(cls);
+      if(defaultInterface == null)
+         throw new IllegalArgumentException("Class " + cls + " does not have a default interface");
+      return defaultInterface;
+   }
+}


Property changes on: projects/metadata/trunk/src/main/java/org/jboss/metadata/lang/ClassHelper.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/AnnotationEjb3UnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/AnnotationEjb3UnitTestCase.java	2007-12-06 16:56:42 UTC (rev 67997)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/AnnotationEjb3UnitTestCase.java	2007-12-06 17:58:35 UTC (rev 67998)
@@ -79,6 +79,7 @@
 import org.jboss.metadata.javaee.spec.RunAsMetaData;
 import org.jboss.metadata.javaee.spec.SecurityRoleMetaData;
 import org.jboss.metadata.javaee.spec.SecurityRolesMetaData;
+import org.jboss.test.metadata.annotation.ejb3.defaultinterface.DefaultInterface;
 import org.jboss.test.metadata.annotation.ejb3.multiview.Multiview21Remote;
 import org.jboss.test.metadata.annotation.ejb3.multiview.Multiview3Remote;
 import org.jboss.test.metadata.annotation.ejb3.multiview.MultiviewHome;
@@ -603,4 +604,35 @@
       assertEquals("Auto-acknowledge", activationConfigProperties.get("acknowledgeMode").getValue());
       assertEquals("javax.jms.Queue", activationConfigProperties.get("destinationType").getValue());
    }
+   
+   /**
+    * EJB 3 4.6.6:
+    * If bean class implements a single interface, that interface is assumed to be the busi-
+    * ness interface of the bean. This business interface will be a local interface unless the
+    * interface is designated as a remote business interface by use of the Remote annota-
+    * tion on the bean class or interface or by means of the deployment descriptor.
+    * @throws Exception
+    */
+   @ScanPackage("org.jboss.test.metadata.annotation.ejb3.defaultinterface")
+   public void testDefaultInterface() throws Exception
+   {
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+      
+      Collection<Class<?>> classes = PackageScanner.loadClasses();
+      System.out.println("Processing classes: "+classes);
+      
+      EjbJar30Creator creator = new EjbJar30Creator(finder);
+      
+      EjbJar30MetaData metaData = creator.create(classes);
+      
+      SessionBeanMetaData bean = (SessionBeanMetaData) metaData.getEnterpriseBean("DefaultRemoteInterfaceBean");
+      
+      assertEquals(1, bean.getBusinessRemotes().size());
+      assertTrue(bean.getBusinessRemotes().contains(DefaultInterface.class.getName()));
+      
+      bean = (SessionBeanMetaData) metaData.getEnterpriseBean("DefaultLocalInterfaceBean");
+      
+      assertEquals(1, bean.getBusinessLocals().size());
+      assertTrue(bean.getBusinessLocals().contains(DefaultInterface.class.getName()));
+   }
 }
\ No newline at end of file

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultInterface.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultInterface.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultInterface.java	2007-12-06 17:58:35 UTC (rev 67998)
@@ -0,0 +1,33 @@
+/*
+ * 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.test.metadata.annotation.ejb3.defaultinterface;
+
+/**
+ * An un-annotated interface.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface DefaultInterface
+{
+
+}


Property changes on: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultInterface.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultLocalInterfaceBean.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultLocalInterfaceBean.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultLocalInterfaceBean.java	2007-12-06 17:58:35 UTC (rev 67998)
@@ -0,0 +1,39 @@
+/*
+ * 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.test.metadata.annotation.ejb3.defaultinterface;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * Bean has an empty Local, so the implemented interface should
+ * become it's local business interface.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local
+public class DefaultLocalInterfaceBean implements DefaultInterface
+{
+
+}


Property changes on: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultLocalInterfaceBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultRemoteInterfaceBean.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultRemoteInterfaceBean.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultRemoteInterfaceBean.java	2007-12-06 17:58:35 UTC (rev 67998)
@@ -0,0 +1,39 @@
+/*
+ * 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.test.metadata.annotation.ejb3.defaultinterface;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+/**
+ * Bean has an empty Remote, so the implemented interface should
+ * become it's remote business interface.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote
+public class DefaultRemoteInterfaceBean implements DefaultInterface
+{
+
+}


Property changes on: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/defaultinterface/DefaultRemoteInterfaceBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list