* Try a little harder to find resources in app.addRepository:

If path names don't resolve by themself, try explicitly using hopHome as parent.
  This is useful in cases where hopHome isn't the current or user directory, such as 
  when running helma within tomcat.
* Make app reference transient.
This commit is contained in:
hns 2008-05-05 14:37:58 +00:00
parent 0592e44ad1
commit 585725d9c6

View file

@ -38,7 +38,7 @@ import org.apache.commons.logging.LogFactory;
* application specific functionality.
*/
public class ApplicationBean implements Serializable {
Application app;
transient Application app;
WrappedMap properties = null;
/**
@ -144,15 +144,12 @@ public class ApplicationBean implements Serializable {
Repository rep;
if (obj instanceof String) {
String path = (String) obj;
File file = new File(path).getAbsoluteFile();
File file = findResource(null, path);
if (!file.exists()) {
file = new File(path + ".zip").getAbsoluteFile();
file = findResource(app.hopHome, path);
}
if (!file.exists()) {
file = new File(path + ".js").getAbsoluteFile();
}
if (!file.exists()) {
throw new RuntimeException("Repository path does not exist: " + obj);
throw new RuntimeException("Repository path does not exist: " + file);
}
if (file.isDirectory()) {
rep = new FileRepository(file, parent);
@ -163,7 +160,7 @@ public class ApplicationBean implements Serializable {
rep = new SingleFileRepository(file, parent);
}
} else {
throw new RuntimeException("Unrecognized file type in addRepository: " + obj);
throw new RuntimeException("Unsupported file type in addRepository: " + file);
}
} else if (obj instanceof Repository) {
rep = (Repository) obj;
@ -178,6 +175,23 @@ public class ApplicationBean implements Serializable {
}
}
/**
* Helper method to resolve a repository path.
* @param parent the parent file
* @param path the repository path
* @return our best guess of what the file may be
*/
private File findResource(File parent, String path) {
File file = new File(parent, path).getAbsoluteFile();
if (!file.exists()) {
file = new File(parent, path + ".zip").getAbsoluteFile();
}
if (!file.exists()) {
file = new File(parent, path + ".js").getAbsoluteFile();
}
return file;
}
/**
* Get the app's classloader
* @return the app's classloader