private void loadPrepararorJar(File file, HashMap preparatorHash,
PreparatorSettings[] preparatorSettingsArr)
throws RegainException
{
// Find the preparator classes
JarFile jarFile = null;
try {
jarFile = new JarFile(file);
// Load the manifest
InputStream in = jarFile.getInputStream(jarFile.getEntry("META-INF/MANIFEST.MF"));
Manifest manifest = new Manifest(in);
in.close();
// Read the class names
Attributes attributes = manifest.getMainAttributes();
String classNameCsv = attributes.getValue("Preparator-Classes");
if (classNameCsv == null) {
throw new RegainException("The manifest in preparator file '" + file
+ "' has no 'Preparator-Classes' attribute");
}
String[] classNameArr = RegainToolkit.splitString(classNameCsv, ";", true);
// Load the classes if they are not disabled
URLClassLoader loader = null;
for (int i = 0; i < classNameArr.length; i++) {
// Get the class name
String className = classNameArr[i];
if (className.startsWith(".")) {
className = PreparatorSettings.DEFAULT_PREPARATOR_PACKAGE + className;
}
if (isPreparatorEnabled(className, preparatorSettingsArr)) {
// Create the class loader if nessesary
if (loader == null) {
loader = new URLClassLoader(new URL[] { file.toURI().toURL() });
}
// Load the preparator and add it to the preparatorHash
Preparator prep = (Preparator) RegainToolkit.createClassInstance(className, Preparator.class, loader);
preparatorHash.put(className, prep);
}
}
}
catch (Throwable thr) {
throw new RegainException("Loading preparator file '" + file
+ "' failed", thr);
}
finally {
if (jarFile != null) {
try { jarFile.close(); } catch (IOException exc) {}
}
}
}