// convert the class name to a file name
String resourceName = className.replace('.', '/') + ".class";
// find the class file resource
ResourceHandle resourceHandle = location.getResourceHandle(resourceName);
if (resourceHandle == null) throw new ClassNotFoundException(className);
byte[] bytes;
Manifest manifest;
try
{
// get the bytes from the class file
bytes = resourceHandle.getBytes();
// get the manifest for defining the packages
manifest = resourceHandle.getManifest();
}
catch (IOException e)
{
throw new ClassNotFoundException(className, e);
}
// get the certificates for the code source
Certificate[] certificates = resourceHandle.getCertificates();
// the code source url is used to define the package and as the security context for the class
URL codeSourceUrl = resourceHandle.getCodeSourceUrl();
// define the package (required for security)
definePackage(className, codeSourceUrl, manifest);
// this is the security context of the class