1 package de.fhdw.wtf.persistence.utils;
2
3 import java.util.HashMap;
4 import java.util.MissingResourceException;
5
6
7
8
9
10
11
12
13 public class PropertiesReaderFactory {
14
15 private static PropertiesReaderFactory _instance = null;
16
17
18
19
20
21
22 public static synchronized PropertiesReaderFactory getInstance() {
23 if (_instance == null) {
24 _instance = new PropertiesReaderFactory();
25 }
26 return _instance;
27 }
28
29
30
31
32
33
34
35 public PropertiesReader getPropertiesReaderFile(final String file) {
36 final PropertiesReader reader = new PropertiesReaderFile();
37 try {
38 reader.initialize(file);
39 return reader;
40 } catch (final MissingResourceException e) {
41 return this.getPropertiesReaderOracle();
42 }
43 }
44
45
46
47
48
49
50
51
52
53 public PropertiesReader getPropertiesReaderOracle() {
54 PropertiesReader reader;
55
56
57
58 reader = new PropertiesReaderFile();
59 try {
60 reader.initialize("oracle.properties");
61 return reader;
62 } catch (final MissingResourceException e) {
63
64 }
65
66
67
68 reader = new PropertiesReaderRessource();
69 try {
70 reader.initialize("oracle");
71 return reader;
72 } catch (final MissingResourceException e) {
73
74 }
75
76
77
78 reader = new PropertiesReader() {
79 private final HashMap<String, String> propValues = new HashMap<>();
80
81 @Override
82 public void initialize(final String propFile) throws MissingResourceException {
83 this.propValues.put("sid", "XE");
84 this.propValues.put("schema", "meta");
85 this.propValues.put("username", "meta");
86 this.propValues.put("password", "meta");
87 this.propValues.put("hostname", "localhost");
88 this.propValues.put("port", "1521");
89 }
90
91 @Override
92 public String getProperty(final String key) {
93 if (!this.propValues.containsKey(key)) {
94 return "";
95 }
96 return this.propValues.get(key);
97 }
98 };
99 reader.initialize("");
100 return reader;
101 }
102 }