User: juha    
  Date: 00/08/20 13:29:17

  Modified:    src/main/org/jboss/verifier/strategy EJBVerifier11.java
                        AbstractVerifier.java
  Log:
  Verifies entity bean class (section 9.2.2):
   - must implement EntityBean
   - public, non-abstract, non-final class
   - default constructor
   - no finalizer()
  Verifies ejbCreate(...) methods (section 9.2.3):
   - must be public, non-final, non-static
   - must return bean's prim key type
   - must be legal RMI/IIOP (NYI)
  Verifies ejbPostCreate(...) methods (section 9.2.4)
   - must be public, non-final, non-static
   - must return void
   - args must match corresponding ejbCreate(...)
  Verifies ejbFind methods (section 9.2.5)
   - all entities must define ejbFindByPrimaryKey
   - finder return type must be prim key type, Collection or Enumeration
   - finder must be public, non-final, non-static
   - finder method arguments must be legal RMI/IIOP (NYI)
  
  Revision  Changes    Path
  1.13      +539 -82   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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- EJBVerifier11.java        2000/08/12 00:42:13     1.12
  +++ EJBVerifier11.java        2000/08/20 20:29:16     1.13
  @@ -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.12 2000/08/12 00:42:13 salborini Exp $
  + * $Id: EJBVerifier11.java,v 1.13 2000/08/20 20:29:16 juha Exp $
    */
   
   
  @@ -58,7 +58,7 @@
    * @see     org.jboss.verifier.strategy.AbstractVerifier
    *
    * @author   Juha Lindfors ([EMAIL PROTECTED])
  - * @version $Revision: 1.12 $
  + * @version $Revision: 1.13 $
    * @since    JDK 1.3
    */
   public class EJBVerifier11 extends AbstractVerifier {
  @@ -69,7 +69,9 @@
   
   
       /*
  -     *  Constructor
  +     * Constructor
  +     *  
  +     * @param   context
        */
       public EJBVerifier11(VerificationContext context) {
   
  @@ -99,57 +101,68 @@
   
       public void checkSession(SessionMetaData session) {
   
  -        boolean sessionDescriptorVerified = true; //  false;
  -
           boolean beanVerified   = false;
           boolean homeVerified   = false;
           boolean remoteVerified = false;
   
  -        //sessionDescriptorVerified = verifySessionDescriptor();
  -
  -
   
           beanVerified   = verifySessionBean(session);
           homeVerified   = verifySessionHome(session);
           remoteVerified = verifySessionRemote(session);
   
   
  -        if ( beanVerified && homeVerified && remoteVerified &&
  -             sessionDescriptorVerified) {
  +        if (beanVerified && homeVerified && remoteVerified) {
   
               /*
                * Verification for this session bean done. Fire the event
                * to tell listeneres everything is ok.
                */
  -            VerificationEvent event = factory.createBeanVerifiedEvent(context);
  -            context.fireBeanChecked(event);
  +            fireBeanVerifiedEvent(session);
           }
       }
   
   
       public void checkEntity(EntityMetaData entity) {
  -        boolean pkVerified = false;
  +        
  +        boolean pkVerified     = true;      // false;
  +        boolean beanVerified   = false;
  +        boolean homeVerified   = false;
  +        boolean remoteVerified = false;
  +
  +        /*
  +         * [TODO] verify the contents of the ejb-jar.xml:
  +         *
  +         *  - prim key class is fully qualified class name
  +         */
  +         
  +        beanVerified   = verifyEntityBean(entity);
  +        homeVerified   = verifyEntityHome(entity);
  +        remoteVerified = verifyEntityRemote(entity);
  +
   
           // will put this back later
           //pkVerified = verifyPrimaryKey(entity.getPrimaryKeyClass());
   
  -        // NO IMPLEMENTATION
  +        if ( beanVerified && homeVerified && remoteVerified && pkVerified) {
  +
  +            /*
  +             * Verification for this entity bean done. Fire the event
  +             * to tell listeneres everything is ok.
  +             */
  +            fireBeanVerifiedEvent(entity);
  +        }
  +
       }
   
       public StrategyContext getContext() {
           return context;
       }
   
  -    public void checkMessageDriven(BeanMetaData beans) {
   
  -            // EMPTY IMPLEMENTATION, EJB 2.0 ONLY
  -    }
  -
  -
   /*
    *****************************************************************************
    *
  - *  PRIVATE INSTANCE METHODS
  + *      VERIFY SESSION BEAN HOME INTERFACE
    *
    *****************************************************************************
    */
  @@ -181,19 +194,19 @@
                if (session.isStateless()) {
                    
                    if (!hasDefaultCreateMethod(home)) {
  -                    fireSpecViolationEvent(new Section("6.8.a"));
  +                    fireSpecViolationEvent(session, new Section("6.8.a"));
   
                       status = false;
                    }
                    
                    if (!hasRemoteReturnType(session, getDefaultCreateMethod(home))) {
  -                     fireSpecViolationEvent(new Section("6.8.b"));;
  +                     fireSpecViolationEvent(session, new Section("6.8.b"));;
                        
                        status = false;
                    }
                    
                    if (hasMoreThanOneCreateMethods(home)) {
  -                     fireSpecViolationEvent(new Section("6.8.c"));
  +                     fireSpecViolationEvent(session, new Section("6.8.c"));
                        
                        status = false;
                    }   
  @@ -207,7 +220,7 @@
                */
               if (!hasEJBHomeInterface(home)) {
                   
  -                fireSpecViolationEvent(new Section("6.10.6.a"));
  +                fireSpecViolationEvent(session, new Section("6.10.6.a"));
                   
                   status = false;
               }
  @@ -232,21 +245,21 @@
                   
                   if (!hasLegalRMIIIOPArguments(method)) {
                       
  -                    fireSpecViolationEvent(new Section("6.10.6.b"));
  +                    fireSpecViolationEvent(session, new Section("6.10.6.b"));
                       
                       status = false;
                   }
                   
                   if (!hasLegalRMIIIOPReturnType(method)) {
                       
  -                    fireSpecViolationEvent(new Section("6.10.6.c"));
  +                    fireSpecViolationEvent(session, new Section("6.10.6.c"));
                       
                       status = false;
                   }
                   
                   if (!throwsRemoteException(method)) {
                       
  -                    fireSpecViolationEvent(new Section("6.10.6.d"));
  +                    fireSpecViolationEvent(session, new Section("6.10.6.d"));
                       
                       status = false;
                   }
  @@ -260,7 +273,7 @@
                */
               if (!hasCreateMethod(home)) {
                   
  -                fireSpecViolationEvent(new Section("6.10.6.e"));
  +                fireSpecViolationEvent(session, new Section("6.10.6.e"));
   
                   status = false;
               }
  @@ -269,10 +282,13 @@
           }
           catch (ClassNotFoundException e) {
   
  -            VerificationEvent event =
  -                    factory.createSpecViolationEvent(context, new 
Section("16.2.c"));
  -
  -            context.fireBeanChecked(event);
  +            /*
  +             * The bean provider MUST specify the fully-qualified name of the
  +             * enterprise bean's  home interface in the <home> element.
  +             *
  +             * Spec 16.2
  +             */
  +            fireSpecViolationEvent(session, new Section("16.2.c"));
   
               status = false;
           }
  @@ -281,7 +297,13 @@
   
       }
   
  -    
  +/*
  + *************************************************************************
  + *
  + *      VERIFY SESSION BEAN REMOTE INTERFACE
  + *
  + *************************************************************************
  + */    
       
       private boolean verifySessionRemote(SessionMetaData session) {
   
  @@ -305,7 +327,7 @@
                */
               if (!hasEJBObjectInterface(remote)) {
                   
  -                fireSpecViolationEvent(new Section("6.10.5.a"));
  +                fireSpecViolationEvent(session, new Section("6.10.5.a"));
       
                   status = false;
               }
  @@ -330,21 +352,21 @@
                   
                   if (!hasLegalRMIIIOPArguments(method)) {
                       
  -                    fireSpecViolationEvent(new Section("6.10.5.b"));
  +                    fireSpecViolationEvent(session, new Section("6.10.5.b"));
                       
                       status = false;
                   }
                   
                   if (!hasLegalRMIIIOPReturnType(method)) {
                       
  -                    fireSpecViolationEvent(new Section("6.10.5.c"));
  +                    fireSpecViolationEvent(session, new Section("6.10.5.c"));
                       
                       status = false;
                   }
                   
                   if (!throwsRemoteException(method)) {
                       
  -                    fireSpecViolationEvent(new Section("6.10.5.d"));
  +                    fireSpecViolationEvent(session, new Section("6.10.5.d"));
                       
                       status = false;
                   }
  @@ -370,21 +392,21 @@
                   
                   if (!hasMatchingMethodNames(remote, bean)) {
                       
  -                    fireSpecViolationEvent(new Section("6.10.5.e"));
  +                    fireSpecViolationEvent(session, new Section("6.10.5.e"));
                       
                       status = false;
                   }
                   
                   if (!hasMatchingMethodArgs(remote, bean)) {
                       
  -                    fireSpecViolationEvent(new Section("6.10.5.f"));
  +                    fireSpecViolationEvent(session, new Section("6.10.5.f"));
                       
                       status = false;
                   }
                   
                   if (!hasMatchingMethodExceptions(remote, bean)) {
                       
  -                    fireSpecViolationEvent(new Section("6.10.5.g"));
  +                    fireSpecViolationEvent(session, new Section("6.10.5.g"));
                       
                       status = false;
                   }
  @@ -395,10 +417,13 @@
           }
           catch (ClassNotFoundException e) {
   
  -            VerificationEvent event =
  -                    factory.createSpecViolationEvent(context, new 
Section("16.2.d"));
  -
  -            context.fireBeanChecked(event);
  +            /*
  +             * The Bean Provider MUST specify the fully-qualified name of the
  +             * enterprise bean's remote interface in the <remote> element.
  +             *
  +             * Spec 16.2
  +             */
  +            fireSpecViolationEvent(session, new Section("16.2.d"));
   
               status = false;
           }
  @@ -406,7 +431,13 @@
           return status;
       }
   
  -    
  +/*
  + *************************************************************************
  + *
  + *      VERIFY SESSION BEAN CLASS
  + *
  + *************************************************************************
  + */    
       
       private boolean verifySessionBean(SessionMetaData session) {
   
  @@ -432,7 +463,7 @@
                */
               if (!hasSessionBeanInterface(bean)) {
   
  -                fireSpecViolationEvent(new Section("6.5.1"));
  +                fireSpecViolationEvent(session, new Section("6.5.1"));
   
                   status = false;
               }
  @@ -450,13 +481,13 @@
               if (hasSessionSynchronizationInterface(bean)) {
   
                   if (session.isStateless()) {
  -                    fireSpecViolationEvent(new Section("6.5.3.a"));
  +                    fireSpecViolationEvent(session, new Section("6.5.3.a"));
   
                       status = false;
                   }
   
                   if (session.isBeanManagedTx()) {
  -                    fireSpecViolationEvent(new Section("6.5.3.b"));
  +                    fireSpecViolationEvent(session, new Section("6.5.3.b"));
   
                       status = false;
                   }
  @@ -470,7 +501,7 @@
                */
               if (!hasEJBCreateMethod(bean)) {
                   
  -                fireSpecViolationEvent(new Section("6.5.5"));
  +                fireSpecViolationEvent(session, new Section("6.5.5"));
   
                   status = false;
               }
  @@ -484,7 +515,7 @@
                */
               if (hasSessionSynchronizationInterface(bean) && 
session.isBeanManagedTx()) {
   
  -                fireSpecViolationEvent(new Section("6.6.1"));
  +                fireSpecViolationEvent(session, new Section("6.6.1"));
   
                   status = false;
               }
  @@ -494,9 +525,9 @@
                *
                * Spec 6.10.2
                */
  -            if (!isPublicClass(bean)) {
  +            if (!isPublic(bean)) {
   
  -               fireSpecViolationEvent(new Section("6.10.2.a"));
  +               fireSpecViolationEvent(session, new Section("6.10.2.a"));
   
                  status = false;
               }
  @@ -506,9 +537,9 @@
                *
                * Spec 6.10.2
                */
  -            if (isFinalClass(bean)) {
  +            if (isFinal(bean)) {
   
  -                fireSpecViolationEvent(new Section("6.10.2.b"));
  +                fireSpecViolationEvent(session, new Section("6.10.2.b"));
   
                   status = false;
               }
  @@ -518,9 +549,9 @@
                *
                * Spec 6.10.2
                */
  -            if (isAbstractClass(bean)) {
  +            if (isAbstract(bean)) {
   
  -                fireSpecViolationEvent(new Section("6.10.2.c"));
  +                fireSpecViolationEvent(session, new Section("6.10.2.c"));
   
                   status = false;
               }
  @@ -533,7 +564,7 @@
                */
               if (!hasDefaultConstructor(bean)) {
   
  -                fireSpecViolationEvent(new Section("6.10.2.d"));
  +                fireSpecViolationEvent(session, new Section("6.10.2.d"));
   
                   status = false;
               }
  @@ -545,7 +576,7 @@
                */
               if (hasFinalizer(bean)) {
   
  -                fireSpecViolationEvent(new Section("6.10.2.e"));
  +                fireSpecViolationEvent(session, new Section("6.10.2.e"));
   
                   status = false;
               }
  @@ -568,28 +599,28 @@
                       
                       Method ejbCreate = (Method)it.next();
                       
  -                    if (!isPublicMember(ejbCreate)) {
  +                    if (!isPublic(ejbCreate)) {
                           
  -                        fireSpecViolationEvent(new Section("6.10.3.a"));
  +                        fireSpecViolationEvent(session, new Section("6.10.3.a"));
                           status = false;
                       }
                       
  -                    if ( (isFinalMember(ejbCreate)) ||
  -                         (isStaticMember(ejbCreate)) ) {
  +                    if ( (isFinal(ejbCreate)) ||
  +                         (isStatic(ejbCreate)) ) {
                                 
  -                        fireSpecViolationEvent(new Section("6.10.3.b"));
  +                        fireSpecViolationEvent(session, new Section("6.10.3.b"));
                           status = false;
                       }
                       
                       if (!hasVoidReturnType(ejbCreate)) {
                           
  -                        fireSpecViolationEvent(new Section("6.10.3.c"));
  +                        fireSpecViolationEvent(session, new Section("6.10.3.c"));
                           status = false;
                       }
                       
                       if (!hasLegalRMIIIOPArguments(ejbCreate)) {
                           
  -                        fireSpecViolationEvent(new Section("6.10.3.d"));
  +                        fireSpecViolationEvent(session, new Section("6.10.3.d"));
                           status = false;
                       }
                   }
  @@ -598,19 +629,457 @@
   
           }
           catch (ClassNotFoundException e) {
  +
  +            /*
  +             * The Bean Provider MUST specify the fully-qualified name of the
  +             * Java class that implements the enterprise bean's business
  +             * methods.
  +             *
  +             * Spec 16.2
  +             */
  +            fireSpecViolationEvent(session, new Section("16.2.b"));
  +            
  +            status = false;
  +        }
  +
  +        return status;
  +    }
  +
  +
  +/*
  + *************************************************************************
  + *
  + *      VERIFY ENTITY BEAN HOME INTERFACE
  + *
  + *************************************************************************
  + */
  + 
  +    private boolean verifyEntityHome(EntityMetaData entity) {
  +
  +        /*
  +         * Indicates whether we issued warnings or not during verification.
  +         * This boolean is returned to the caller.
  +         */
  +        boolean status = true;
  +
  +        String name = entity.getHome();
  +        
  +        try {
  +            Class home = classloader.loadClass(name);
  +
  +
  +             
  +        }
  +        catch (ClassNotFoundException e) {
  +
  +            /*
  +             * The bean provider MUST specify the fully-qualified name of the
  +             * enterprise bean's  home interface in the <home> element.
  +             *
  +             * Spec 16.2
  +             */
  +            fireSpecViolationEvent(entity, new Section("16.2.c"));
  +
  +            status = false;
  +        }
  +        
  +        return status;
  +
  +    }
  +
  +    
  +/*
  + *************************************************************************
  + *  
  + *      VERIFY ENTITY BEAN REMOTE INTERFACE
  + *
  + *************************************************************************
  + */
  +    
  +    private boolean verifyEntityRemote(EntityMetaData entity) {
  +
  +        /*
  +         * Indicates whether we issued warnings or not during verification.
  +         * This boolean is returned to the caller.
  +         */
  +        boolean status = true;
  +
  +        String  name   = entity.getRemote();
  +
  +
  +        try {
  +            Class home = classloader.loadClass(name);
  +
  +
  +        }
  +        catch (ClassNotFoundException e) {
   
  -            VerificationEvent event =
  -                    factory.createSpecViolationEvent(context, new 
Section("16.2.b"));
  +            /*
  +             * The Bean Provider MUST specify the fully-qualified name of the
  +             * enterprise bean's remote interface in the <remote> element.
  +             *
  +             * Spec 16.2
  +             */
  +            fireSpecViolationEvent(entity, new Section("16.2.d"));
   
  -            context.fireBeanChecked(event);
  +            status = false;
  +        }
  +
  +        return status;
  +    }
  +
  +    
  +
  +/*
  + *************************************************************************
  + *
  + *      VERIFY ENTITY BEAN CLASS
  + *
  + *************************************************************************
  + */
  +    
  +    private boolean verifyEntityBean(EntityMetaData entity) {
  +
  +        /*
  +         * Indicates whether we issued warnings or not during verification.
  +         * This boolean is returned to the caller.
  +         */
  +        boolean status = true;
  +
  +        String  name   = entity.getEjbClass();
  +
  +
  +        try {
  +            Class bean = classloader.loadClass(name);
  +
  +            /*
  +             * The enterprise bean class MUST implement, directly or
  +             * indirectly, the javax.ejb.EntityBean interface.
  +             *
  +             * Spec 9.2.2
  +             */
  +            if (!hasEntityBeanInterface(bean)) {
  +
  +                fireSpecViolationEvent(entity, new Section("9.2.2.a"));
  +
  +                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
  +             *
  +             * 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:
  +             *
  +             *      - The method MUST be declared as public
  +             *      - The method MUST NOT be declared as final or static
  +             *      - The return type MUST be the entity bean's primary key type
  +             *      - The method arguments MUST be legal types for RMI/IIOP
  +             *      - The method return value type MUST be legal type for RMI/IIOP
  +             *
  +             * Spec 9.2.3
  +             */
  +            if (hasEJBCreateMethod(bean)) {
  +                
  +                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. 
  +             *
  +             * The ejbPostCreate(...) method MUST follow these rules:
  +             *
  +             *   - the method MUST be declared as public
  +             *   - the method MUST NOT be declared as final or static
  +             *   - the return type MUST be void
  +             *   - the method arguments MUST be the same as the matching
  +             *     ejbCreate(...) method
  +             *
  +             * Spec 9.2.4
  +             */
  +            if (hasEJBCreateMethod(bean)) {
  +                
  +                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;
  +                        }
  +                    }
  +                }
  +            }
  +            
  +            
  +            /*
  +             * Every entity bean MUST define the ejbFindByPrimaryKey method.
  +             *
  +             * The return type for the ejbFindByPrimaryKey method MUST be the
  +             * primary key type.
  +             *
  +             * The ejbFindByPrimaryKey method MUST be a single-object finder.
  +             *
  +             * Spec 9.2.5
  +             */
  +            if (!hasEJBFindByPrimaryKey(bean)) {
  +                
  +                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.
  +             *
  +             * A finder method MUST NOT be declared as static.
  +             *
  +             * A finder method MUST NOT be declared as final.
  +             *
  +             * The finder method argument types MUST be legal types
  +             * for RMI/IIOP
  +             *
  +             * The finder method return type MUST be either the entity bean's
  +             * primary key type, or java.lang.util.Enumeration interface or
  +             * java.lang.util.Collection interface.
  +             *
  +             * 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) {
   
  +            /*
  +             * The Bean Provider MUST specify the fully-qualified name of the
  +             * Java class that implements the enterprise bean's business
  +             * methods.
  +             *
  +             * 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;
  @@ -622,7 +1091,7 @@
               return false;  // Can't do any other checks if the class is null!
           }
   
  -        if(!isPublicClass(cls)) {
  +        if(!isPublic(cls)) {
               status = false;
               context.fireBeanChecked(new VerificationEvent(context, "Primary key 
class must be public (see section 9.4.7.2)."));
           }
  @@ -657,12 +1126,6 @@
       }
   
   
  -
  -
  -
  -
  -
  -
       private boolean isAllFieldsPublic(Class c) {
           try {
               Field list[] = c.getFields();
  @@ -688,13 +1151,7 @@
   
   
   
  -    private void fireSpecViolationEvent(Section section) {
  -
  -        VerificationEvent event =
  -                factory.createSpecViolationEvent(context, section);
  -
  -        context.fireBeanChecked(event);
  -    }
  +    
   
   
   
  
  
  
  1.9       +291 -133  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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AbstractVerifier.java     2000/08/12 00:42:13     1.8
  +++ AbstractVerifier.java     2000/08/20 20:29:16     1.9
  @@ -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: AbstractVerifier.java,v 1.8 2000/08/12 00:42:13 salborini Exp $
  + * $Id: AbstractVerifier.java,v 1.9 2000/08/20 20:29:16 juha Exp $
    */
   
   // standard imports
  @@ -49,80 +49,26 @@
    * @see     org.jboss.verifier.strategy.VerificationStrategy
    *
    * @author   Juha Lindfors ([EMAIL PROTECTED])
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    * @since    JDK 1.3
    */
   public abstract class AbstractVerifier implements VerificationStrategy {
   
  -    /*
  -     * checks if a class's member (method, constructor or field) has a 'static'
  -     * modifier.
  -     */
  -    public boolean isStaticMember(Member member) {
  -
  -        if (Modifier.isStatic(member.getModifiers()))
  -            return true;
  -
  -        return false;
  -    }
  -
  -    /*
  -     * checks if a class's member (method, constructor or field) has a 'final'
  -     * modifier.
  -     */
  -    public boolean isFinalMember(Member member) {
  -
  -        if (Modifier.isFinal(member.getModifiers()))
  -            return true;
  -
  -        return false;
  -    }
  -
  -    /*
  -     * checks if a class's memeber (method, constructor or field) has a 'public'
  -     * modifier.
  -     */
  -    public boolean isPublicMember(Member member) {
  -
  -        if (Modifier.isPublic(member.getModifiers()))
  -            return true;
  -
  -        return false;
  -    }
  -
  -
  -    /*
  -     * checks if the session type is 'Stateful'
  -     */
  -    public boolean isStateful(SessionMetaData session) {
  -
  -        return session.isStateful();
  -    }
  -
  -    /*
  -     * checks if the session type is 'Stateless'
  -     */
  -    public boolean isStateless(SessionMetaData session) {
  -
  -        return session.isStateless();
  -    }
  -
  -    /*
  -     * checks if a method has a void return type
  -     */
  -    public boolean hasVoidReturnType(Method method) {
   
  -        return (method.getReturnType() == Void.TYPE);
  -    }
  -
  -
  -
       public boolean hasLegalRMIIIOPReturnType(Method method) {
  +        
  +        // [TODO]
  +        
  +        
           return true;
       }
   
       public boolean hasLegalRMIIIOPArguments(Method method) {
   
  +        
  +        // [TODO]
  +        
  +        
           return true;
   
   
  @@ -162,56 +108,67 @@
   
   
       /*
  -     * checks if the given class is declared as public
  +     * checks if the method includes java.rmi.RemoteException in its
  +     * throws clause.
        */
  -    public boolean isPublicClass(Class c) {
  +    public boolean throwsRemoteException(Method method) {
   
  -        if (Modifier.isPublic(c.getModifiers()))
  -            return true;
  +        Class[] exception = method.getExceptionTypes();
   
  +        for (int i = 0; i < exception.length; ++i) {
  +
  +            if (exception[i].getName().equals(REMOTE_EXCEPTION))
  +                return true;
  +        }
  +
           return false;
       }
   
  +    
  +    
  +    /*
  +     * checks if a class's member (method, constructor or field) has a 'static'
  +     * modifier.
  +     */
  +    public boolean isStatic(Member member) {
  +        return (Modifier.isStatic(member.getModifiers()));
  +    }
   
       /*
  +     * checks if a class's member (method, constructor or field) has a 'final'
  +     * modifier.
  +     */
  +    public boolean isFinal(Member member) {
  +        return (Modifier.isFinal(member.getModifiers()));
  +    }
  +    
  +    /*
        * checks if the given class is declared as final
        */
  -    public boolean isFinalClass(Class c) {
  -
  -        if (Modifier.isFinal(c.getModifiers()))
  -            return true;
  -
  -        return false;
  +    public boolean isFinal(Class c) {
  +        return (Modifier.isFinal(c.getModifiers()));
       }
   
  -
       /*
  -     * checks if the given class is declared as abstract
  +     * checks if a class's memeber (method, constructor or field) has a 'public'
  +     * modifier.
        */
  -    public boolean isAbstractClass(Class c) {
  -
  -        if (Modifier.isAbstract(c.getModifiers()))
  -            return true;
  -
  -        return false;
  +    public boolean isPublic(Member member) {
  +        return (Modifier.isPublic(member.getModifiers()));
       }
   
  -
       /*
  -     * checks if the method includes java.rmi.RemoteException in its
  -     * throws clause.
  +     * checks if the given class is declared as public
        */
  -    public boolean throwsRemoteException(Method method) {
  -
  -        Class[] exception = method.getExceptionTypes();
  -
  -        for (int i = 0; i < exception.length; ++i) {
  -
  -            if (exception[i].getName().equals(REMOTE_EXCEPTION))
  -                return true;
  -        }
  +    public boolean isPublic(Class c) {
  +        return (Modifier.isPublic(c.getModifiers()));
  +    }
   
  -        return false;
  +    /*
  +     * checks if the given class is declared as abstract
  +     */
  +    public boolean isAbstract(Class c) {
  +        return (Modifier.isAbstract(c.getModifiers()));
       }
   
       /*
  @@ -221,6 +178,34 @@
           return hasInterface(c, SERIALIZATION_INTERFACE);
       }
   
  +    /*
  +     * checks if finder returns the primary key type
  +     */
  +    public boolean isSingleObjectFinder(EntityMetaData entity, Method finder) {
  +        return hasPrimaryKeyReturnType(entity, finder);
  +    }
  +
  +    /*
  +     * checks if finder method returns either Collection or Enumeration
  +     */
  +    public boolean isMultiObjectFinder(Method finder) {
  +        return (finder.getReturnType().getName().equals(COLLECTION_INTERFACE)
  +                || finder.getReturnType().getName().equals(ENUMERATION_INTERFACE));
  +    }
  +
  +    /*
  +     *  checks the return type of method matches the bean's remote interface
  +     */
  +    public boolean hasRemoteReturnType(BeanMetaData bean, Method m) {
  +        return (m.getReturnType().getName().equals(bean.getRemote()));
  +    }
  +    
  +    /*
  +     * checks if a method has a void return type
  +     */
  +    public boolean hasVoidReturnType(Method method) {
  +        return (method.getReturnType() == Void.TYPE);
  +    }
   
       /*
        * Finds java.ejb.SessionBean interface from the class
  @@ -229,8 +214,14 @@
           return hasInterface(c, SESSION_BEAN_INTERFACE);
       }
   
  -
       /*
  +     * Finds java.ejb.EntityBean interface from the class
  +     */
  +     public boolean hasEntityBeanInterface(Class c) {
  +         return hasInterface(c, ENTITY_BEAN_INTERFACE);
  +     }
  +     
  +    /*
        * Finds java.ejb.EJBObject interface from the class
        */
       public boolean hasEJBObjectInterface(Class c) {
  @@ -251,15 +242,16 @@
           return hasInterface(c, SESSION_SYNCHRONIZATION_INTERFACE);
       }
   
  -
       /*
        * Checks if a class has a default (no args) constructor
        */
       public boolean hasDefaultConstructor(Class c) {
  +
           try {
  +
               c.newInstance();
  -        }
   
  +        }
           catch(Exception e) {
               return false;
           }
  @@ -267,20 +259,19 @@
           return true;
       }
   
  -
       /*
        * Checks of the class defines a finalize() method
        */
       public boolean hasFinalizer(Class c) {
   
           try {
  +
               Method finalizer = c.getDeclaredMethod(FINALIZE_METHOD, new Class[0]);
  -        }
   
  +        }
           catch (NoSuchMethodException e) {
               return false;
           }
  -
           catch (SecurityException e) {
               System.err.println(e);
               return false;
  @@ -290,6 +281,29 @@
       }
   
       /*
  +     * 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;
  +            }
  +        }
  +        catch (SecurityException e) {
  +            System.err.println(e);
  +        }
  +        
  +        return false;
  +    }
  +    
  +    /*
        * Searches for an instance of a public create method from the class
        */
       public boolean hasCreateMethod(Class c) {
  @@ -305,11 +319,8 @@
                       return true;
               }
           }
  -
           catch (SecurityException e) {
               System.err.println(e);
  -            // [TODO]   Can be thrown by the getMethods() call if access is
  -            //          denied --> createVerifierWarningEvent
           }
   
           return false;
  @@ -328,8 +339,8 @@
                   String name = method[i].getName();
   
                   if (name.equals(EJB_CREATE_METHOD))
  -                    if (!isStaticMember(method[i])
  -                            && !isFinalMember(method[i])
  +                    if (!isStatic(method[i])
  +                            && !isFinal(method[i])
                               && hasVoidReturnType(method[i]))
   
                           return true;
  @@ -337,8 +348,6 @@
           }
           catch (SecurityException e) {
               System.err.println(e);
  -            // [TODO]   Can be thrown by the getMethods() call if access is
  -            //          denied --> createVerifierWarningEvent
           }
   
           return false;
  @@ -366,33 +375,68 @@
                   }
               }
           }
  -
           catch (SecurityException e) {
               System.err.println(e);
  -            // [TODO]   Can be thrown by the getMethods() call if access is
  -            //          denied --> createVerifierWarningEvent
           }
   
           return false;
       }
  -
  -    public boolean hasRemoteReturnType(BeanMetaData session, Method m) {
   
  -        if (m.getReturnType().getName().equals(session.getRemote()))
  -            return true;
  -
  +    /*
  +     * 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;
  +            }
  +        }
  +        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.
  +     * Returns the default create method. Return null if not found.
        */
       public Method getDefaultCreateMethod(Class c) {
   
  +        Method method = null;
  +        
           try {
  -            Method[] method = c.getMethods();
   
  +            method = c.getMethod(CREATE_METHOD, null);
  +
  +        }
  +        catch (SecurityException e) {
  +            System.err.println(e);
  +        }
  +        catch (NoSuchMethodException ignored) {}
  +        
  +        return method;
  +    }
  +
  +/*          Method[] method = c.getMethods();
  +
               for (int i = 0; i < method.length; ++i) {
   
                   String name = method[i].getName();
  @@ -404,17 +448,55 @@
                           return method[i];
                   }
               }
  -        }
  +*/
   
  +    /*
  +     * 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);
  -            // [TODO]   Can be thrown by the getMethods() call if access is
  -            //          denied --> createVerifierWarningEvent
  -        }
  -
  +        }           
  +        
           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) { 
  +        
  +                if (method[i].getName().startsWith("ejbFind"))
  +                    finders.add(method[i]);
  +            }
  +        }
  +        catch (SecurityException e) {
  +            System.err.println(e);
  +        }
  +        
  +        return finders.iterator();
  +    }
  +    
  +    
       /*
        * Returns the ejbCreate(...) methods of a bean
        */
  @@ -423,7 +505,6 @@
           List ejbCreates = new LinkedList();
   
           try {
  -
               Method[] method = c.getMethods();
   
               for (int i = 0; i < method.length; ++i) {
  @@ -432,11 +513,8 @@
                       ejbCreates.add(method[i]);
               }
           }
  -
           catch (SecurityException e) {
               System.err.println(e);
  -            // [TODO]   Can be thrown by the getMethods() call if access is
  -            //          denied --> createVerifierWarningEvent
           }
   
           return ejbCreates.iterator();
  @@ -452,14 +530,13 @@
   
               return Arrays.asList(method).iterator();
           }
  -
           catch (SecurityException e) {
               System.err.println(e);
   
               return null;
           }
       }
  -
  +    
   
       public boolean hasMoreThanOneCreateMethods(Class c) {
   
  @@ -477,11 +554,8 @@
                   }
               }
           }
  -
           catch (SecurityException e) {
               System.err.println(e);
  -            // [TODO]   Can be thrown by the getMethods() call if access is
  -            //          denied --> createVerifierWarningEvent
           }
   
           return (count > 1);
  @@ -489,20 +563,74 @@
   
       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);        
  +        }
  +        catch (NoSuchMethodException e) {
  +            return false;
  +        }
  +    }
  +    
  +    
  +    public Method getMatchingEJBPostCreate(Class bean, Method ejbCreate) {
  +        
  +        try {
  +            return bean.getMethod(EJB_POST_CREATE, ejbCreate.getParameterTypes());
  +        }
  +        catch (NoSuchMethodException e) {
  +            return null;
  +        }
  +    }
   
  +    
  +/*
  + *************************************************************************
  + *
  + *      IMPLEMENTS VERIFICATIONSTRATEGY INTERFACE
  + *
  + *************************************************************************
  + */
  +
  +    /**
  +     * Provides an empty default implementation for EJB 1.1 verifier (message
  +     * beans are for EJB 2.0 and greater only).
  +     *
  +     * @param beans  the message bean to verify
  +     */
  +    public void checkMessageBean(BeanMetaData bean) {}
  +
  +    
  +/*
  + *************************************************************************
  + *
  + *      PRIVATE INSTANCE METHODS
  + *
  + *************************************************************************
  + */
  + 
       private boolean hasInterface(Class c, String name) {
           try {
               Class intClass = Class.forName(name);
  @@ -512,6 +640,15 @@
       }
   
   
  +
  +/*
  + *************************************************************************
  + *
  + *      STRING CONSTANTS
  + *
  + *************************************************************************
  + */
  + 
       /*
        * Ejb-jar DTD
        */
  @@ -535,15 +672,27 @@
   
   
   
  +    /*
  +     * class names
  +     */
       private final static String SESSION_BEAN_INTERFACE =
           "javax.ejb.SessionBean";
   
       private final static String SESSION_SYNCHRONIZATION_INTERFACE =
           "javax.ejb.SessionSynchronization";
   
  +    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";
   
  @@ -555,9 +704,18 @@
   
   
   
  +    /*
  +     * method names
  +     */
  +    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";
   
  
  
  

Reply via email to