Specificationpublic final class Specification extends Object Utility class that represents either an available "Optional Package"
(formerly known as "Standard Extension") as described in the manifest
of a JAR file, or the requirement for such an optional package.
For more information about optional packages, see the document
Optional Package Versioning in the documentation bundle for your
Java2 Standard Edition package, in file
guide/extensions/versioning.html . |
Fields Summary |
---|
private static final String | MISSING | public static final Attributes$Name | SPECIFICATION_TITLEManifest Attribute Name object for SPECIFICATION_TITLE. | public static final Attributes$Name | SPECIFICATION_VERSIONManifest Attribute Name object for SPECIFICATION_VERSION. | public static final Attributes$Name | SPECIFICATION_VENDORManifest Attribute Name object for SPECIFICATION_VENDOR. | public static final Attributes$Name | IMPLEMENTATION_TITLEManifest Attribute Name object for IMPLEMENTATION_TITLE. | public static final Attributes$Name | IMPLEMENTATION_VERSIONManifest Attribute Name object for IMPLEMENTATION_VERSION. | public static final Attributes$Name | IMPLEMENTATION_VENDORManifest Attribute Name object for IMPLEMENTATION_VENDOR. | public static final Compatibility | COMPATIBLEEnum indicating that extension is compatible with other Package
Specification. | public static final Compatibility | REQUIRE_SPECIFICATION_UPGRADEEnum indicating that extension requires an upgrade
of specification to be compatible with other Package Specification. | public static final Compatibility | REQUIRE_VENDOR_SWITCHEnum indicating that extension requires a vendor
switch to be compatible with other Package Specification. | public static final Compatibility | REQUIRE_IMPLEMENTATION_CHANGEEnum indicating that extension requires an upgrade
of implementation to be compatible with other Package Specification. | public static final Compatibility | INCOMPATIBLEThis enum indicates that an extension is incompatible with
other Package Specification in ways other than other enums
indicate. For example, the other Package Specification
may have a different ID. | private String | specificationTitleThe name of the Package Specification. | private DeweyDecimal | specificationVersionThe version number (dotted decimal notation) of the specification
to which this optional package conforms. | private String | specificationVendorThe name of the company or organization that originated the
specification to which this specification conforms. | private String | implementationTitleThe title of implementation. | private String | implementationVendorThe name of the company or organization that produced this
implementation of this specification. | private String | implementationVersionThe version string for implementation. The version string is
opaque. | private String[] | sectionsThe sections of jar that the specification applies to. |
Constructors Summary |
---|
public Specification(String specificationTitle, String specificationVersion, String specificationVendor, String implementationTitle, String implementationVersion, String implementationVendor)The constructor to create Package Specification object.
Note that every component is allowed to be specified
but only the specificationTitle is mandatory.
this(specificationTitle, specificationVersion, specificationVendor,
implementationTitle, implementationVersion, implementationVendor,
null);
| public Specification(String specificationTitle, String specificationVersion, String specificationVendor, String implementationTitle, String implementationVersion, String implementationVendor, String[] sections)The constructor to create Package Specification object.
Note that every component is allowed to be specified
but only the specificationTitle is mandatory.
this.specificationTitle = specificationTitle;
this.specificationVendor = specificationVendor;
if (null != specificationVersion) {
try {
this.specificationVersion
= new DeweyDecimal(specificationVersion);
} catch (final NumberFormatException nfe) {
final String error = "Bad specification version format '"
+ specificationVersion + "' in '" + specificationTitle
+ "'. (Reason: " + nfe + ")";
throw new IllegalArgumentException(error);
}
}
this.implementationTitle = implementationTitle;
this.implementationVendor = implementationVendor;
this.implementationVersion = implementationVersion;
if (null == this.specificationTitle) {
throw new NullPointerException("specificationTitle");
}
String[] copy = null;
if (null != sections) {
copy = new String[ sections.length ];
System.arraycopy(sections, 0, copy, 0, sections.length);
}
this.sections = copy;
|
Methods Summary |
---|
public Compatibility | getCompatibilityWith(org.apache.tools.ant.taskdefs.optional.extension.Specification other)Return a Compatibility enum indicating the relationship of this
Package Specification with the specified
Extension .
// Specification Name must match
if (!specificationTitle.equals(other.getSpecificationTitle())) {
return INCOMPATIBLE;
}
// Available specification version must be >= required
final DeweyDecimal otherSpecificationVersion
= other.getSpecificationVersion();
if (null != specificationVersion) {
if (null == otherSpecificationVersion
|| !isCompatible(specificationVersion, otherSpecificationVersion)) {
return REQUIRE_SPECIFICATION_UPGRADE;
}
}
// Implementation Vendor ID must match
final String otherImplementationVendor
= other.getImplementationVendor();
if (null != implementationVendor) {
if (null == otherImplementationVendor
|| !implementationVendor.equals(otherImplementationVendor)) {
return REQUIRE_VENDOR_SWITCH;
}
}
// Implementation version must be >= required
final String otherImplementationVersion
= other.getImplementationVersion();
if (null != implementationVersion) {
if (null == otherImplementationVersion
|| !implementationVersion.equals(otherImplementationVersion)) {
return REQUIRE_IMPLEMENTATION_CHANGE;
}
}
// This available optional package satisfies the requirements
return COMPATIBLE;
| public java.lang.String | getImplementationTitle()Get the title of the specification.
return implementationTitle;
| public java.lang.String | getImplementationVendor()Get the vendor of the extensions implementation.
return implementationVendor;
| public java.lang.String | getImplementationVersion()Get the version of the implementation.
return implementationVersion;
| public java.lang.String[] | getSections()Return an array containing sections to which specification applies
or null if relevent to no sections.
if (null == sections) {
return null;
}
final String[] newSections = new String[ sections.length ];
System.arraycopy(sections, 0, newSections, 0, sections.length);
return newSections;
| private static org.apache.tools.ant.taskdefs.optional.extension.Specification | getSpecification(java.lang.String section, java.util.jar.Attributes attributes)Extract an Package Specification from Attributes.
//WARNING: We trim the values of all the attributes because
//Some extension declarations are badly defined (ie have spaces
//after version or vendor)
final String name
= getTrimmedString(attributes.getValue(SPECIFICATION_TITLE));
if (null == name) {
return null;
}
final String specVendor
= getTrimmedString(attributes.getValue(SPECIFICATION_VENDOR));
if (null == specVendor) {
throw new ParseException(MISSING + SPECIFICATION_VENDOR, 0);
}
final String specVersion
= getTrimmedString(attributes.getValue(SPECIFICATION_VERSION));
if (null == specVersion) {
throw new ParseException(MISSING + SPECIFICATION_VERSION, 0);
}
final String impTitle
= getTrimmedString(attributes.getValue(IMPLEMENTATION_TITLE));
if (null == impTitle) {
throw new ParseException(MISSING + IMPLEMENTATION_TITLE, 0);
}
final String impVersion
= getTrimmedString(attributes.getValue(IMPLEMENTATION_VERSION));
if (null == impVersion) {
throw new ParseException(MISSING + IMPLEMENTATION_VERSION, 0);
}
final String impVendor
= getTrimmedString(attributes.getValue(IMPLEMENTATION_VENDOR));
if (null == impVendor) {
throw new ParseException(MISSING + IMPLEMENTATION_VENDOR, 0);
}
return new Specification(name, specVersion, specVendor,
impTitle, impVersion, impVendor,
new String[]{section});
| public java.lang.String | getSpecificationTitle()Get the title of the specification.
return specificationTitle;
| public java.lang.String | getSpecificationVendor()Get the vendor of the specification.
return specificationVendor;
| public DeweyDecimal | getSpecificationVersion()Get the version of the specification.
return specificationVersion;
| public static org.apache.tools.ant.taskdefs.optional.extension.Specification[] | getSpecifications(java.util.jar.Manifest manifest)Return an array of Package Specification objects.
If there are no such optional packages, a zero-length array is returned.
if (null == manifest) {
return new Specification[ 0 ];
}
final ArrayList results = new ArrayList();
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);
final Specification specification
= getSpecification(key, attributes);
if (null != specification) {
results.add(specification);
}
}
final ArrayList trimmedResults = removeDuplicates(results);
return (Specification[]) trimmedResults.toArray(new Specification[trimmedResults.size()]);
| private static java.lang.String | getTrimmedString(java.lang.String value)Trim the supplied string if the string is non-null
return value == null ? null : value.trim();
| private boolean | isCompatible(DeweyDecimal first, DeweyDecimal second)Return true if the first version number is greater than
or equal to the second; otherwise return false .
return first.isGreaterThanOrEqual(second);
| public boolean | isCompatibleWith(org.apache.tools.ant.taskdefs.optional.extension.Specification other)Return true if the specified package
is satisfied by this Specification . Otherwise, return
false .
return (COMPATIBLE == getCompatibilityWith(other));
| private static boolean | isEqual(org.apache.tools.ant.taskdefs.optional.extension.Specification specification, org.apache.tools.ant.taskdefs.optional.extension.Specification other)Test if two specifications are equal except for their sections.
return
specification.getSpecificationTitle().equals(other.getSpecificationTitle())
&& specification.getSpecificationVersion().isEqual(other.getSpecificationVersion())
&& specification.getSpecificationVendor().equals(other.getSpecificationVendor())
&& specification.getImplementationTitle().equals(other.getImplementationTitle())
&& specification.getImplementationVersion().equals(other.getImplementationVersion())
&& specification.getImplementationVendor().equals(other.getImplementationVendor());
| private static org.apache.tools.ant.taskdefs.optional.extension.Specification | mergeInSections(org.apache.tools.ant.taskdefs.optional.extension.Specification specification, java.util.ArrayList sectionsToAdd)Merge the specified sections into specified section and return result.
If no sections to be added then just return original specification.
if (0 == sectionsToAdd.size()) {
return specification;
}
sectionsToAdd.addAll(Arrays.asList(specification.getSections()));
final String[] sections =
(String[]) sectionsToAdd.toArray(new String[sectionsToAdd.size()]);
return new Specification(specification.getSpecificationTitle(),
specification.getSpecificationVersion().toString(),
specification.getSpecificationVendor(),
specification.getImplementationTitle(),
specification.getImplementationVersion(),
specification.getImplementationVendor(),
sections);
| private static java.util.ArrayList | removeDuplicates(java.util.ArrayList list)Combine all specifications objects that are identical except
for the sections.
Note this is very inefficent and should probably be fixed
in the future.
final ArrayList results = new ArrayList();
final ArrayList sections = new ArrayList();
while (list.size() > 0) {
final Specification specification = (Specification) list.remove(0);
final Iterator iterator = list.iterator();
while (iterator.hasNext()) {
final Specification other = (Specification) iterator.next();
if (isEqual(specification, other)) {
final String[] otherSections = other.getSections();
if (null != sections) {
sections.addAll(Arrays.asList(otherSections));
}
iterator.remove();
}
}
final Specification merged =
mergeInSections(specification, sections);
results.add(merged);
//Reset list of sections
sections.clear();
}
return results;
| public java.lang.String | toString()Return a String representation of this object.
final String brace = ": ";
final StringBuffer sb
= new StringBuffer(SPECIFICATION_TITLE.toString());
sb.append(brace);
sb.append(specificationTitle);
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 != implementationTitle) {
sb.append(IMPLEMENTATION_TITLE);
sb.append(brace);
sb.append(implementationTitle);
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 != implementationVendor) {
sb.append(IMPLEMENTATION_VENDOR);
sb.append(brace);
sb.append(implementationVendor);
sb.append(StringUtils.LINE_SEP);
}
return sb.toString();
|
|