mcconnell 2003/11/25 10:53:49
Modified: merlin/util/defaults/src/java/org/apache/avalon/defaults
Defaults.java
Log:
Add static utility to get default properties.
Revision Changes Path
1.4 +31 -2
avalon/merlin/util/defaults/src/java/org/apache/avalon/defaults/Defaults.java
Index: Defaults.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/util/defaults/src/java/org/apache/avalon/defaults/Defaults.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Defaults.java 24 Nov 2003 21:17:29 -0000 1.3
+++ Defaults.java 25 Nov 2003 18:53:49 -0000 1.4
@@ -50,7 +50,8 @@
package org.apache.avalon.defaults ;
-
+import java.io.IOException ;
+import java.io.InputStream ;
import java.util.ArrayList ;
import java.util.Properties ;
import java.util.Enumeration ;
@@ -376,6 +377,34 @@
}
}
}
+
+ /**
+ * Read in a static properties resource relative to a supplied class
+ * and path.
+ *
+ * @param ref a class used to establish a classloader and anchors
+ * relative path references
+ * @param path the resoruce address
+ * @return the static properties
+ * @exception IllegalStateException if the path is unresolvable
+ */
+ public static Properties getStaticProperties( Class ref, String path ) throws
IOException
+ {
+ Properties bootstrap = new Properties();
+ InputStream input = ref.getResourceAsStream( path );
+ if( input == null )
+ {
+ final String error =
+ "Internal error, unable to locate enbedded resource: "
+ + path
+ + " from the resource: "
+ + ref.getProtectionDomain().getCodeSource().getLocation();
+ throw new IllegalStateException( error );
+ }
+ bootstrap.load( input );
+ return bootstrap;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]