FileDocCategorySizeDatePackage
ManifestResource.javaAPI DocApache Tomcat 6.0.148373Fri Jul 20 04:20:32 BST 2007org.apache.catalina.util

ManifestResource

public class ManifestResource extends Object
Representation of a Manifest file and its available extensions and required extensions
author
Greg Murray
author
Justyna Horwat
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

Fields Summary
public static final int
SYSTEM
public static final int
WAR
public static final int
APPLICATION
private ArrayList
availableExtensions
private ArrayList
requiredExtensions
private String
resourceName
private int
resourceType
Constructors Summary
public ManifestResource(String resourceName, Manifest manifest, int resourceType)

        
         
                              
        this.resourceName = resourceName;
        this.resourceType = resourceType;
        processManifest(manifest);
    
Methods Summary
public intgetAvailableExtensionCount()
Gets the number of available extensions

return
The number of available extensions

        return (availableExtensions != null) ? availableExtensions.size() : 0;
    
private java.util.ArrayListgetAvailableExtensions(java.util.jar.Manifest manifest)
Return the set of Extension objects representing optional packages that are bundled with the application associated with the specified Manifest.

param
manifest Manifest to be parsed
return
List of available extensions, or null if the web application does not bundle any extensions


        Attributes attributes = manifest.getMainAttributes();
        String name = attributes.getValue("Extension-Name");
        if (name == null)
            return null;

        ArrayList extensionList = new ArrayList();

        Extension extension = new Extension();
        extension.setExtensionName(name);
        extension.setImplementationURL(
            attributes.getValue("Implementation-URL"));
        extension.setImplementationVendor(
            attributes.getValue("Implementation-Vendor"));
        extension.setImplementationVendorId(
            attributes.getValue("Implementation-Vendor-Id"));
        extension.setImplementationVersion(
            attributes.getValue("Implementation-Version"));
        extension.setSpecificationVersion(
            attributes.getValue("Specification-Version"));

        extensionList.add(extension);

        return extensionList;
    
public java.util.ArrayListgetAvailableExtensions()
Gets the list of available extensions

return
List of available extensions

        return availableExtensions;
    
public intgetRequiredExtensionCount()
Gets the number of required extensions

return
The number of required extensions

        return (requiredExtensions != null) ? requiredExtensions.size() : 0;
    
private java.util.ArrayListgetRequiredExtensions(java.util.jar.Manifest manifest)
Return the set of Extension objects representing optional packages that are required by the application associated with the specified Manifest.

param
manifest Manifest to be parsed
return
List of required extensions, or null if the application does not require any extensions


        Attributes attributes = manifest.getMainAttributes();
        String names = attributes.getValue("Extension-List");
        if (names == null)
            return null;

        ArrayList extensionList = new ArrayList();
        names += " ";

        while (true) {

            int space = names.indexOf(' ");
            if (space < 0)
                break;
            String name = names.substring(0, space).trim();
            names = names.substring(space + 1);

            String value =
                attributes.getValue(name + "-Extension-Name");
            if (value == null)
                continue;
            Extension extension = new Extension();
            extension.setExtensionName(value);
            extension.setImplementationURL
                (attributes.getValue(name + "-Implementation-URL"));
            extension.setImplementationVendorId
                (attributes.getValue(name + "-Implementation-Vendor-Id"));
            String version = attributes.getValue(name + "-Implementation-Version");
            extension.setImplementationVersion(version);
            extension.setSpecificationVersion
                (attributes.getValue(name + "-Specification-Version"));
            extensionList.add(extension);
        }
        return extensionList;
    
public java.util.ArrayListgetRequiredExtensions()
Gets the list of required extensions

return
List of required extensions

        return requiredExtensions;   
    
public java.lang.StringgetResourceName()
Gets the name of the resource

return
The name of the resource

        return resourceName;
    
public booleanisFulfilled()
Returns true if all required extension dependencies have been meet for this ManifestResource object.

return
boolean true if all extension dependencies have been satisfied

        if (requiredExtensions == null) {
            return false;
        }
        Iterator it = requiredExtensions.iterator();
        while (it.hasNext()) {
            Extension ext = (Extension)it.next();
            if (!ext.isFulfilled()) return false;            
        }
        return true;
    
private voidprocessManifest(java.util.jar.Manifest manifest)

        availableExtensions = getAvailableExtensions(manifest);
        requiredExtensions = getRequiredExtensions(manifest);
    
public booleanrequiresExtensions()
Convienience method to check if this ManifestResource has an requires extensions.

return
true if required extensions are present

        return (requiredExtensions != null) ? true : false;
    
public java.lang.StringtoString()


        StringBuffer sb = new StringBuffer("ManifestResource[");
        sb.append(resourceName);

        sb.append(", isFulfilled=");
        sb.append(isFulfilled() +"");
        sb.append(", requiredExtensionCount =");
        sb.append(getRequiredExtensionCount());
        sb.append(", availableExtensionCount=");
        sb.append(getAvailableExtensionCount());
        switch (resourceType) {
            case SYSTEM : sb.append(", resourceType=SYSTEM"); break;
            case WAR : sb.append(", resourceType=WAR"); break;
            case APPLICATION : sb.append(", resourceType=APPLICATION"); break;
        }
        sb.append("]");
        return (sb.toString());