public Program load(String filename, File baseDirectory, String encoding) throws LanguageException {
// Does source file exist?
File sourceFile = new File(baseDirectory, filename + "." + this.getSourceExtension());
if (!sourceFile.exists()) {
throw new LanguageException("Can't load program - File doesn't exist: " + IOUtils.getFullFilename(sourceFile));
}
if (!sourceFile.isFile()) {
throw new LanguageException("Can't load program - File is not a normal file: " + IOUtils.getFullFilename(sourceFile));
}
if (!sourceFile.canRead()) {
throw new LanguageException("Can't load program - File cannot be read: " + IOUtils.getFullFilename(sourceFile));
}
this.compile(filename, baseDirectory, encoding);
if (this.deleteSources) {
sourceFile.delete();
}
Class program = this.loadProgram(filename, baseDirectory);
// Try to instantiate once to ensure there are no exceptions thrown in the constructor
try {
Object testInstance = program.newInstance();
} catch(IllegalAccessException iae) {
getLogger().debug("No public constructor for class " + program.getName());
} catch(Exception e) {
// Unload class and delete the object file, or it won't be recompiled
// (leave the source file to allow examination).
this.doUnload(program);
new File(baseDirectory, filename + "." + this.getObjectExtension()).delete();
String message = "Error while instantiating " + filename;
getLogger().debug(message, e);
throw new LanguageException(message, e);
}
if (program == null) {
throw new LanguageException("Can't load program : " + baseDirectory.toString() + File.separator + filename);
}
return new JavaProgram(program);
}