mirror of
https://github.com/corda/corda.git
synced 2025-06-13 04:38:19 +00:00
ensure ClassLoader.getPackage works with all class libraries
There's more work to do to derive all the properties of a given class from its code source (e.g. JAR file), but this at least ensures that ClassLoader.getPackage will actually return something non-null when appropriate.
This commit is contained in:
@ -17,9 +17,12 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
public abstract class ClassLoader {
|
||||
private final ClassLoader parent;
|
||||
private Map<String, Package> packages;
|
||||
|
||||
protected ClassLoader(ClassLoader parent) {
|
||||
if (parent == null) {
|
||||
@ -33,6 +36,45 @@ public abstract class ClassLoader {
|
||||
this(getSystemClassLoader());
|
||||
}
|
||||
|
||||
private Map<String, Package> packages() {
|
||||
if (packages == null) {
|
||||
packages = new HashMap();
|
||||
}
|
||||
return packages;
|
||||
}
|
||||
|
||||
protected Package getPackage(String name) {
|
||||
synchronized (this) {
|
||||
return packages().get(name);
|
||||
}
|
||||
}
|
||||
|
||||
protected Package[] getPackages() {
|
||||
synchronized (this) {
|
||||
return packages().values().toArray(new Package[packages().size()]);
|
||||
}
|
||||
}
|
||||
|
||||
protected Package definePackage(String name,
|
||||
String specificationTitle,
|
||||
String specificationVersion,
|
||||
String specificationVendor,
|
||||
String implementationTitle,
|
||||
String implementationVersion,
|
||||
String implementationVendor,
|
||||
URL sealBase)
|
||||
{
|
||||
Package p = new Package
|
||||
(name, implementationTitle, implementationVersion,
|
||||
implementationVendor, specificationTitle, specificationVersion,
|
||||
specificationVendor, sealBase, this);
|
||||
|
||||
synchronized (this) {
|
||||
packages().put(name, p);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
public static ClassLoader getSystemClassLoader() {
|
||||
return ClassLoader.class.getClassLoader();
|
||||
}
|
||||
|
Reference in New Issue
Block a user