m2u-upass-core / src / my / com / upass / Config.java @ 9:16125cca68e4
History | View | Annotate | Download (1.25 KB)
1 | 0:02300db8682b | hadi | |
---|---|---|---|
2 | package my.com.upass; |
||
3 | |||
4 | import java.io.FileInputStream; |
||
5 | import java.net.URL; |
||
6 | import java.net.URLDecoder; |
||
7 | import java.util.Properties; |
||
8 | |||
9 | import org.apache.log4j.Logger; |
||
10 | |||
11 | public class Config |
||
12 | { |
||
13 | private static final Logger logger = Logger.getLogger (Config.class); |
||
14 | private static final Properties props = new Properties (); |
||
15 | private static Config instance = null; |
||
16 | private static String CONFIG = "upass.cfg"; |
||
17 | |||
18 | public Config ()
|
||
19 | { |
||
20 | try
|
||
21 | { |
||
22 | // Load config file from classes directory
|
||
23 | URL url = this.getClass ().getClassLoader ().getResource (CONFIG); |
||
24 | String processedUrl = URLDecoder.decode (url.getFile (), "UTF-8"); |
||
25 | FileInputStream in = new FileInputStream (processedUrl); |
||
26 | props.load (in); |
||
27 | |||
28 | in.close (); |
||
29 | } |
||
30 | catch (Exception e) |
||
31 | { |
||
32 | logger.error ("Exception(1) " + getClass ().getName () + ":" + e.getMessage ()); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | public void setConfig (String configFile) |
||
37 | { |
||
38 | CONFIG = configFile; |
||
39 | } |
||
40 | |||
41 | public void initInstance () |
||
42 | { |
||
43 | if (instance == null) |
||
44 | { |
||
45 | instance = new Config ();
|
||
46 | } |
||
47 | return;
|
||
48 | } |
||
49 | |||
50 | public static Config getInstance () |
||
51 | { |
||
52 | if (instance == null) |
||
53 | { |
||
54 | instance = new Config ();
|
||
55 | } |
||
56 | return instance;
|
||
57 | } |
||
58 | |||
59 | public Properties getConfig () |
||
60 | { |
||
61 | return props;
|
||
62 | } |
||
63 | |||
64 | } |