1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.webmacro.resource;
25
26 import org.webmacro.Broker;
27 import org.webmacro.InitException;
28 import org.webmacro.NotFoundException;
29 import org.webmacro.Provider;
30 import org.webmacro.util.Settings;
31
32 /***
33 * A very simple provider which simply takes the config information
34 * passed to it by the broker and returns it.
35 */
36 public class ConfigProvider implements Provider
37 {
38
39 private Settings _config;
40
41 public String getType ()
42 {
43 return "config";
44 }
45
46 public void init (Broker b, Settings config) throws InitException
47 {
48 _config = config;
49 if (_config == null)
50 {
51 throw new InitException("Attempt to init with no configuration");
52 }
53 }
54
55 public void flush ()
56 {
57 }
58
59 public void destroy ()
60 {
61 _config = null;
62 }
63
64 public Object get (String key) throws NotFoundException
65 {
66 Object o = _config.getSetting(key);
67 if (o == null)
68 {
69 throw new NotFoundException("No config information for: " + key);
70 }
71 return o;
72 }
73 }