758 |
} |
} |
759 |
|
|
760 |
/** |
/** |
761 |
|
* Look in both Attributes for a given value. The first Attributes |
762 |
|
* object, if not null, has precedence. |
763 |
|
*/ |
764 |
|
private String getAttributeValue(Attributes.Name name, Attributes first, |
765 |
|
Attributes second) |
766 |
|
{ |
767 |
|
String result = null; |
768 |
|
if (first != null) |
769 |
|
result = first.getValue(name); |
770 |
|
if (result == null) |
771 |
|
result = second.getValue(name); |
772 |
|
return result; |
773 |
|
} |
774 |
|
|
775 |
|
/** |
776 |
* Defines a Package based on the given name and the supplied manifest |
* Defines a Package based on the given name and the supplied manifest |
777 |
* information. The manifest indicates the tile, version and |
* information. The manifest indicates the title, version and |
778 |
* vendor information of the specification and implementation and wheter the |
* vendor information of the specification and implementation and whether the |
779 |
* package is sealed. If the Manifest indicates that the package is sealed |
* package is sealed. If the Manifest indicates that the package is sealed |
780 |
* then the Package will be sealed with respect to the supplied URL. |
* then the Package will be sealed with respect to the supplied URL. |
781 |
* |
* |
782 |
|
* @exception IllegalArgumentException If this package name already exists |
783 |
|
* in this class loader |
784 |
* @param name The name of the package |
* @param name The name of the package |
785 |
* @param manifest The manifest describing the specification, |
* @param manifest The manifest describing the specification, |
786 |
* implementation and sealing details of the package |
* implementation and sealing details of the package |
787 |
* @param url the code source url to seal the package |
* @param url the code source url to seal the package |
|
* @exception IllegalArgumentException If this package name already exists |
|
|
* in this class loader |
|
788 |
* @return the defined Package |
* @return the defined Package |
789 |
*/ |
*/ |
790 |
protected Package definePackage(String name, Manifest manifest, URL url) |
protected Package definePackage(String name, Manifest manifest, URL url) |
791 |
throws IllegalArgumentException |
throws IllegalArgumentException |
792 |
{ |
{ |
793 |
|
// Compute the name of the package as it may appear in the |
794 |
|
// Manifest. |
795 |
|
StringBuffer xform = new StringBuffer(name); |
796 |
|
for (int i = xform.length () - 1; i >= 0; --i) |
797 |
|
if (xform.charAt(i) == '.') |
798 |
|
xform.setCharAt(i, '/'); |
799 |
|
xform.append('/'); |
800 |
|
String xformName = xform.toString(); |
801 |
|
|
802 |
|
Attributes entryAttr = manifest.getAttributes(xformName); |
803 |
Attributes attr = manifest.getMainAttributes(); |
Attributes attr = manifest.getMainAttributes(); |
804 |
String specTitle = attr.getValue(Attributes.Name.SPECIFICATION_TITLE); |
|
805 |
String specVersion = attr.getValue(Attributes.Name.SPECIFICATION_VERSION); |
String specTitle |
806 |
String specVendor = attr.getValue(Attributes.Name.SPECIFICATION_VENDOR); |
= getAttributeValue(Attributes.Name.SPECIFICATION_TITLE, |
807 |
String implTitle = attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE); |
entryAttr, attr); |
808 |
String implVersion = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION); |
String specVersion |
809 |
String implVendor = attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR); |
= getAttributeValue(Attributes.Name.SPECIFICATION_VERSION, |
810 |
|
entryAttr, attr); |
811 |
|
String specVendor |
812 |
|
= getAttributeValue(Attributes.Name.SPECIFICATION_VENDOR, |
813 |
|
entryAttr, attr); |
814 |
|
String implTitle |
815 |
|
= getAttributeValue(Attributes.Name.IMPLEMENTATION_TITLE, |
816 |
|
entryAttr, attr); |
817 |
|
String implVersion |
818 |
|
= getAttributeValue(Attributes.Name.IMPLEMENTATION_VERSION, |
819 |
|
entryAttr, attr); |
820 |
|
String implVendor |
821 |
|
= getAttributeValue(Attributes.Name.IMPLEMENTATION_VENDOR, |
822 |
|
entryAttr, attr); |
823 |
|
|
824 |
// Look if the Manifest indicates that this package is sealed |
// Look if the Manifest indicates that this package is sealed |
825 |
// XXX - most likely not completely correct! |
// XXX - most likely not completely correct! |
831 |
// make sure that the URL is null so the package is not sealed |
// make sure that the URL is null so the package is not sealed |
832 |
url = null; |
url = null; |
833 |
|
|
834 |
return definePackage(name, specTitle, specVersion, specVendor, implTitle, |
return definePackage(name, |
835 |
implVersion, implVendor, url); |
specTitle, specVendor, specVersion, |
836 |
|
implTitle, implVendor, implVersion, |
837 |
|
url); |
838 |
} |
} |
839 |
|
|
840 |
/** |
/** |