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

CheckMgr

public abstract class CheckMgr extends Object

Fields Summary
static Vector
listenerList
protected FrameworkContext
frameworkContext
protected final boolean
debug
protected Context
context
private static final String
excludeListFileName
private Logger
logger
protected boolean
isDDPresent
private Vector
test
Constructors Summary
Methods Summary
public static voidaddVerifierEventsListener(VerifierEventsListener l)
support notification of test completion with a ChangeEvent the ChangeEvent source is the corresponding Result object

param
l change listener

        listenerList.add(l);
    
protected voidcheck(Descriptor descriptor)

Entry point for executing all tests pertinent to this architecture

param
descriptor ConnectorDescritor the deployment descriptor


                           
          
        logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.CheckMgr.check",
                new Object[]{getClass().getName(), descriptor.getName()});

        setRuntimeDDPresent(getAbstractArchiveUri(descriptor));

        // Load the list of tests from the property file for this manager
        loadTestInformationFromPropsFile();

        // These temporary placeholder will keep the results of the tests

        logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.CheckMgr.RunAllTests",
                new Object[]{descriptor.getName()});
        String schemaVersion = getSchemaVersion(descriptor);
        context.setSchemaVersion(schemaVersion);
        context.setJavaEEVersion(frameworkContext.getJavaEEVersion());
        context.setComponentNameConstructor(getComponentNameConstructor(descriptor));
        FileArchive moduleArchive = new FileArchive();
        moduleArchive.open(getAbstractArchiveUri(descriptor));
        context.setModuleArchive(moduleArchive);
        ResultManager resultManager = frameworkContext.getResultManager();
        for (int i = 0; i < test.size(); i++) {
            TestInformation ti = (TestInformation) test.elementAt(i);
            String minVersion = ti.getMinimumVersion();
            String maxVersion = ti.getMaximumVersion();
            // does this test apply to the schema version implemented by
            // this component's descriptor
            if (schemaVersion != null && minVersion != null &&
                    schemaVersion.compareTo(minVersion) < 0) {
                logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.CheckMgr.version.NOT_APPLICABLE",
                        new Object[]{ti.getClassName()});
                continue;
            }
            if (schemaVersion != null && maxVersion != null &&
                    schemaVersion.compareTo(maxVersion) > 0) {
                logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.CheckMgr.version.NOT_APPLICABLE",
                        new Object[]{ti.getClassName()});
                continue;
            }
            if(!isApplicable(ti, descriptor)) {
                logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.CheckMgr.version.NOT_APPLICABLE",
                        new Object[]{ti.getClassName()});
                continue;
            }
            try {
                Class c = Class.forName(ti.getClassName());
                VerifierCheck t = (VerifierCheck) c.newInstance();
                t.setVerifierContext(context);
                Result r = t.check(descriptor);
                // no need to setComponentName as it is already set in
                // VerifierTest.getInitialisedResult(). By Sahoo
                // r.setComponentName(getArchiveUri(descriptor));
                setModuleName(r);
                resultManager.add(r);
                // notify listeners of test completion
                fireTestFinishedEvent(r);
            } catch (Throwable e) {
                LogRecord logRecord = new LogRecord(Level.SEVERE,
                        ti.getClassName());
                logRecord.setThrown(e);
                resultManager.log(logRecord);
            }
        }

        fireAllTestsFinishedEvent();
        // done adding it to hastable vector.
    
protected voidcheckPersistenceUnits(RootDeploymentDescriptor descriptor)

        if (frameworkContext.isPartition() &&
                !frameworkContext.isPersistenceUnits())
            return;
        CheckMgr puCheckMgr = new PersistenceUnitCheckMgrImpl(
                frameworkContext, context);
        for(PersistenceUnitsDescriptor pus :
                descriptor.getPersistenceUnitsDescriptors()) {
            for (PersistenceUnitDescriptor pu :
                    pus.getPersistenceUnitDescriptors()) {
                puCheckMgr.check(pu);
            }
        }
    
protected voidcheckWebServices(Descriptor descriptor)

        if (frameworkContext.isPartition() &&
                !frameworkContext.isWebServices())
            return;
        BundleDescriptor bundleDescriptor = (BundleDescriptor) descriptor;
        WebServiceCheckMgrImpl webServiceCheckMgr = new WebServiceCheckMgrImpl(
                frameworkContext);
        if (bundleDescriptor.hasWebServices()) {
            WebServicesDescriptor wdesc = bundleDescriptor.getWebServices();
            webServiceCheckMgr.setVerifierContext(context);
            webServiceCheckMgr.check(wdesc);
        }
    
