⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extension.java

📁 java ant的源码!非常值得看的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (null != implementationVersion) {            try {                this.implementationVersion                    = new DeweyDecimal(implementationVersion);            } catch (final NumberFormatException nfe) {                final String error = "Bad implementation version format '"                    + implementationVersion + "' in '" + extensionName                    + "'. (Reason: " + nfe + ")";                throw new IllegalArgumentException(error);            }        }        if (null == this.extensionName) {            throw new NullPointerException("extensionName property is null");        }    }    /**     * Get the name of the extension.     *     * @return the name of the extension     */    public String getExtensionName() {        return extensionName;    }    /**     * Get the vendor of the extensions specification.     *     * @return the vendor of the extensions specification.     */    public String getSpecificationVendor() {        return specificationVendor;    }    /**     * Get the version of the extensions specification.     *     * @return the version of the extensions specification.     */    public DeweyDecimal getSpecificationVersion() {        return specificationVersion;    }    /**     * Get the url of the extensions implementation.     *     * @return the url of the extensions implementation.     */    public String getImplementationURL() {        return implementationURL;    }    /**     * Get the vendor of the extensions implementation.     *     * @return the vendor of the extensions implementation.     */    public String getImplementationVendor() {        return implementationVendor;    }    /**     * Get the vendorID of the extensions implementation.     *     * @return the vendorID of the extensions implementation.     */    public String getImplementationVendorID() {        return implementationVendorID;    }    /**     * Get the version of the extensions implementation.     *     * @return the version of the extensions implementation.     */    public DeweyDecimal getImplementationVersion() {        return implementationVersion;    }    /**     * Return a Compatibility enum indicating the relationship of this     * <code>Extension</code> with the specified <code>Extension</code>.     *     * @param required Description of the required optional package     * @return the enum indicating the compatibility (or lack thereof)     *         of specifed extension     */    public Compatibility getCompatibilityWith(final Extension required) {        // Extension Name must match        if (!extensionName.equals(required.getExtensionName())) {            return INCOMPATIBLE;        }        // Available specification version must be >= required        final DeweyDecimal requiredSpecificationVersion            = required.getSpecificationVersion();        if (null != requiredSpecificationVersion) {            if (null == specificationVersion                || !isCompatible(specificationVersion, requiredSpecificationVersion)) {                return REQUIRE_SPECIFICATION_UPGRADE;            }        }        // Implementation Vendor ID must match        final String requiredImplementationVendorID            = required.getImplementationVendorID();        if (null != requiredImplementationVendorID) {            if (null == implementationVendorID                || !implementationVendorID.equals(requiredImplementationVendorID)) {                return REQUIRE_VENDOR_SWITCH;            }        }        // Implementation version must be >= required        final DeweyDecimal requiredImplementationVersion            = required.getImplementationVersion();        if (null != requiredImplementationVersion) {            if (null == implementationVersion                || !isCompatible(implementationVersion, requiredImplementationVersion)) {                return REQUIRE_IMPLEMENTATION_UPGRADE;            }        }        // This available optional package satisfies the requirements        return COMPATIBLE;    }    /**     * Return <code>true</code> if the specified <code>Extension</code>     * (which represents an optional package required by an application)     * is satisfied by this <code>Extension</code> (which represents an     * optional package that is already installed.  Otherwise, return     * <code>false</code>.     *     * @param required Description of the required optional package     * @return true if the specified extension is compatible with this extension     */    public boolean isCompatibleWith(final Extension required) {        return (COMPATIBLE == getCompatibilityWith(required));    }    /**     * Return a String representation of this object.     *     * @return string representation of object.     */    public String toString() {        final String brace = ": ";        final StringBuffer sb = new StringBuffer(EXTENSION_NAME.toString());        sb.append(brace);        sb.append(extensionName);        sb.append(StringUtils.LINE_SEP);        if (null != specificationVersion) {            sb.append(SPECIFICATION_VERSION);            sb.append(brace);            sb.append(specificationVersion);            sb.append(StringUtils.LINE_SEP);        }        if (null != specificationVendor) {            sb.append(SPECIFICATION_VENDOR);            sb.append(brace);            sb.append(specificationVendor);            sb.append(StringUtils.LINE_SEP);        }        if (null != implementationVersion) {            sb.append(IMPLEMENTATION_VERSION);            sb.append(brace);            sb.append(implementationVersion);            sb.append(StringUtils.LINE_SEP);        }        if (null != implementationVendorID) {            sb.append(IMPLEMENTATION_VENDOR_ID);            sb.append(brace);            sb.append(implementationVendorID);            sb.append(StringUtils.LINE_SEP);        }        if (null != implementationVendor) {            sb.append(IMPLEMENTATION_VENDOR);            sb.append(brace);            sb.append(implementationVendor);            sb.append(StringUtils.LINE_SEP);        }        if (null != implementationURL) {            sb.append(IMPLEMENTATION_URL);            sb.append(brace);            sb.append(implementationURL);            sb.append(StringUtils.LINE_SEP);        }        return sb.toString();    }    /**     * Return <code>true</code> if the first version number is greater than     * or equal to the second; otherwise return <code>false</code>.     *     * @param first First version number (dotted decimal)     * @param second Second version number (dotted decimal)     */    private boolean isCompatible(final DeweyDecimal first,                                 final DeweyDecimal second) {        return first.isGreaterThanOrEqual(second);    }    /**     * Retrieve all the extensions listed under a particular key     * (Usually EXTENSION_LIST or OPTIONAL_EXTENSION_LIST).     *     * @param manifest the manifest to extract extensions from     * @param listKey the key used to get list (Usually     *        EXTENSION_LIST or OPTIONAL_EXTENSION_LIST)     * @return the list of listed extensions     */    private static Extension[] getListed(final Manifest manifest,                                          final Attributes.Name listKey) {        final ArrayList results = new ArrayList();        final Attributes mainAttributes = manifest.getMainAttributes();        if (null != mainAttributes) {            getExtension(mainAttributes, results, listKey);        }        final Map entries = manifest.getEntries();        final Iterator keys = entries.keySet().iterator();        while (keys.hasNext()) {            final String key = (String) keys.next();            final Attributes attributes = (Attributes) entries.get(key);            getExtension(attributes, results, listKey);        }        return (Extension[]) results.toArray(new Extension[results.size()]);    }    /**     * Add required optional packages defined in the specified     * attributes entry, if any.     *     * @param attributes Attributes to be parsed     * @param required list to add required optional packages to     * @param listKey the key to use to lookup list, usually EXTENSION_LIST     *    or OPTIONAL_EXTENSION_LIST     */    private static void getExtension(final Attributes attributes,                                     final ArrayList required,                                     final Attributes.Name listKey) {        final String names = attributes.getValue(listKey);        if (null == names) {            return;        }        final String[] extentions = split(names, " ");        for (int i = 0; i < extentions.length; i++) {            final String prefix = extentions[ i ] + "-";            final Extension extension = getExtension(prefix, attributes);            if (null != extension) {                required.add(extension);            }        }    }    /**     * Splits the string on every token into an array of strings.     *     * @param string the string     * @param onToken the token     * @return the resultant array     */    private static String[] split(final String string,                                        final String onToken) {        final StringTokenizer tokenizer = new StringTokenizer(string, onToken);        final String[] result = new String[ tokenizer.countTokens() ];        for (int i = 0; i < result.length; i++) {            result[ i ] = tokenizer.nextToken();        }        return result;    }    /**     * Extract an Extension from Attributes.     * Prefix indicates the prefix checked for each string.     * Usually the prefix is <em>"&lt;extension&gt;-"</em> if looking for a     * <b>Required</b> extension. If you are looking for an     * <b>Available</b> extension     * then the prefix is <em>""</em>.     *     * @param prefix the prefix for each attribute name     * @param attributes Attributes to searched     * @return the new Extension object, or null     */    private static Extension getExtension(final String prefix,                                          final Attributes attributes) {        //WARNING: We trim the values of all the attributes because        //Some extension declarations are badly defined (ie have spaces        //after version or vendorID)        final String nameKey = prefix + EXTENSION_NAME;        final String name = getTrimmedString(attributes.getValue(nameKey));        if (null == name) {            return null;        }        final String specVendorKey = prefix + SPECIFICATION_VENDOR;        final String specVendor            = getTrimmedString(attributes.getValue(specVendorKey));        final String specVersionKey = prefix + SPECIFICATION_VERSION;        final String specVersion            = getTrimmedString(attributes.getValue(specVersionKey));        final String impVersionKey = prefix + IMPLEMENTATION_VERSION;        final String impVersion            = getTrimmedString(attributes.getValue(impVersionKey));        final String impVendorKey = prefix + IMPLEMENTATION_VENDOR;        final String impVendor            = getTrimmedString(attributes.getValue(impVendorKey));        final String impVendorIDKey = prefix + IMPLEMENTATION_VENDOR_ID;        final String impVendorId            = getTrimmedString(attributes.getValue(impVendorIDKey));        final String impURLKey = prefix + IMPLEMENTATION_URL;        final String impURL = getTrimmedString(attributes.getValue(impURLKey));        return new Extension(name, specVersion, specVendor, impVersion,                              impVendor, impVendorId, impURL);    }    /**     * Trim the supplied string if the string is non-null     *     * @param value the string to trim or null     * @return the trimmed string or null     */    private static String getTrimmedString(final String value) {        return null == value ? null : value.trim();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -