FileDocCategorySizeDatePackage
ConnectorTest.javaAPI DocGlassfish v2 API11469Fri May 04 22:33:28 BST 2007com.sun.enterprise.tools.verifier.tests.connector

ConnectorTest

public abstract class ConnectorTest extends com.sun.enterprise.tools.verifier.tests.VerifierTest implements ConnectorCheck, com.sun.enterprise.tools.verifier.tests.VerifierCheck
Superclass for all connector tests, contains common services.
author
Jerome Dochez
version

Fields Summary
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.Descriptor descriptor)

run an individual test against the deployment descriptor for the archive the verifier is performing compliance tests against.

param
descriptor deployment descriptor for the archive
return
result object containing the result of the individual test performed

        return check((ConnectorDescriptor) descriptor);
    
public abstract com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.ConnectorDescriptor descriptor)

all connector tests should implement this method. it run an individual test against the resource adapter deployment descriptor.

param
descriptor deployment descriptor for the rar file
return
result object containing the result of the individual test performed

protected booleancheckMethodImpl(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] parmTypes, java.lang.String methodSignature, com.sun.enterprise.tools.verifier.Result result)

Check that a class overrides some methods defined in the java.lang.Object class

param
clazz the implementation class
param
methodName the method name
param
parmTypes the method parameter types
param
methodSignature a human readable signature description of the method
param
result where to put the method lookup result
return
true if the method is overriden by the implementation class

        
        Method m=null;
        Class c = clazz;
	    
        do {
            try {
                m = c.getDeclaredMethod(methodName, parmTypes);
            } catch(NoSuchMethodException nsme) {
            } catch(SecurityException se) {
            }
            c = c.getSuperclass();
        } while (m != null && c!=null && c != Object.class);            

        if (m==null) {
	    result.failed(smh.getLocalString
	        ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.MethodOverride.failed", 
                "Warning: The class [ {0} ] does not override the method [ {1} ]",
                new Object[] {clazz.getName(), methodSignature }));                  
            return false;
        } else {
	    result.passed(smh.getLocalString
	        ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.MethodOverride.passed", 
                "The class [ {0} ] overrides the method [ {1} ]",
                new Object[] {clazz.getName(), methodSignature }));                                       
            return true;
        }
    
protected java.lang.ClassfindImplementorOf(com.sun.enterprise.deployment.ConnectorDescriptor desc, java.lang.String interfaceName)

Find a class implementating the interface in the jar files contained in the connector rar file.

param
interfaceName the interface the class should implement
return
class implementing the interface or null if not present in the jar files

        /**
        * This is a little bit hectic but we have to go through all the 
        * jar files included in the rar file and load all classes implemented
        * in these jar files. For each class, we should look if the class
        * implements the requested interface "interfaceName"
        */
        
        // let's get the rar file
        try {
            String uri=getAbstractArchiveUri(desc);
            FileArchive arch = new FileArchive();
            arch.open(uri);
            for(Enumeration en = arch.entries();en.hasMoreElements();) {                    
                String entry = (String)en.nextElement();
                if (entry.endsWith(".jar")) {
                    // we found a jar file, let's load it
                    JarInputStream jis = new JarInputStream(arch.getEntry(entry));
                    try {
                        // Now we are going to iterate over the element of the jar file
                        ZipEntry ze = jis.getNextEntry();
                        while(ze!=null) {
                            String elementName = (String) ze.getName();
                            // Is this jar entry a java class file ?
                            if (elementName.endsWith(".class")) {
                                // we found a .class file let's load it and see if it does implement the interface
                                String className = elementName.substring(0, elementName.length()-".class".length()).replace('/",'.");
                                //try {
                                ClassLoader jcl = getVerifierContext().getRarClassLoader();
                                Class c = Class.forName(className, false, jcl);

                                if (isImplementorOf(c, interfaceName))
                                    if(c.getSuperclass() != null)
                                        return c;

                            }
                            ze = jis.getNextEntry();
                        }
                    } catch(ClassNotFoundException cnfe) {
                        // We ignore this for now
                    } catch(NoClassDefFoundError cdnf) {
                        //continue to search other classes
                    } finally {
                        try {
                            if(jis != null)
                                jis.close();
                        } catch(Exception e) {}
                    }
                }
            }
        } catch(java.io.IOException ioe) {
            Verifier.debug(ioe);
        }
        return null;
    
protected booleanfindImplementorOf(com.sun.enterprise.deployment.ConnectorDescriptor desc, java.lang.String interfaceName, com.sun.enterprise.tools.verifier.Result result)

Look for an implementation of an interface in all the classes present in a jar file, setting the result object with the look up result

param
interfaceName interface to look for an implementor
param
result where to put the look up result

        Class c = findImplementorOf(desc, interfaceName);
        if (c != null) {
	    result.passed(smh.getLocalString
	        ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.findImplementor.passed", 
                "The class [ {0} ] implements the [ {1} ] interface",
                new Object[] {c.getName(), interfaceName}));    
            return true;
        } else {
	    result.failed(smh.getLocalString
	        ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.findImplementor.failed", 
                "Error: There is no implementation of the [ {0} ] provided",
                new Object[] {interfaceName}));        
            return false;
        }
    
protected java.lang.StringgetAbstractArchiveUri(com.sun.enterprise.deployment.ConnectorDescriptor desc)

        String archBase = getVerifierContext().getAbstractArchive().
                getArchiveUri();
        final ModuleDescriptor moduleDescriptor = desc.getModuleDescriptor();
        if (moduleDescriptor.isStandalone()) {
            return archBase; // it must be a stand-alone module; no such physical dir exists
        } else {
            return archBase + File.separator +
                    FileUtils.makeFriendlyFileName(moduleDescriptor.getArchiveUri());
        }
    
protected booleanisClassLoadable(java.lang.String className, com.sun.enterprise.tools.verifier.Result result)

Check if a class or interface can be loaded from the archive file

param
className the class or interface name
param
result instance for test status
return
true if the class or interface can be loaded

        ClassLoader jcl = getVerifierContext().getClassLoader();
        try {
            Class.forName(className, false, jcl);
            result.passed(smh.getLocalString
                    ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.isClassLoadable.passed", 
                    "The class [ {0} ] is contained in the archive file",
                    new Object[] {className}));                
            return true;
        } catch(ClassNotFoundException cnfe) {
            result.failed(smh.getLocalString
                    ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.isClassLoadable.failed", 
                    "The class [ {0} ] is not contained in the archive file",
                    new Object[] {className}));                
            return true;
        }