FileDocCategorySizeDatePackage
FilterClassHasValidConstructor.javaAPI DocGlassfish v2 API4467Fri May 04 22:34:10 BST 2007com.sun.enterprise.tools.verifier.tests.web

FilterClassHasValidConstructor

public class FilterClassHasValidConstructor extends FilterClass implements WebCheck
Filter class must implement a no arg constructor. Verify that the Filter class implements a no arg constructor.
author
Jerome Dochez
version
1.0

Fields Summary
Constructors Summary
Methods Summary
protected booleanrunIndividualFilterTest(com.sun.enterprise.tools.verifier.Result result, java.lang.Class filterClass)

Run the verifier test against a declared individual filter class

param
result is used to put the test results in
param
filterClass is the individual filter class object to test
return
true if the test pass

        
        boolean validConstructor = false;
        boolean foundIt = false;
        Class clazz = filterClass;
        
        if (filterClass == null) 
            return false;
        
        // walk up the class tree 
        do {
            Constructor[] constructors = filterClass.getDeclaredConstructors();
            for (int i = 0; i < constructors.length; i++) {
                logger.log(Level.FINE, getClass().getName() + ".debug",
                        new Object[] {constructors[i].toString()});
                Class[] parameters = constructors[i].getParameterTypes();
                if (parameters.length == 0) {
                    // we found it, let's look if it is public
                    if (Modifier.isPublic(constructors[i].getModifiers())) {
                        validConstructor = true;
                    } else {
                        validConstructor = false;
                    }
                    // we exit anyway...
                    foundIt = true;;
                }
            }
        } while ((!foundIt) && ((filterClass=filterClass.getSuperclass()) != null));
        
        if (validConstructor) {
            result.addGoodDetails(smh.getLocalString
                (getClass().getName() + ".passed",
                    "Listener class [ {0} ] implements a valid constructor.",
                    new Object[] {filterClass.getName()}));
        } else {
            result.addErrorDetails(smh.getLocalString
                (getClass().getName() + ".failed",
                 "Error: Listener class [ {0} ] does not implement a valid constructor.",
                 new Object[] {clazz.getName()}));
        }   
        return validConstructor;