[MOBY-guts] biomoby commit
Gary Schlitz
gss at pub.open-bio.org
Mon Jun 14 20:58:13 UTC 2004
gss
Mon Jun 14 16:58:12 EDT 2004
Update of /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools
In directory pub.open-bio.org:/tmp/cvs-serv10926/src/org/smoby/ref/tools
Modified Files:
MOBYProperties.java
Log Message:
Use servlet context to find properties file
moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools MOBYProperties.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/MOBYProperties.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/MOBYProperties.java 2004/03/20 00:36:48 1.1
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/MOBYProperties.java 2004/06/14 20:58:12 1.2
@@ -3,6 +3,8 @@
import java.io.*;
import java.util.*;
+import javax.servlet.ServletContext;
+
/**
* This abstract class contains a set of static methods for retrieving
@@ -32,25 +34,12 @@
public static String getProperty(String propName, boolean required)
throws MissingPropertyException
{
- try {
- String value = getProps().getProperty(propName);
- if (required && (value == null)) {
- throw new MissingPropertyException(propName,
- "Property " + propName + " not found in " + PROP_FILE_NAME);
- }
- return value;
- } catch (FileNotFoundException e) {
- if (required) {
- throw new MissingPropertyException(propName,
- "Properties file " + PROP_FILE_NAME + " not found on classpath", e);
- }
- } catch (IOException e) {
- if (required) {
- throw new MissingPropertyException(propName,
- "Error while reading " + PROP_FILE_NAME, e);
- }
+ String value = props.getProperty(propName);
+ if (required && (value == null)) {
+ throw new MissingPropertyException(propName,
+ "Property " + propName + " not found in " + PROP_FILE_NAME);
}
- return null;
+ return value;
}
/**
@@ -68,21 +57,22 @@
}
/**
- * Use lazy evaluation to create a Properties object and load the
- * properties file into it.
- * @return the Properties object.
- * @throws FileNotFoundException
- * @throws IOException
+ * Read the properties file
+ * @throws FileNotFoundException if the file cannot be located
+ * @throws IOException if the file cannot be read
*/
- private static Properties getProps()
- throws FileNotFoundException, IOException
+ public static void initProps(ServletContext context)
+ throws FileNotFoundException, IOException
{
- if (props == null) {
+ if (props == null) // Only try to read it once
+ {
props = new Properties();
- InputStream is = MOBYProperties.class.getClassLoader().
- getResourceAsStream(PROP_FILE_NAME);
- props.load(is);
+ InputStream is = context.getResourceAsStream(PROP_FILE_NAME);
+ if (is == null) {
+ throw new FileNotFoundException(
+ "Properties file \"" + PROP_FILE_NAME + "\" not found");
+ }
+ props.load(is);
}
- return props;
}
}
More information about the MOBY-guts
mailing list