protected voidfireAllTestsFinishedEvent()


        Object[] listeners;
        synchronized (listenerList) {
            listeners = listenerList.toArray();
        }
        if (listeners == null)
            return;

        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = 0; i < listeners.length; i++) {
            if (listeners[i] instanceof VerifierEventsListener) {
                //  create the event:
                EventObject event = new EventObject(this);
                ((VerifierEventsListener) listeners[i]).allTestsFinished(event);
            }
        }
    
protected voidfireTestFinishedEvent(Result r)


        Object[] listeners;
        synchronized (listenerList) {
            listeners = listenerList.toArray();
        }
        if (listeners == null)
            return;

        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = 0; i < listeners.length; i++) {
            if (listeners[i] instanceof VerifierEventsListener) {
                //  create the event:
                EventObject event = new EventObject(r);
                ((VerifierEventsListener) listeners[i]).testFinished(event);
            }
        }
    
protected java.lang.StringgetAbstractArchiveUri(Descriptor descriptor)

        String archBase = context.getAbstractArchive().getArchiveUri();
        if (descriptor instanceof Application)
            return archBase;
        ModuleDescriptor mdesc = getBundleDescriptor(descriptor).getModuleDescriptor();
        if(mdesc.isStandalone()) {
            return archBase;
        } else {
            return archBase + File.separator +
                    FileUtils.makeFriendlyFileName(mdesc.getArchiveUri());
        }
    
protected java.lang.StringgetArchiveUri(Descriptor descriptor)

        String archiveUri = getBundleDescriptor(descriptor).getModuleDescriptor().getArchiveUri();
        return new File(archiveUri).getName();
    
protected BundleDescriptorgetBundleDescriptor(Descriptor descriptor)
EjbCheckMgrImpl, WebServiceClientCheckMgrImpl and WebServiceCheckMgrImpl classes override this method. For each of these areas the tests are run on descriptors rather than bundle descriptors.

        return (BundleDescriptor) descriptor;
    
protected abstract com.sun.enterprise.tools.verifier.tests.ComponentNameConstructorgetComponentNameConstructor(Descriptor descriptor)

protected java.util.VectorgetFinalTestList(java.util.Vector orignalList, java.util.Vector excludeList)

param
orignalList
param
excludeList
return
vector successful completion of getting exclude list

        if (excludeList == null) return orignalList;
        if (orignalList.size() != 0 && excludeList.size() != 0) {
            for (int i = 0; i < excludeList.size(); i++) {
                for (int j = 0; j < orignalList.size(); j++) {
                    if (((TestInformation) orignalList.elementAt(j)).getClassName()
                            .equals(
                                    ((TestInformation) excludeList.elementAt(i)).getClassName())) {
                        orignalList.remove(j);
                    }
                }
            }
        }
        return orignalList;
    
private booleangetRuntimeDDPresent()

        return isDDPresent;
    
protected abstract java.lang.StringgetSchemaVersion(Descriptor descriptor)

protected abstract java.lang.StringgetSunONETestsListFileName()
Adding a new function to get the SunONE AS test lists for Ejb tests

protected static java.lang.StringgetSunPrefix()

        return "sun-"; // NOI18N
    
protected java.util.VectorgetTestFromExcludeList()

return
boolean successful completion of getting exclude list

        Vector<TestInformation> testExcluded = new Vector<TestInformation>();
        logger.log(Level.FINE,
                "com.sun.enterprise.tools.verifier.CheckMgr.TestnamesPropsFile"); // NOI18N
        // parse the xml file
        File inputFile = getTestsFileFor(excludeListFileName);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();

        Document doc = builder.parse(inputFile);
        NodeList list = doc.getElementsByTagName("test"); // NOI18N
        for (int i = 0; i < list.getLength(); i++) {
            Element e = (Element) list.item(i);
            NodeList nl = e.getChildNodes();
            TestInformation ti = new TestInformation();
            for (int j = 0; j < nl.getLength(); j++) {
                String nodeName = nl.item(j).getNodeName();
                if ("test-class".equals(nodeName.trim())) { // NOI18N
                    Node el = nl.item(j);
                    ti.setClassName(el.getFirstChild().getNodeValue().trim());
                }
            }
            testExcluded.addElement(ti);
        }
        return testExcluded;
    
private java.io.FilegetTestsFileFor(java.lang.String filename)
Retrieve Web tests from TestNamesWeb.conf file

param
filename file listing all web tests to run
return
File File handle for tests to run

        // in case of appserver the config file will be <AS>/lib/verifier and
        // for AVK it will be <AVK>/config/verifier.
        // Put checks if this directory is null.
        File f = new File(frameworkContext.getConfigDirStr());
        f = new File(f, filename);
        return new File(f.toString());
    
protected abstract java.lang.StringgetTestsListFileName()

