Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/config/ConfigurationFactory.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.config; | |
2 | |
3 import java.util.logging.Logger; | |
4 import java.util.logging.Level; | |
5 | |
6 import net.jini.config.Configuration; | |
7 import net.jini.config.ConfigurationProvider; | |
8 import net.jini.config.ConfigurationException; | |
9 | |
10 import net.jini.security.BasicProxyPreparer; | |
11 import net.jini.security.ProxyPreparer; | |
12 | |
13 import com.sun.jini.config.Config; | |
14 | |
15 import org.dancres.blitz.Logging; | |
16 | |
17 public class ConfigurationFactory { | |
18 static Logger theLogger = | |
19 Logging.newLogger("org.dancres.blitz.config.ConfigurationFactory", | |
20 Level.INFO); | |
21 | |
22 private static String[] theArgs = {"config/blitz.config"}; | |
23 | |
24 static { | |
25 String myDefault = System.getProperty("org.dancres.blitz.config"); | |
26 | |
27 if (myDefault != null) | |
28 theArgs = new String[] {myDefault}; | |
29 } | |
30 | |
31 private static Configuration theConfig; | |
32 | |
33 public static final String BLITZ_MODULE = "org.dancres.blitz"; | |
34 | |
35 private static final ProxyPreparer DEFAULT_PREPARER = | |
36 new BasicProxyPreparer(); | |
37 | |
38 /** | |
39 Configure the arguments for finding a Configuration | |
40 */ | |
41 public static void setup(String[] anArgs) { | |
42 theLogger.log(Level.INFO, | |
43 "ConfigurationFactory will load config from: " + | |
44 anArgs[0]); | |
45 theArgs = anArgs; | |
46 } | |
47 | |
48 /** | |
49 Attempt to load configured config file or the default which is | |
50 "config/blitz.config" | |
51 */ | |
52 private static synchronized void load() throws ConfigurationException { | |
53 theLogger.log(Level.INFO, "Loading config from: " + theArgs[0]); | |
54 | |
55 theConfig = | |
56 ConfigurationProvider.getInstance(theArgs, | |
57 ConfigurationFactory.class.getClassLoader()); | |
58 } | |
59 | |
60 /** | |
61 Attempt to obtain the configuration | |
62 */ | |
63 public static synchronized Configuration getConfig() | |
64 throws ConfigurationException { | |
65 if (theConfig == null) { | |
66 load(); | |
67 } | |
68 | |
69 return theConfig; | |
70 } | |
71 | |
72 public static synchronized ProxyPreparer getPreparer(String aName) | |
73 throws ConfigurationException { | |
74 | |
75 return (ProxyPreparer) | |
76 Config.getNonNullEntry(getConfig(), BLITZ_MODULE, aName, | |
77 ProxyPreparer.class, DEFAULT_PREPARER); | |
78 } | |
79 | |
80 public static synchronized Object getEntry(String aName, Class aType) | |
81 throws ConfigurationException { | |
82 return getConfig().getEntry(BLITZ_MODULE, aName, aType); | |
83 } | |
84 | |
85 public static synchronized Object getEntry(String aName, Class aType, | |
86 Object aDefault) | |
87 throws ConfigurationException { | |
88 | |
89 return getConfig().getEntry(BLITZ_MODULE, aName, aType, aDefault); | |
90 } | |
91 | |
92 public static synchronized Object getEntry(String aName, Class aType, | |
93 Object aDefault, Object aData) | |
94 throws ConfigurationException { | |
95 return getConfig().getEntry(BLITZ_MODULE, aName, aType, | |
96 aDefault, aData); | |
97 } | |
98 } |