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));
}
Class clazz = null;
ArrayList dependecies = new ArrayList();
String className = null;
BufferedReader r = null;
try {
r = new BufferedReader(
(encoding == null)?
new FileReader(sourceFile):
new InputStreamReader(new FileInputStream(sourceFile), encoding));
className = getMeta(r.readLine(), "extends");
if (className == null) {
throw new LanguageException("Can't load program - Signature is not found: "
+ IOUtils.getFullFilename(sourceFile));
}
clazz = ClassUtils.loadClass(className);
String line;
while((line = getMeta(r.readLine(), "depends")) != null) {
dependecies.add(line);
}
} catch (IOException e) {
throw new LanguageException("Can't load program - Signature is not found: "
+ IOUtils.getFullFilename(sourceFile));
} catch (ClassNotFoundException e) {
throw new LanguageException("Can't load program - Base class " + className + " is not found: "
+ IOUtils.getFullFilename(sourceFile));
} finally {
if (r != null) try {
r.close();
} catch (IOException ignored) {