return
String the file name containing the list of tests to be performed by this manager on each archive file

protected booleanisApplicable(TestInformation test, Descriptor descriptor)
This method is overridden in EjbCheckMgrImpl. This method is used to ensure that entity and mdb tests are not run for session descriptors and similarly the other way round.

        return true;
    
private voidloadTestInformationFromPropsFile()

load all the test names from the property file. Each manager has its list of test to be performed for each archive in a property file. The tests list of a list of class name implementing a particular test


        if(!test.isEmpty())
            return;
        logger.log(Level.FINE,
                "com.sun.enterprise.tools.verifier.CheckMgr.TestnamesPropsFile"); // NOI18N

        File inputFile = getTestsFileFor(getTestsListFileName());

        // parse the xml file
        DocumentBuilder db = DocumentBuilderFactory.newInstance()
                .newDocumentBuilder();
        Document doc = db.parse(inputFile);
        NodeList list = doc.getElementsByTagName("test"); // NOI18N
        for (int i = 0; i < list.getLength(); i++) {
            Element e = (Element) list.item(i);
            NodeList nl = e.getChildNodes();
            TestInformation ti = new TestInformation();
            for (int j = 0; j < nl.getLength(); j++) {
                String nodeName = nl.item(j).getNodeName();
                if ("test-class".equals(nodeName.trim())) { // NOI18N
                    Node el = nl.item(j);
                    ti.setClassName(el.getFirstChild().getNodeValue().trim());
                }
                if ("minimum-version".equals(nodeName.trim())) { // NOI18N
                    Node el = nl.item(j);
                    ti.setMinimumVersion(
                            el.getFirstChild().getNodeValue().trim());
                }
                if ("maximum-version".equals(nodeName.trim())) { // NOI18N
                    Node el = nl.item(j);
                    ti.setMaximumVersion(
                            el.getFirstChild().getNodeValue().trim());
                }
            }
            test.addElement(ti);
        }

        if ((!frameworkContext.isPortabilityMode() && 
                getRuntimeDDPresent()))
            readSunONETests(test);
        // to get the list of tests to be excluded
        Vector<TestInformation> testExcluded = getTestFromExcludeList();
        // to exclude the tests
        test = getFinalTestList(test, testExcluded);
    
private voidreadSunONETests(java.util.Vector test)

        String sunonetests = getSunONETestsListFileName();
        if (sunonetests == null)
            return;
        File inputFile = getTestsFileFor(sunonetests);
        if (!inputFile.exists())
            return;
        DocumentBuilder db = DocumentBuilderFactory.newInstance()
                .newDocumentBuilder();
        Document doc = db.parse(inputFile);
        NodeList list = doc.getElementsByTagName("test"); // NOI18N
        for (int i = 0; i < list.getLength(); i++) {
            Element e = (Element) list.item(i);
            NodeList nl = e.getChildNodes();
            TestInformation ti = new TestInformation();
            for (int j = 0; j < nl.getLength(); j++) {
                String nodeName = nl.item(j).getNodeName();
                if ("test-class".equals(nodeName.trim())) { // NOI18N
                    Node el = nl.item(j);
                    ti.setClassName(el.getFirstChild().getNodeValue().trim());
                }
                if ("minimum-version".equals(nodeName.trim())) { // NOI18N
                    Node el = nl.item(j);
                    ti.setMinimumVersion(
                            el.getFirstChild().getNodeValue().trim());
                }
                if ("maximum-version".equals(nodeName.trim())) { // NOI18N
                    Node el = nl.item(j);
                    ti.setMaximumVersion(
                            el.getFirstChild().getNodeValue().trim());
                }
            }
            test.addElement(ti);
        }
    
public static voidremoveVerifierEventsListener(VerifierEventsListener l)
Remove change listener

param
l change listener

        listenerList.remove(l);
    
protected abstract voidsetModuleName(Result r)

protected voidsetRuntimeDDPresent(java.lang.String uri)

        InputStream is = null;
        try {
            AbstractArchive abstractArchive = new FileArchiveFactory().openArchive(
                    uri);
            Archivist archivist = ArchivistFactory.getArchivistForArchive(
                    abstractArchive);
            if(archivist != null) {
                String ddFileEntryName = archivist.getRuntimeDeploymentDescriptorPath();
                is = abstractArchive.getEntry(ddFileEntryName);
                if (is != null) {
                    isDDPresent = true;
                }
            }

        } catch (IOException e) {
            isDDPresent = false;
        } finally {
            try {
                if(is != null)
                    is.close();
            } catch (Exception e) {
                // nothing to do here
            }
        }
    
public voidsetVerifierContext(Context context)
This method sets the Context object

        this.context = context;