01: package net.sf.crispy.properties;
02:
03: import java.io.InputStream;
04: import java.util.Properties;
05:
06: import net.sf.crispy.PropertiesLoader;
07:
08: /**
09: * Load file where the class is find.
10: * Example: class is: <code>test.crispy.Run</code> the file is in the same directory
11: * <code>/test/crispy/example.properties</code>
12: * use internal: <code>clazz.getResourceAsStream(fileName);</code>
13: *
14: * @author Linke
15: *
16: */
17: public class ClassPropertiesLoader implements PropertiesLoader {
18:
19: private String fileName = null;
20: private Class clazz = null;
21:
22: public ClassPropertiesLoader(Class pvClass, String pvFileName) {
23: fileName = pvFileName;
24: clazz = pvClass;
25: }
26:
27: public Properties load() {
28: if (fileName == null) {
29: throw new IllegalArgumentException(
30: "The file name for the ClassPropertiesLoader is null.");
31: }
32: if (clazz == null) {
33: throw new IllegalArgumentException(
34: "The class for the ClassPropertiesLoader is null.");
35: }
36:
37: InputStream lvInputStream = clazz.getResourceAsStream(fileName);
38: Properties lvProperties = new Properties();
39: try {
40: lvProperties.load(lvInputStream);
41: } catch (Exception e) {
42: throw new PropertiesLoadException("Error in load-method:",
43: e);
44: }
45: return lvProperties;
46: }
47:
48: }
|