|
1 |
| package net.sf.crispy.properties; |
|
2 |
| |
|
3 |
| import java.io.InputStream; |
|
4 |
| import java.util.Properties; |
|
5 |
| |
|
6 |
| import net.sf.crispy.PropertiesLoader; |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| public class ClassPropertiesLoader implements PropertiesLoader { |
|
18 |
| |
|
19 |
| private String fileName = null; |
|
20 |
| private Class clazz = null; |
|
21 |
| |
|
22 |
5
| public ClassPropertiesLoader(Class pvClass, String pvFileName) {
|
|
23 |
5
| fileName = pvFileName;
|
|
24 |
5
| clazz = pvClass;
|
|
25 |
| } |
|
26 |
| |
|
27 |
6
| public Properties load() {
|
|
28 |
6
| if (fileName == null) {
|
|
29 |
2
| throw new IllegalArgumentException("The file name for the ClassPropertiesLoader is null.");
|
|
30 |
| } |
|
31 |
4
| if (clazz == null) {
|
|
32 |
1
| throw new IllegalArgumentException("The class for the ClassPropertiesLoader is null.");
|
|
33 |
| } |
|
34 |
| |
|
35 |
3
| InputStream lvInputStream = clazz.getResourceAsStream(fileName);
|
|
36 |
3
| Properties lvProperties = new Properties();
|
|
37 |
3
| try {
|
|
38 |
3
| lvProperties.load(lvInputStream);
|
|
39 |
| } catch (Exception e) { |
|
40 |
1
| throw new PropertiesLoadException("Error in load-method:", e);
|
|
41 |
| } |
|
42 |
2
| return lvProperties;
|
|
43 |
| } |
|
44 |
| |
|
45 |
| } |