FileDocCategorySizeDatePackage
BaseVerifier.javaAPI DocGlassfish v2 API8884Fri May 04 22:33:24 BST 2007com.sun.enterprise.tools.verifier

BaseVerifier

public abstract class BaseVerifier extends Object
The base class of all the verifiers. It has all the common logic required in the verification process.
author
Vikas Awasthi

Fields Summary
protected Logger
logger
protected FrameworkContext
frameworkContext
protected Context
context
Constructors Summary
Methods Summary
protected booleanareTestsNotRequired(boolean isModuleGivenInPartiotioningArgs)

        return (frameworkContext.isPartition() &&
                !isModuleGivenInPartiotioningArgs);
    
protected abstract java.lang.ClassLoadercreateClassLoader()

protected voidcreateDOMObject(org.xml.sax.InputSource source, java.lang.String dd)

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        EntityResolver dh = new XMLValidationHandler(false);
        builder.setEntityResolver(dh);
        Document document = builder.parse(source);

        if ((dd.indexOf("sun-")) < 0) { // NOI18N
            if ((dd.indexOf("webservices")) < 0) { // NOI18N
                context.setDocument(document);
            } else {
                context.setWebServiceDocument(document);
            }
        } else
            context.setRuntimeDocument(document);
    
protected voidcreateDocumentObject(com.sun.enterprise.deployment.Descriptor descriptor)


         

       

       
             

       

         

       
                
        InputStream is = null;
        InputSource source = null;

        String archBase = context.getAbstractArchive().getArchiveUri();
        String uri = null;
        if(descriptor instanceof Application) {
            uri = archBase;
        } else {
            BundleDescriptor bundleDesc =
                BundleDescriptor.class.cast(descriptor);
            if(bundleDesc.getModuleDescriptor().isStandalone()) {
                uri = archBase;
            } else {
                uri = archBase + File.separator + getArchiveUri();
            }
        }
        String dd[] = getDDString();
        for (int i = 0; i < dd.length; i++) {
            try{
                is = getInputStreamFromAbstractArchive(uri, dd[i]);
                if (is != null) {
                    source = new InputSource(is);
                    createDOMObject(source, dd[i]);
                    is.close();
                }
            } finally {
                try {
                    if(is != null) {
                        is.close();
                    }
                } catch(Exception e) {}
            }
        }
    
private java.util.ListgetAllJars(java.io.File file)

param
file
return
returns a list of jars in the a directory
throws
IOException

        List<String> list = new ArrayList<String>();
        if (file.isDirectory() || file.canRead()) {
            File[] files = file.listFiles();
            for (int i=0; i<files.length; i++) {
                File jar = files[i];
                if ( FileUtils.isJar(jar)) {
                    list.add( jar.getCanonicalPath() );
                }
            }
        }
        return list;
    
protected abstract java.lang.StringgetArchiveUri()

protected java.lang.StringgetClassPath(java.util.List classPath)
converts list of paths to a string of paths separated by pathSeparator

        StringBuilder cp = new StringBuilder("");
        for (int i = 0; i < classPath.size(); i++) {
            cp.append(classPath.get(i));
            cp.append(File.pathSeparator);
        }
        return cp.toString();
    
protected abstract java.lang.StringgetClassPath()

protected abstract java.lang.String[]getDDString()

public abstract com.sun.enterprise.deployment.DescriptorgetDescriptor()

protected java.io.InputStreamgetInputStreamFromAbstractArchive(java.lang.String uri, java.lang.String ddName)

        FileArchive arch = new FileArchive();
        arch.open(uri);
        InputStream deploymentEntry = arch.getEntry(ddName);
        return deploymentEntry;
    
protected java.lang.StringgetLibdirClasspath(java.lang.String appRoot, java.lang.String libdirPath)

param
appRoot The location of the exploded archive
param
libdirPath library-directory location as specified in aplication.xml
return
Classpath string containing list of jar files in the library directory separated by File.separator char
throws
IOException

        StringBuilder classpath=new StringBuilder();
        libdirPath = libdirPath.replace('/", File.separatorChar);
        List<String> jars = getAllJars(new File(appRoot, libdirPath));
        for (String s : jars) {
            classpath.append(s);
            classpath.append(File.pathSeparator);
        }
        return classpath.toString();
    
protected voidpreVerification()

        logger.log(Level.INFO, "Verifying: [ " + getArchiveUri() + " ]");
        ClassLoader loader = createClassLoader();
        context = new Context(loader);
        context.setAppserverMode(!frameworkContext.isPortabilityMode());
        context.setAbstractArchive(frameworkContext.getAbstractArchive());
        context.setClassPath(getClassPath());
        logger.log(Level.FINE, "Using CLASSPATH: " + getClassPath());
    
public abstract voidverify()

protected voidverify(com.sun.enterprise.deployment.Descriptor descriptor, CheckMgr checkMgrImpl)

        //hs for creating DOM object for runtime tests
        createDocumentObject(descriptor);
        // now start calling each individual test, as per spec
        checkMgrImpl.setVerifierContext(context);
        checkMgrImpl.check(descriptor);
        logger.log(Level.FINE,
                getClass().getName() + ".debug.endStaticVerification"); // NOI18N