if (record) {
record(bytecode);
}
// Use a protectionDomain to associate the codebase with the
// class.
ProtectionDomain pd = (ProtectionDomain)pdCache.get(bytecode.codebase);
if (pd == null) {
try {
URL url = urlFactory.getCodeBase(bytecode.codebase);
CodeSource source = new CodeSource(url, (Certificate[])null);
pd = new ProtectionDomain(source, null, this, null);
pdCache.put(bytecode.codebase, pd);
} catch (MalformedURLException mux) {
throw new ClassNotFoundException(name, mux);
}
}
// Do it the simple way.
byte bytes[] = bytecode.bytes;
int i = name.lastIndexOf('.');
if (i != -1) {
String pkgname = name.substring(0, i);
// Check if package already loaded.
Package pkg = getPackage(pkgname);
Manifest man = bytecode.manifest;
if (pkg != null) {
// Package found, so check package sealing.
if (pkg.isSealed()) {
// Verify that code source URL is the same.
if (!pkg.isSealed(pd.getCodeSource().getLocation())) {
throw new SecurityException("sealing violation: package " + pkgname + " is sealed");
}
} else {
// Make sure we are not attempting to seal the package
// at this code source URL.
if ((man != null) && isSealed(pkgname, man)) {
throw new SecurityException("sealing violation: can't seal package " + pkgname + ": already loaded");
}
}
} else {
if (man != null) {
definePackage(pkgname, man, pd.getCodeSource().getLocation());
} else {
definePackage(pkgname, null, null, null, null, null, null, null);
}
}
}