mirror of
https://github.com/corda/corda.git
synced 2025-06-21 08:40:03 +00:00
Merge pull request #205 from dicej/getPackage
ensure ClassLoader.getPackage works with all class libraries
This commit is contained in:
@ -559,8 +559,7 @@ public final class Class <T> implements Type, AnnotatedElement {
|
||||
String name = getCanonicalName();
|
||||
int index = name.lastIndexOf('.');
|
||||
if (index >= 0) {
|
||||
return new Package(name.substring(0, index),
|
||||
null, null, null, null, null, null, null, null);
|
||||
return getClassLoader().getPackage(name.substring(0, index));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -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