FileDocCategorySizeDatePackage
WebTestsUtil.javaAPI DocGlassfish v2 API7186Fri May 04 22:34:12 BST 2007com.sun.enterprise.tools.verifier.tests.web

WebTestsUtil

public class WebTestsUtil extends Object implements VerifierEventsListener
Singleton Utility class to load war archive and get class loader
author
Jerome Dochez
author
Sheetal Vartak
version
1.0

Fields Summary
protected final String
listenerClassPath
protected final String
libraryClassPath
private final String
separator
private static File
warFile
private static WebTestsUtil
util
private static ClassLoader
cl
Constructors Summary
Methods Summary
public voidallTestsFinished(java.util.EventObject e)

Notification that all tests pertinent to a verifier check manager have been completed

param
e event object which source is the check manager for the completed tests

        // remove tmp files
        if ((warFile != null) && (warFile.exists())) {
            deleteDirectory(warFile.getAbsolutePath());
        }
        warFile=null;
        util=null;
        cl=null;
        WebCheckMgrImpl.removeVerifierEventsListener(this);        
    
public voidappendCLWithWebInfContents()
method that appends the class loader's class path


	try {
	    File warclasses = new File(warFile, listenerClassPath);
	    File libraries = new File(warFile, libraryClassPath);
	    Vector<File> v = new Vector<File>();
	    if (libraries.exists()) {
		File[] libs = libraries.listFiles();
		for (int i=0;i<libs.length;i++) {
		    if (libs[i].getName().endsWith(".jar")) {
			v.add(libs[i]);
		    }
		}
	    }
	    URL[] repositories = new URL[v.size() + 1];
	    try {
		repositories[0] = warclasses.toURI().toURL();
		for (int i = 1;i <= v.size(); i++) {
		    repositories[i] = ((File) v.elementAt(i-1)).toURI().toURL();
		}
	    }catch(MalformedURLException ex) {
		throw ex;
	    }
	    
	    for (int i = 0; i < repositories.length; i++) {
		((JarClassLoader)cl).appendURL(repositories[i]);
	    }
	}catch (Exception e) {
	    throw e;
	}
    
private voiddeleteDirectory(java.lang.String oneDir)

        
        File[] listOfFiles;
        File cleanDir;

        cleanDir = new File(oneDir);
        if (!cleanDir.exists())  // Nothing to do.  Return; 
            return;

        listOfFiles = cleanDir.listFiles();
        if(listOfFiles != null) {       
            for(int countFiles = 0; countFiles < listOfFiles.length; countFiles++) {                    
                if (listOfFiles[countFiles].isFile()) {
                    listOfFiles[countFiles].delete();
                } else { // It is a directory
                    String nextCleanDir =  cleanDir + separator + listOfFiles[countFiles].getName();
                    File newCleanDir = new File(nextCleanDir);
                    deleteDirectory(newCleanDir.getAbsolutePath());
                }                    
            }// End for loop
        } // End if statement            
 
        cleanDir.delete();
    
public java.io.FileextractJarFile(java.io.File warFilePath)

Extract if necessary the war file and return the path to the extracted archive file

param
warFilePath is the path for the warfile to extract
return
the file identifier for the extracted directory

        
        //if (!warFile.exists())
	try {
	    warFile = new File(System.getProperty("java.io.tmpdir"), "listenertmp");   
            if (!warFile.exists()) {
                warFile.mkdirs();
            }
	    VerifierUtils.copyArchiveToDir(warFilePath, warFile); 
	    return warFile;
	}catch (Exception e) {
	    throw new IOException (e.getMessage());
	}
    
private java.lang.ClassLoadergetClassLoader()

	return cl;
    
public static com.sun.enterprise.tools.verifier.tests.web.WebTestsUtilgetUtil(java.lang.ClassLoader cLoader)

Get the unique instance for this class

 
    
    
                   
         
    
        if (util==null) {
	    util = new WebTestsUtil();
	    WebCheckMgrImpl.addVerifierEventsListener(util);
	    cl = cLoader;
        }    
        return util;
    
public java.lang.ClassloadClass(java.lang.String className)

load a class from the war archive file

param
className the class to load
return
the class object if it can be loaded


        if ((warFile==null || !warFile.exists()) 
            && (getClassLoader() == null)) {
            throw new ClassNotFoundException();
        }
	    Class c = getClassLoader().loadClass(className);
	    return c;
    
public voidtestFinished(java.util.EventObject e)

Individual test completion notification event

param
e event object which source is the result of the individual test

        // do nothing, we don't care