User: mulder  
  Date: 00/09/11 18:51:48

  Modified:    src/main/org/jboss/verifier/strategy AbstractVerifier.java
                        EJBVerifier11.java
  Log:
  Fix a bug where entity create and postCreate methods were never verified
  (since ejbCreate does not return null for an entity).
  
  Add verification of entity Primary Keys.
  
  Note that test beans do not all verify.  We should fix that.
  
  Revision  Changes    Path
  1.10      +98 -65    jboss/src/main/org/jboss/verifier/strategy/AbstractVerifier.java
  
  Index: AbstractVerifier.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/verifier/strategy/AbstractVerifier.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractVerifier.java     2000/08/20 20:29:16     1.9
  +++ AbstractVerifier.java     2000/09/12 01:51:48     1.10
  @@ -19,10 +19,11 @@
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    *
    * This package and its source code is available at www.jboss.org
  - * $Id: AbstractVerifier.java,v 1.9 2000/08/20 20:29:16 juha Exp $
  + * $Id: AbstractVerifier.java,v 1.10 2000/09/12 01:51:48 mulder Exp $
    */
   
   // standard imports
  +import java.lang.reflect.Field;
   import java.lang.reflect.Member;
   import java.lang.reflect.Method;
   import java.lang.reflect.Modifier;
  @@ -49,26 +50,26 @@
    * @see     org.jboss.verifier.strategy.VerificationStrategy
    *
    * @author   Juha Lindfors ([EMAIL PROTECTED])
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.10 $
    * @since    JDK 1.3
    */
   public abstract class AbstractVerifier implements VerificationStrategy {
   
   
       public boolean hasLegalRMIIIOPReturnType(Method method) {
  -        
  +
           // [TODO]
  -        
  -        
  +
  +
           return true;
       }
   
       public boolean hasLegalRMIIIOPArguments(Method method) {
   
  -        
  +
           // [TODO]
  -        
  -        
  +
  +
           return true;
   
   
  @@ -123,9 +124,9 @@
   
           return false;
       }
  +
  +
   
  -    
  -    
       /*
        * checks if a class's member (method, constructor or field) has a 'static'
        * modifier.
  @@ -141,7 +142,7 @@
       public boolean isFinal(Member member) {
           return (Modifier.isFinal(member.getModifiers()));
       }
  -    
  +
       /*
        * checks if the given class is declared as final
        */
  @@ -164,6 +165,21 @@
           return (Modifier.isPublic(c.getModifiers()));
       }
   
  +    /**
  +     * Checks whether all the fields in the class are declared as public.
  +     */
  +    public static boolean isAllFieldsPublic(Class c) {
  +        try {
  +            Field list[] = c.getFields();
  +            for(int i=0; i<list.length; i++)
  +                if(!Modifier.isPublic(list[i].getModifiers()))
  +                    return false;
  +        } catch(Exception e) {
  +            return false;
  +        }
  +        return true;
  +    }
  +
       /*
        * checks if the given class is declared as abstract
        */
  @@ -199,7 +215,7 @@
       public boolean hasRemoteReturnType(BeanMetaData bean, Method m) {
           return (m.getReturnType().getName().equals(bean.getRemote()));
       }
  -    
  +
       /*
        * checks if a method has a void return type
        */
  @@ -220,7 +236,7 @@
        public boolean hasEntityBeanInterface(Class c) {
            return hasInterface(c, ENTITY_BEAN_INTERFACE);
        }
  -     
  +
       /*
        * Finds java.ejb.EJBObject interface from the class
        */
  @@ -284,14 +300,14 @@
        * check if a class has one or more finder methods
        */
       public boolean hasFinderMethod(Class c) {
  -        
  +
           try {
               Method[] method = c.getMethods();
   
               for (int i = 0; i <  method.length; ++i) {
  -                
  +
                   String name = method[i].getName();
  -                
  +
                   if (name.startsWith("ejbFind"))
                       return true;
               }
  @@ -299,10 +315,24 @@
           catch (SecurityException e) {
               System.err.println(e);
           }
  -        
  +
           return false;
       }
  -    
  +
  +    /**
  +     * Checks for at least one non-static field.
  +     */
  +    public static boolean hasANonStaticField(Class c) {
  +        try {
  +            Field list[] = c.getFields();
  +            for(int i=0; i<list.length; i++)
  +                if(!Modifier.isStatic(list[i].getModifiers()))
  +                    return true;
  +        } catch(Exception e) {
  +        }
  +        return false;
  +    }
  +
       /*
        * Searches for an instance of a public create method from the class
        */
  @@ -329,7 +359,7 @@
       /*
        * Searches for an instance of a public ejbCreate method from the class
        */
  -    public boolean hasEJBCreateMethod(Class c) {
  +    public boolean hasEJBCreateMethod(Class c, boolean isSession) {
   
           try {
               Method[] method = c.getMethods();
  @@ -341,7 +371,10 @@
                   if (name.equals(EJB_CREATE_METHOD))
                       if (!isStatic(method[i])
                               && !isFinal(method[i])
  -                            && hasVoidReturnType(method[i]))
  +                            && ((isSession && hasVoidReturnType(method[i]))
  +                                || (!isSession)
  +                               )
  +                       )
   
                           return true;
               }
  @@ -386,14 +419,14 @@
        * checks if the class has an ejbFindByPrimaryKey method
        */
       public boolean hasEJBFindByPrimaryKey(Class c) {
  -        
  +
           try {
               Method[] method = c.getMethods();
  -            
  +
               for (int i = 0; i < method.length; ++i) {
  -                
  +
                   String name = method[i].getName();
  -                
  +
                   if (name.equals(EJB_FIND_BY_PRIMARY_KEY))
                       return true;
               }
  @@ -401,27 +434,27 @@
           catch (SecurityException e) {
               System.err.println(e);
           }
  -        
  +
           return false;
       }
  -    
  +
       /*
        * checks the return type of method matches the entity's primary key class
        */
       public boolean hasPrimaryKeyReturnType(EntityMetaData entity, Method m) {
           return (m.getReturnType().getName().equals(entity.getPrimaryKeyClass()));
       }
  -    
  -    
   
   
  +
  +
       /*
        * Returns the default create method. Return null if not found.
        */
       public Method getDefaultCreateMethod(Class c) {
   
           Method method = null;
  -        
  +
           try {
   
               method = c.getMethod(CREATE_METHOD, null);
  @@ -431,7 +464,7 @@
               System.err.println(e);
           }
           catch (NoSuchMethodException ignored) {}
  -        
  +
           return method;
       }
   
  @@ -454,37 +487,37 @@
        * Returns the ejbFindByPrimaryKey method
        */
       public Method getEJBFindByPrimaryKey(Class c) {
  -        
  +
           try {
               Method[] method = c.getMethods();
  -            
  +
               for (int i = 0; i < method.length; ++i) {
  -                
  +
                   String name = method[i].getName();
  -                
  +
                   if (name.equals(EJB_FIND_BY_PRIMARY_KEY))
                       return method[i];
               }
           }
           catch (SecurityException e) {
               System.err.println(e);
  -        }           
  -        
  +        }
  +
           return null;
       }
  -    
  +
       /*
        * returns the ejbFind<METHOD> methods of a bean
        */
       public Iterator getFinderMethods(Class c) {
  -        
  +
           List finders = new LinkedList();
  -        
  +
           try {
               Method[] method = c.getMethods();
  -            
  -            for (int i = 0; i < method.length; ++i) { 
  -        
  +
  +            for (int i = 0; i < method.length; ++i) {
  +
                   if (method[i].getName().startsWith("ejbFind"))
                       finders.add(method[i]);
               }
  @@ -492,11 +525,11 @@
           catch (SecurityException e) {
               System.err.println(e);
           }
  -        
  +
           return finders.iterator();
       }
  -    
  -    
  +
  +
       /*
        * Returns the ejbCreate(...) methods of a bean
        */
  @@ -536,8 +569,8 @@
               return null;
           }
       }
  -    
   
  +
       public boolean hasMoreThanOneCreateMethods(Class c) {
   
           int count = 0;
  @@ -564,39 +597,39 @@
       public boolean hasMatchingMethodNames(Class a, Class b) {
   
           // [TODO]
  -        
  -        
  +
  +
           return true;
       }
   
       public boolean hasMatchingMethodArgs(Class a, Class b) {
   
           // [TODO]
  -        
  -        
  +
  +
           return true;
       }
   
       public boolean hasMatchingMethodExceptions(Class a, Class b) {
   
           // [TODO]
  -        
  -        
  +
  +
           return true;
       }
   
       public boolean hasMatchingEJBPostCreate(Class bean, Method ejbCreate) {
           try {
  -            return (bean.getMethod(EJB_POST_CREATE, ejbCreate.getParameterTypes()) 
!= null);        
  +            return (bean.getMethod(EJB_POST_CREATE, ejbCreate.getParameterTypes()) 
!= null);
           }
           catch (NoSuchMethodException e) {
               return false;
           }
       }
  -    
  -    
  +
  +
       public Method getMatchingEJBPostCreate(Class bean, Method ejbCreate) {
  -        
  +
           try {
               return bean.getMethod(EJB_POST_CREATE, ejbCreate.getParameterTypes());
           }
  @@ -605,7 +638,7 @@
           }
       }
   
  -    
  +
   /*
    *************************************************************************
    *
  @@ -621,8 +654,8 @@
        * @param beans  the message bean to verify
        */
       public void checkMessageBean(BeanMetaData bean) {}
  +
   
  -    
   /*
    *************************************************************************
    *
  @@ -630,7 +663,7 @@
    *
    *************************************************************************
    */
  - 
  +
       private boolean hasInterface(Class c, String name) {
           try {
               Class intClass = Class.forName(name);
  @@ -648,7 +681,7 @@
    *
    *************************************************************************
    */
  - 
  +
       /*
        * Ejb-jar DTD
        */
  @@ -683,16 +716,16 @@
   
       private final static String ENTITY_BEAN_INTERFACE =
           "javax.ejb.EntityBean";
  -        
  +
       private final static String SERIALIZATION_INTERFACE =
           "java.io.Serializable";
   
       private final static String COLLECTION_INTERFACE  =
           "java.util.Collection";
  -        
  +
       private final static String ENUMERATION_INTERFACE =
           "java.util.Enumeration";
  -        
  +
       private final static String REMOTE_EXCEPTION      =
           "java.rmi.RemoteException";
   
  @@ -709,13 +742,13 @@
        */
       private final static String EJB_FIND_BY_PRIMARY_KEY =
           "ejbFindByPrimaryKey";
  -        
  +
       private final static String EJB_CREATE_METHOD     =
           "ejbCreate";
   
       private final static String EJB_POST_CREATE       =
           "ejbPostCreate";
  -        
  +
       private final static String CREATE_METHOD         =
           "create";
   
  
  
  
  1.15      +272 -255  jboss/src/main/org/jboss/verifier/strategy/EJBVerifier11.java
  
  Index: EJBVerifier11.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/verifier/strategy/EJBVerifier11.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- EJBVerifier11.java        2000/08/26 20:14:14     1.14
  +++ EJBVerifier11.java        2000/09/12 01:51:48     1.15
  @@ -19,7 +19,7 @@
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    *
    * This package and its source code is available at www.jboss.org
  - * $Id: EJBVerifier11.java,v 1.14 2000/08/26 20:14:14 juha Exp $
  + * $Id: EJBVerifier11.java,v 1.15 2000/09/12 01:51:48 mulder Exp $
    */
   
   
  @@ -58,7 +58,7 @@
    * @see     org.jboss.verifier.strategy.AbstractVerifier
    *
    * @author   Juha Lindfors ([EMAIL PROTECTED])
  - * @version $Revision: 1.14 $
  + * @version $Revision: 1.15 $
    * @since    JDK 1.3
    */
   public class EJBVerifier11 extends AbstractVerifier {
  @@ -70,7 +70,7 @@
   
       /*
        * Constructor
  -     *  
  +     *
        * @param   context
        */
       public EJBVerifier11(VerificationContext context) {
  @@ -123,8 +123,8 @@
   
   
       public void checkEntity(EntityMetaData entity) {
  -        
  -        boolean pkVerified     = true;      // false;
  +
  +        boolean pkVerified     = false;
           boolean beanVerified   = false;
           boolean homeVerified   = false;
           boolean remoteVerified = false;
  @@ -134,15 +134,11 @@
            *
            *  - prim key class is fully qualified class name
            */
  -         
           beanVerified   = verifyEntityBean(entity);
           homeVerified   = verifyEntityHome(entity);
           remoteVerified = verifyEntityRemote(entity);
  +        pkVerified     = verifyPrimaryKey(entity);
   
  -
  -        // will put this back later
  -        //pkVerified = verifyPrimaryKey(entity.getPrimaryKeyClass());
  -
           if ( beanVerified && homeVerified && remoteVerified && pkVerified) {
   
               /*
  @@ -151,7 +147,6 @@
                */
               fireBeanVerifiedEvent(entity);
           }
  -
       }
   
       public StrategyContext getContext() {
  @@ -176,7 +171,7 @@
           boolean status = true;
   
           String name = session.getHome();
  -        
  +
           try {
               Class home = classloader.loadClass(name);
   
  @@ -192,26 +187,26 @@
                * Spec 6.8
                */
                if (session.isStateless()) {
  -                 
  +
                    if (!hasDefaultCreateMethod(home)) {
                       fireSpecViolationEvent(session, new Section("6.8.a"));
   
                       status = false;
                    }
  -                 
  +
                    if (!hasRemoteReturnType(session, getDefaultCreateMethod(home))) {
                        fireSpecViolationEvent(session, new Section("6.8.b"));;
  -                     
  +
                        status = false;
                    }
  -                 
  +
                    if (hasMoreThanOneCreateMethods(home)) {
                        fireSpecViolationEvent(session, new Section("6.8.c"));
  -                     
  +
                        status = false;
  -                 }   
  +                 }
                }
  -             
  +
               /*
                * The session bean's home interface MUST extend the
                * javax.ejb.EJBHome interface.
  @@ -219,13 +214,13 @@
                * Spec 6.10.6
                */
               if (!hasEJBHomeInterface(home)) {
  -                
  +
                   fireSpecViolationEvent(session, new Section("6.10.6.a"));
  -                
  +
                   status = false;
               }
  -            
  -            /*                
  +
  +            /*
                * Method arguments defined in the home interface MUST be
                * of valid types for RMI/IIOP.
                *
  @@ -238,29 +233,29 @@
                * Spec 6.10.6
                */
               Iterator it = getMethods(home);
  -            
  +
               while (it.hasNext()) {
  -                
  -                Method method = (Method)it.next();    
  -                
  +
  +                Method method = (Method)it.next();
  +
                   if (!hasLegalRMIIIOPArguments(method)) {
  -                    
  +
                       fireSpecViolationEvent(session, new Section("6.10.6.b"));
  -                    
  +
                       status = false;
                   }
  -                
  +
                   if (!hasLegalRMIIIOPReturnType(method)) {
  -                    
  +
                       fireSpecViolationEvent(session, new Section("6.10.6.c"));
  -                    
  +
                       status = false;
                   }
  -                
  +
                   if (!throwsRemoteException(method)) {
  -                    
  +
                       fireSpecViolationEvent(session, new Section("6.10.6.d"));
  -                    
  +
                       status = false;
                   }
               }
  @@ -272,13 +267,13 @@
                * Spec 6.10.6
                */
               if (!hasCreateMethod(home)) {
  -                
  +
                   fireSpecViolationEvent(session, new Section("6.10.6.e"));
   
                   status = false;
               }
  +
   
  -             
           }
           catch (ClassNotFoundException e) {
   
  @@ -292,7 +287,7 @@
   
               status = false;
           }
  -        
  +
           return status;
   
       }
  @@ -303,8 +298,8 @@
    *      VERIFY SESSION BEAN REMOTE INTERFACE
    *
    *************************************************************************
  - */    
  -    
  + */
  +
       private boolean verifySessionRemote(SessionMetaData session) {
   
           /*
  @@ -326,13 +321,13 @@
                * Spec 6.10.5
                */
               if (!hasEJBObjectInterface(remote)) {
  -                
  +
                   fireSpecViolationEvent(session, new Section("6.10.5.a"));
  -    
  +
                   status = false;
               }
  -    
  -            /*                
  +
  +            /*
                * Method arguments defined in the remote interface MUST be
                * of valid types for RMI/IIOP.
                *
  @@ -345,29 +340,29 @@
                * Spec 6.10.5
                */
               Iterator it = getMethods(remote);
  -            
  +
               while (it.hasNext()) {
  -                
  -                Method method = (Method)it.next();    
  -                
  +
  +                Method method = (Method)it.next();
  +
                   if (!hasLegalRMIIIOPArguments(method)) {
  -                    
  +
                       fireSpecViolationEvent(session, new Section("6.10.5.b"));
  -                    
  +
                       status = false;
                   }
  -                
  +
                   if (!hasLegalRMIIIOPReturnType(method)) {
  -                    
  +
                       fireSpecViolationEvent(session, new Section("6.10.5.c"));
  -                    
  +
                       status = false;
                   }
  -                
  +
                   if (!throwsRemoteException(method)) {
  -                    
  +
                       fireSpecViolationEvent(session, new Section("6.10.5.d"));
  -                    
  +
                       status = false;
                   }
               }
  @@ -380,7 +375,7 @@
                *  - the same name
                *  - the same number and types of arguments, and the same
                *    return type
  -             *  - All the exceptions defined in the throws clause of the 
  +             *  - All the exceptions defined in the throws clause of the
                *    matching method of the session bean class must be defined
                *    in the throws clause of the method of the remote interface
                *
  @@ -389,31 +384,31 @@
               try {
                   String beanName = session.getEjbClass();
                   Class  bean     = classloader.loadClass(beanName);
  -                
  +
                   if (!hasMatchingMethodNames(remote, bean)) {
  -                    
  +
                       fireSpecViolationEvent(session, new Section("6.10.5.e"));
  -                    
  +
                       status = false;
                   }
  -                
  +
                   if (!hasMatchingMethodArgs(remote, bean)) {
  -                    
  +
                       fireSpecViolationEvent(session, new Section("6.10.5.f"));
  -                    
  +
                       status = false;
                   }
  -                
  +
                   if (!hasMatchingMethodExceptions(remote, bean)) {
  -                    
  +
                       fireSpecViolationEvent(session, new Section("6.10.5.g"));
  -                    
  +
                       status = false;
                   }
               }
  -            
  +
               catch (ClassNotFoundException ignored) {}
  -            
  +
           }
           catch (ClassNotFoundException e) {
   
  @@ -437,8 +432,8 @@
    *      VERIFY SESSION BEAN CLASS
    *
    *************************************************************************
  - */    
  -    
  + */
  +
       private boolean verifySessionBean(SessionMetaData session) {
   
           /*
  @@ -492,15 +487,15 @@
                       status = false;
                   }
               }
  -            
  +
   
               /*
                * A session bean MUST implement AT LEAST one ejbCreate method.
                *
                * Spec 6.5.5
                */
  -            if (!hasEJBCreateMethod(bean)) {
  -                
  +            if (!hasEJBCreateMethod(bean, true)) {
  +
                   fireSpecViolationEvent(session, new Section("6.5.5"));
   
                   status = false;
  @@ -591,35 +586,35 @@
                *
                * Spec 6.10.3
                */
  -            if (hasEJBCreateMethod(bean)) {
  -                
  +            if (hasEJBCreateMethod(bean, true)) {
  +
                   Iterator it = getEJBCreateMethods(bean);
  -                
  +
                   while (it.hasNext()) {
  -                    
  +
                       Method ejbCreate = (Method)it.next();
  -                    
  +
                       if (!isPublic(ejbCreate)) {
  -                        
  +
                           fireSpecViolationEvent(session, new Section("6.10.3.a"));
                           status = false;
                       }
  -                    
  +
                       if ( (isFinal(ejbCreate)) ||
                            (isStatic(ejbCreate)) ) {
  -                              
  +
                           fireSpecViolationEvent(session, new Section("6.10.3.b"));
                           status = false;
                       }
  -                    
  +
                       if (!hasVoidReturnType(ejbCreate)) {
  -                        
  +
                           fireSpecViolationEvent(session, new Section("6.10.3.c"));
                           status = false;
                       }
  -                    
  +
                       if (!hasLegalRMIIIOPArguments(ejbCreate)) {
  -                        
  +
                           fireSpecViolationEvent(session, new Section("6.10.3.d"));
                           status = false;
                       }
  @@ -638,7 +633,7 @@
                * Spec 16.2
                */
               fireSpecViolationEvent(session, new Section("16.2.b"));
  -            
  +
               status = false;
           }
   
  @@ -653,7 +648,7 @@
    *
    *************************************************************************
    */
  - 
  +
       private boolean verifyEntityHome(EntityMetaData entity) {
   
           /*
  @@ -663,12 +658,12 @@
           boolean status = true;
   
           String name = entity.getHome();
  -        
  +
           try {
               Class home = classloader.loadClass(name);
   
   
  -             
  +
           }
           catch (ClassNotFoundException e) {
   
  @@ -682,20 +677,20 @@
   
               status = false;
           }
  -        
  +
           return status;
   
       }
  +
   
  -    
   /*
    *************************************************************************
  - *  
  + *
    *      VERIFY ENTITY BEAN REMOTE INTERFACE
    *
    *************************************************************************
    */
  -    
  +
       private boolean verifyEntityRemote(EntityMetaData entity) {
   
           /*
  @@ -728,8 +723,8 @@
           return status;
       }
   
  -    
   
  +
   /*
    *************************************************************************
    *
  @@ -737,7 +732,7 @@
    *
    *************************************************************************
    */
  -    
  +
       private boolean verifyEntityBean(EntityMetaData entity) {
   
           /*
  @@ -764,43 +759,43 @@
   
                   status = false;
               }
  -            
  +
               /*
                * The entity bean class MUST be defined as public.
                *
                * Spec 9.2.2
                */
               if (!isPublic(bean))  {
  -                
  +
                   fireSpecViolationEvent(entity, new Section("9.2.2.b"));
  -            
  +
                   status = false;
               }
  -            
  +
               /*
                * The entity bean class MUST NOT be defined as abstract.
                *
                * Spec 9.2.2
                */
               if (isAbstract(bean)) {
  -                     
  +
                   fireSpecViolationEvent(entity, new Section("9.2.2.c"));
  -                
  +
                   status = false;
               }
  -            
  +
               /*
                * The entity bean class MUST NOT be defined as final.
                *
                * Spec 9.2.2
                */
               if (isFinal(bean)) {
  -            
  +
                   fireSpecViolationEvent(entity, new Section("9.2.2.d"));
  -                
  +
                   status = false;
               }
  -            
  +
               /*
                * The entity bean class MUST define a public constructor that
                * takes no arguments
  @@ -808,24 +803,24 @@
                * Spec 9.2.2
                */
               if (!hasDefaultConstructor(bean)) {
  -            
  +
                   fireSpecViolationEvent(entity, new Section("9.2.2.e"));
  -                
  +
                   status = false;
               }
  -            
  +
               /*
                * The entity bean class MUST NOT define the finalize() method.
                *
                * Spec 9.2.2
                */
               if (hasFinalizer(bean)) {
  -                 
  +
                   fireSpecViolationEvent(entity, new Section("9.2.2.f"));
  -                 
  +
                   status = false;
               }
  -            
  +
               /*
                * The ejbCreate(...) method signatures MUST follow these rules:
                *
  @@ -837,50 +832,50 @@
                *
                * Spec 9.2.3
                */
  -            if (hasEJBCreateMethod(bean)) {
  -                
  +            if (hasEJBCreateMethod(bean, false)) {
  +
                   Iterator it = getEJBCreateMethods(bean);
  -                
  +
                   while (it.hasNext()) {
  -                    
  +
                       Method ejbCreate = (Method)it.next();
  -                    
  +
                       if (!isPublic(ejbCreate)) {
  -                        
  +
                           fireSpecViolationEvent(entity, new Section("9.2.3.a"));
                           status = false;
                       }
  -                    
  +
                       if ( (isFinal(ejbCreate)) ||
                            (isStatic(ejbCreate)) ) {
  -                              
  +
                           fireSpecViolationEvent(entity, new Section("9.2.3.b"));
                           status = false;
                       }
  -                    
  +
                       if (!hasPrimaryKeyReturnType(entity, ejbCreate)) {
  -                        
  +
                           fireSpecViolationEvent(entity, new Section("9.2.3.c"));
                           status = false;
                       }
  -                    
  +
                       if (!hasLegalRMIIIOPArguments(ejbCreate)) {
  -                        
  +
                           fireSpecViolationEvent(entity, new Section("9.2.3.d"));
                           status = false;
                       }
  -                    
  +
                       if (!hasLegalRMIIIOPReturnType(ejbCreate)) {
  -                        
  +
                           fireSpecViolationEvent(entity, new Section("9.2.3.e"));
                           status = false;
                       }
                   }
               }
  -            
  +
               /*
                * For each ejbCreate(...) method, the entity bean class MUST
  -             * define a matching ejbPostCreate(...) method. 
  +             * define a matching ejbPostCreate(...) method.
                *
                * The ejbPostCreate(...) method MUST follow these rules:
                *
  @@ -892,50 +887,52 @@
                *
                * Spec 9.2.4
                */
  -            if (hasEJBCreateMethod(bean)) {
  -                
  +            if (hasEJBCreateMethod(bean, false)) {
                   Iterator it =  getEJBCreateMethods(bean);
  -                
  +
                   while (it.hasNext()) {
  -                    
                       Method ejbCreate = (Method)it.next();
  -                    
  +
                       if (!hasMatchingEJBPostCreate(bean, ejbCreate)) {
  -                        
  +
                           fireSpecViolationEvent(entity, new Section("9.2.4.a"));
  -                        
  +
                           status = false;
                       }
  -                    
  +
                       if (hasMatchingEJBPostCreate(bean, ejbCreate)) {
  -                        
  +
                           Method ejbPostCreate = getMatchingEJBPostCreate(bean, 
ejbCreate);
  -                        
  +
                           if (!isPublic(ejbPostCreate)) {
  -                            
  +
                               fireSpecViolationEvent(entity, new Section("9.2.4.b"));
  -                            
  +
                               status = false;
                           }
  -                        
  +
                           if (isStatic(ejbPostCreate)) {
  -                            
  +
                               fireSpecViolationEvent(entity, new Section("9.2.4.c"));
  -                            
  +
                               status = false;
                           }
  -                        
  +
                           if (isFinal(ejbPostCreate)) {
  -                            
  +
                               fireSpecViolationEvent(entity, new Section("9.2.4.d"));
  -                            
  +
                               status = false;
                           }
  +
  +                        if(!hasVoidReturnType(ejbPostCreate)) {
  +                            fireSpecViolationEvent(entity, new Section("9.2.4.e"));
  +                            status = false;
  +                        }
                       }
                   }
               }
  -            
  -            
  +
               /*
                * Every entity bean MUST define the ejbFindByPrimaryKey method.
                *
  @@ -951,31 +948,31 @@
                    * ejbFindByPrimaryKey() implementation, we only check BMP.
                    * For CMP it is the responsibility of the container to
                    * provide the implementation. */
  -                 
  +
                   fireSpecViolationEvent(entity, new Section("9.2.5.a"));
  -                
  +
                   status = false;
               }
  -            
  +
               if (hasEJBFindByPrimaryKey(bean)) {
  -                
  +
                   Method ejbFindByPrimaryKey = getEJBFindByPrimaryKey(bean);
  -                
  +
                   if (!hasPrimaryKeyReturnType(entity, ejbFindByPrimaryKey)) {
  -                    
  +
                       fireSpecViolationEvent(entity, new Section("9.2.5.b"));
  -                    
  +
                       status = false;
                   }
  -                
  +
                   if (!isSingleObjectFinder(entity, ejbFindByPrimaryKey)) {
  -                    
  +
                       fireSpecViolationEvent(entity, new Section("9.2.5.c"));
  -                    
  +
                       status = false;
                   }
               }
  -            
  +
               /*
                * A finder method MUST be declared as public.
                *
  @@ -993,54 +990,54 @@
                * Spec 9.2.5
                */
               if (hasFinderMethod(bean)) {
  -                 
  +
                   Iterator it = getFinderMethods(bean);
  -                
  +
                   while (it.hasNext()) {
  -                    
  +
                       Method finder = (Method)it.next();
  -                    
  +
                       if (!isPublic(finder)) {
  -                        
  +
                           fireSpecViolationEvent(entity, new Section("9.2.5.d"));
  -                        
  +
                           status = false;
                       }
  -                    
  +
                       if (isFinal(finder)) {
  -                        
  +
                           fireSpecViolationEvent(entity, new Section("9.2.5.e"));
  -                        
  +
                           status = false;
                       }
  -                    
  +
                       if (isStatic(finder)) {
  -                        
  +
                           fireSpecViolationEvent(entity, new Section("9.2.5.f"));
  -                        
  +
                           status = false;
                       }
  -                    
  +
                       if (!hasLegalRMIIIOPArguments(finder)) {
  -                        
  +
                           fireSpecViolationEvent(entity, new Section("9.2.5.g"));
  -                        
  +
                           status = false;
                       }
  -                    
  +
                       if (! (isSingleObjectFinder(entity, finder)
                           || isMultiObjectFinder(finder))) {
  -                        
  +
                           fireSpecViolationEvent(entity, new Section("9.2.5.h"));
  -                        
  +
                           status = false;
                       }
  -                } 
  +                }
               }
  -            
  -            
  -            
  -            
  +
  +
  +
  +
           }
           catch (ClassNotFoundException e) {
   
  @@ -1052,113 +1049,133 @@
                * Spec 16.2
                */
               fireSpecViolationEvent(entity, new Section("16.2.b"));
  -            
  +
               status = false;
           }
   
           return status;
       }
  +
   
  -    
  -    
  +
       private void fireSpecViolationEvent(BeanMetaData bean, Section section) {
   
           VerificationEvent event = factory.createSpecViolationEvent(context, 
section);
           event.setName(bean.getEjbName());
  -        
  +
           context.fireSpecViolation(event);
       }
  -    
  +
       private void fireBeanVerifiedEvent(BeanMetaData bean) {
  -        
  +
           VerificationEvent event = factory.createBeanVerifiedEvent(context);
           event.setName(bean.getEjbName());
  -        
  +
           context.fireBeanChecked(event);
       }
   
  -    
  -
  -    
  -    
  -
  -
  -    
  -    private boolean verifyPrimaryKey(String className) {
  -        boolean status = true;
  -        Class cls = null;
  -
  -        try {
  -            cls = Class.forName(className);
  -        } catch(Exception e) {
  -            context.fireBeanChecked(new VerificationEvent(context, "Primary key 
class is not available."));
  -            return false;  // Can't do any other checks if the class is null!
  -        }
   
  -        if(!isPublic(cls)) {
  -            status = false;
  -            context.fireBeanChecked(new VerificationEvent(context, "Primary key 
class must be public (see section 9.4.7.2)."));
  -        }
   
  -        if(!isAllFieldsPublic(cls)) {
  -            status = false;
  -            context.fireBeanChecked(new VerificationEvent(context, "Primary key 
fields must all be public (see section 9.4.7.2)."));
  -        }
   
  -        if(!hasANonStaticField(cls)) {
  -            status = false;
  -            context.fireBeanChecked(new VerificationEvent(context, "Primary key 
must have at least one nonstatic field."));
  -        }
   
  -        Object one, two;
  -        try {
  -            one = cls.newInstance();
  -            two = cls.newInstance();
  -            if(!one.equals(two)) {
  -                status = false;
  -                context.fireBeanChecked(new VerificationEvent(context, "Primary key 
does not implement equals() correctly (see section 9.2.9)."));
  -            }
  -            if(one.hashCode() != two.hashCode()) {
  -                status = false;
  -                context.fireBeanChecked(new VerificationEvent(context, "Primary key 
does not implement hashCode() correctly (see section 9.2.9)."));
  -            }
  -        } catch(Exception e) {
  -            status = false;
  -        }
   
  -        return status;
  -    }
   
   
  -    private boolean isAllFieldsPublic(Class c) {
  -        try {
  -            Field list[] = c.getFields();
  -            for(int i=0; i<list.length; i++)
  -                if(!Modifier.isPublic(list[i].getModifiers()))
  -                    return false;
  -        } catch(Exception e) {
  -            return false;
  +    private boolean verifyPrimaryKey(EntityMetaData entity) {
  +        boolean status = true;
  +        if(entity.getPrimaryKeyClass() == null || 
entity.getPrimaryKeyClass().length() == 0) {
  +            fireSpecViolationEvent(entity, new Section("16.5.a"));
  +            return false; // We can't get any further if there's no PK class 
specified!
           }
  -        return true;
  -    }
   
  -    private boolean hasANonStaticField(Class c) {
  -        try {
  -            Field list[] = c.getFields();
  -            for(int i=0; i<list.length; i++)
  -                if(!Modifier.isStatic(list[i].getModifiers()))
  -                    return true;
  -        } catch(Exception e) {
  -        }
  -        return false;
  -    }
  +        if(entity.getPrimKeyField() == null || entity.getPrimKeyField().length() == 
0) {
   
  +            Class cls = null;
   
  +            try {
  +                cls = classloader.loadClass(entity.getPrimaryKeyClass());
   
  -    
  +                if(entity.isCMP()) {
  +                    if(!isPublic(cls)) {
  +                        status = false;
  +                        fireSpecViolationEvent(entity, new Section("9.4.7.2.a"));
  +                    }
   
  +                    if(!isAllFieldsPublic(cls)) {
  +                        status = false;
  +                        fireSpecViolationEvent(entity, new Section("9.4.7.2.b"));
  +                    }
   
  +                    if(!hasANonStaticField(cls)) {
  +                        status = false;
  +                        fireSpecViolationEvent(entity, new Section("9.4.7.2.c"));
  +                    }
  +                }
   
  +                if(!cls.getName().equals("java.lang.Object")) {
  +                    Object one, two;
  +                    try {
  +                        one = cls.newInstance();
  +                        two = cls.newInstance();
  +                        try {
  +                            if(!one.equals(two)) {
  +                                status = false;
  +                                fireSpecViolationEvent(entity, new 
Section("9.2.9.b"));
  +                            }
  +                        } catch(NullPointerException e) {} // That's OK - the 
implementor expected the fields to have values
  +                        try {
  +                            if(one.hashCode() != two.hashCode()) {
  +                                status = false;
  +                                fireSpecViolationEvent(entity, new 
Section("9.2.9.c"));
  +                            }
  +                        } catch(NullPointerException e) {} // That's OK - the 
implementor expected the fields to have values
  +                    } catch(IllegalAccessException e) {
  +                        fireSpecViolationEvent(entity, new Section("9.2.9.a"));
  +                        status = false;
  +                    } catch(InstantiationException e) {
  +                        fireSpecViolationEvent(entity, new Section("9.2.9.a"));
  +                        status = false;
  +                    }
  +                }
  +            } catch(ClassNotFoundException e) {
  +                fireSpecViolationEvent(entity, new Section("16.2.e"));
  +                status = false;  // Can't do any other checks if the class is null!
  +            }
  +        } else {
  +            if(entity.isBMP()) {
  +                fireSpecViolationEvent(entity, new Section("9.4.7.1.a"));
  +                status = false;
  +            }
  +            try {
  +                Class fieldClass = classloader.loadClass(entity.getEjbClass());
  +                Field field = null;
  +                try {
  +                    field = fieldClass.getField(entity.getPrimKeyField());
  +                    
if(!entity.getPrimaryKeyClass().equals(field.getType().getName())) {
  +                        status = false;
  +                        fireSpecViolationEvent(entity, new Section("9.4.7.1.c"));
  +                    }
  +                    Iterator it = entity.getCMPFields();
  +                    boolean found = false;
  +                    while(it.hasNext()) {
  +                        String fieldName = (String)it.next();
  +                        if(fieldName.equals(entity.getPrimKeyField())) {
  +                            found = true;
  +                            break;
  +                        }
  +                    }
  +                    if(!found) {
  +                        status = false;
  +                        fireSpecViolationEvent(entity, new Section("9.4.7.1.d"));
  +                    }
  +                } catch(NoSuchFieldException e) {
  +                    status = false;
  +                    fireSpecViolationEvent(entity, new Section("9.4.7.1.b"));
  +                }
  +            } catch(ClassNotFoundException e) {} // reported elsewhere
  +        }
   
  +        return status;
  +    }
   }
   
  
  
  

Reply via email to