FileDocCategorySizeDatePackage
IconImageTypeTest.javaAPI DocGlassfish v2 API9355Fri May 04 22:33:26 BST 2007com.sun.enterprise.tools.verifier.tests

IconImageTypeTest

public class IconImageTypeTest extends VerifierTest implements VerifierCheck
This test is deried from Java EE platform spec. See javaee_5.xsd
author
Sanjeeb.Sahoo@Sun.COM

Fields Summary
private Collection
smallIconUris
private Collection
largeIconUris
private Descriptor
descriptor
private com.sun.enterprise.tools.verifier.Result
result
ComponentNameConstructor
compName
private static final String[]
allowableImageTypesForJavaEEOlderThan5
private static final String[]
allowableImageTypesForJavaEE5
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(Descriptor descriptor)

        
        this.descriptor = descriptor;
        compName = getVerifierContext().getComponentNameConstructor();
        result = getInitializedResult();
        result.setStatus(Result.PASSED);
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString
                      (getClass().getName() + ".passed", //NOI18N
                       "No errors were detected.")); // NOI18N

        // Now collect all the Icon URIs that we are going to test
        collectIconURIs();
        testIconURIType();
        testIconURIExistence();
        return result;
    
private voidcollectIconURIs()

        // in the absence of a proper Visitor pattern I am left with
        // little option but to use instanceof
        if(descriptor instanceof Application)
            collectIconURIs((Application)descriptor);
        else if(descriptor instanceof ApplicationClientDescriptor)
            collectIconURIs((ApplicationClientDescriptor)descriptor);
        else if(descriptor instanceof EjbDescriptor)
            collectIconURIs((EjbDescriptor)descriptor);
        else if(descriptor instanceof ConnectorDescriptor)
            collectIconURIs((ConnectorDescriptor)descriptor);
        else if(descriptor instanceof WebBundleDescriptor)
            collectIconURIs((WebBundleDescriptor)descriptor);
        else if(descriptor instanceof WebServiceEndpoint)
            collectIconURIs((WebServiceEndpoint)descriptor);
        else if(descriptor instanceof ServiceReferenceDescriptor)
            collectIconURIs((ServiceReferenceDescriptor)descriptor);
        else {
            // every time we introduce a new CheckMgrImpl, this will fail
            // that way we can be notified of the fact that this method needs
            // to be modified as well.
            throw new RuntimeException("Unexpected descriptor type.");
        }
    
private voidcollectIconURIs(Descriptor desc)

        String uri=desc.getSmallIconUri();
        if(uri!=null && uri.length()>0) smallIconUris.add(uri);
        uri = desc.getLargeIconUri();
        if(uri!=null && uri.length()>0) largeIconUris.add(uri);
    
private voidcollectIconURIs(WebBundleDescriptor webBundleDescriptor)

        // this is for itself
        collectIconURIs((Descriptor)webBundleDescriptor);
        // now collect for each servlet
        for (Object o : webBundleDescriptor.getWebComponentDescriptorsSet()){
            collectIconURIs(WebComponentDescriptor.class.cast(o));
        }
        // now collect for each servlet filter
        for (Object o : webBundleDescriptor.getServletFilterDescriptors()) {
            collectIconURIs(ServletFilterDescriptor.class.cast(o));
        }
    
private voidcollectIconURIs(WebServiceEndpoint webServiceEndpoint)

        // WebService.xml is organised like this:
        // WebServicesDescriptor->WebService->WebServiceEndpoint
        // Since we don't have a CheckMgr that runs test for WebService.xml,
        // a work around would be to collect all Icons for all the parents
        // and test them here.
        // This means a problem there would be as many times as there are
        // end points.
        collectIconURIs(webServiceEndpoint.getWebService().getWebServicesDescriptor());
        collectIconURIs(webServiceEndpoint.getWebService());

        // this is for itself
        collectIconURIs((Descriptor)webServiceEndpoint);
        // now collect for each port-compont_handler in handler-chain
        for (Object o : webServiceEndpoint.getHandlers()){
            collectIconURIs(WebServiceHandler.class.cast(o));
        }
    
private voidcollectIconURIs(EjbDescriptor desc)

        // Since we don't have a CheckMgr that runs test for ejb-jar.xml,
        // a work around would be to collect all Icons for the parent
        // and test them here.
        // This means a problem there would be as many times as there are
        // beans.
        collectIconURIs(desc.getEjbBundleDescriptor());
        // this is for itself
        collectIconURIs((Descriptor)descriptor);
    
private voidtestIconURIExistence()

        Collection<String> allURIs = new ArrayList<String>(smallIconUris);
        allURIs.addAll(largeIconUris);
        for(String uri : allURIs){
            Archive moduleArchive = getVerifierContext().getModuleArchive();
            boolean passed = false;
            for(Enumeration entries = moduleArchive.entries(); entries.hasMoreElements();){
                if(uri.equals(entries.nextElement())) {
                    passed = true;
                    break;
                }
            }
            if(!passed){
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString
                        (getClass().getName() + ".failedExistence",
                                "Error: icon image URI [ {0} ] is not packaged inside [ {1} ].",
                                new Object[]{uri, getVerifierContext().getModuleArchive().getURI()}));
            }
        }
    
private voidtestIconURIType()

        String[] allowableImageTypes;
        String JavaEESchemaVersion = getVerifierContext().getJavaEEVersion();
        if (JavaEESchemaVersion.compareTo(SpecVersionMapper.JavaEEVersion_5) < 0){
            allowableImageTypes = allowableImageTypesForJavaEEOlderThan5;
        } else {
            allowableImageTypes = allowableImageTypesForJavaEE5;
        }

        Collection<String> allURIs = new ArrayList<String>(smallIconUris);
        allURIs.addAll(largeIconUris);
        for(String uri : allURIs){
            boolean passed = false;
            for(String allowableType : allowableImageTypes) {
                if(uri.endsWith(allowableType)) {
                    passed = true;
                    break;
                }
            }
            if(!passed){
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString
                        (getClass().getName() + ".failedImageType",
                                "Error: Unsupported image type used in icon image URI [ {0} ].",
                                new Object[]{uri}));
            }
        }