lcsim-conditions/src/main/java/org/lcsim/conditions
diff -u -r1.3 -r1.4
--- ConditionsReader.java 19 Mar 2012 20:55:58 -0000 1.3
+++ ConditionsReader.java 28 Mar 2012 17:15:27 -0000 1.4
@@ -123,6 +123,9 @@
* For more details see @link http://confluence.slac.stanford.edu/display/ilc/Conditions+database
*/
static ConditionsReader create(String detectorName, int run) throws ConditionsNotFoundException {
+ boolean debug = true;
+ if (debug)
+ System.out.println("ConditionsReader.create - " + detectorName);
String name = detectorName;
try {
if (cache == null) {
@@ -153,6 +156,14 @@
return new ZipConditionsReader(file);
}
} else {
+
+ // Search the classpath for conditions.
+ try {
+ return new BaseClasspathConditionsReader(name);
+ } catch (IOException x) {
+ System.out.println(x.getLocalizedMessage());
+ }
+
// Search for a local, cached copy.
File detectorDir = new File(home, "detectors");
File zipFile = new File(detectorDir, name + ".zip");
@@ -164,12 +175,6 @@
return new DirectoryConditionsReader(dirFile);
}
- // Search the classpath from the base package.
- try {
- return new BaseClasspathConditionsReader(name);
- } catch (IOException x) {
- }
-
// Finally, try to pull the detector conditions from the lcsim.org website.
try {
URL url = new URL("http://www.lcsim.org/detectors/" + name + ".zip");
@@ -327,30 +332,35 @@
}
/**
- * This ConditionsReader finds detector conditions with the assumption that the conditions are located in a package called <code>detectorName</code>.
- * This ConditionsReader will work if the lcsim-detector jar from the LCDetectors project is on the classpath.
+ * This ConditionsReader finds detector conditions with the assumption that they
+ * are located in a package called <code>detectorName</code>, which must be
+ * accessible to the ContextClassLoader of the current thread.
*/
private static class BaseClasspathConditionsReader extends ConditionsReader {
private String detectorName;
+ //private ClassLoader classLoader;
+ String propFileName = "detector.properties";
BaseClasspathConditionsReader(String detectorName) throws IOException {
this.detectorName = detectorName;
- if (ConditionsReader.class.getResourceAsStream("/" + detectorName + "/detector.properties") == null) {
- throw new IOException("Unable to find " + detectorName + "/detector.properties on the classpath!");
+ //classLoader = Thread.currentThread().getContextClassLoader();
+ //if (ConditionsReader.class.getResourceAsStream("/" + detectorName + "/detector.properties") == null) {
+ if (getClass().getResourceAsStream("/" + detectorName + "/" + propFileName) == null) {
+ throw new IOException("Unable to find " + detectorName + "/" + propFileName + " on the classpath.");
}
}
public InputStream open(String name, String type) throws IOException {
- InputStream in = ConditionsReader.class.getResourceAsStream("/" + detectorName + "/" + name + "." + type);
+ InputStream in = getClass().getResourceAsStream("/" + detectorName + "/" + name + "." + type);
if (in == null) {
- throw new IOException("Conditions " + detectorName + "." + name + "." + type + " not found");
+ throw new IOException("Conditions for " + detectorName + " with type " + type + " were not found");
}
return in;
}
- public void close() throws IOException {
- }
+ public void close() throws IOException
+ {}
}
private static class DummyConditionsReader extends ConditionsReader {