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

ListenerClassHasValidConstructor

public class ListenerClassHasValidConstructor extends ListenerClass implements WebCheck
Listener class must implement a no arg constructor. Verify that the Listener class implements a no arg constructor.
author
Jerome Dochez
version
1.0

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

Run the verifier test against a declared individual listener class

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

        
        boolean validConstructor = false;
        boolean foundIt = false;
        
        if (listenerClass == null) 
            return false;
        
        // walk up the class tree 
        do {
            Constructor[] constructors = listenerClass.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) {
                    if (Modifier.isPublic(constructors[i].getModifiers())) {
                        validConstructor=true;
                    } else {
                        validConstructor=false;
                    }
                    foundIt = true;
                    break;
                }
            }
        } while ((!foundIt) && ((listenerClass=listenerClass.getSuperclass()) != null));
        
        if (validConstructor) {
	   
            result.addGoodDetails(smh.getLocalString
                (getClass().getName() + ".passed",
                    "Listener class [ {0} ] implements a valid constructor.",
                    new Object[] {listenerClass.getName()}));
        } else {
	 
            result.addErrorDetails(smh.getLocalString
                (getClass().getName() + ".failed",
                 "Error: Listener class [ {0} ] does not implement a valid constructor.",
                 new Object[] {listenerClass.getName()}));
        }   
        return validConstructor;