1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.webscripts;
20
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.springframework.extensions.config.Config;
28 import org.springframework.extensions.config.ConfigElement;
29 import org.springframework.extensions.config.ConfigService;
30
31
32
33
34
35
36
37 public abstract class ConfigModel
38 {
39 protected ConfigService configService;
40 protected Map<String, ConfigElement> globalConfig;
41 protected String scriptConfig;
42
43 private static Log logger = LogFactory.getLog(ConfigModel.class);
44
45 public ConfigModel(ConfigService configService, String scriptConfig)
46 {
47 this.configService = configService;
48 this.scriptConfig = scriptConfig;
49
50 if (this.configService != null)
51 {
52
53 this.globalConfig = this.configService.getGlobalConfig().getConfigElements();
54 }
55
56
57 if (this.globalConfig == null)
58 {
59 this.globalConfig = Collections.emptyMap();
60 }
61 }
62
63
64
65
66
67
68 public Map<String, ConfigElement> getGlobal()
69 {
70 return this.globalConfig;
71 }
72
73
74
75
76
77
78 @SuppressWarnings("unchecked")
79 public Map<String, ConfigElement> getScoped()
80 {
81 return new ScopedConfigMap();
82 }
83
84
85
86
87
88
89
90 public abstract Object getScript();
91
92
93
94
95
96
97
98 @SuppressWarnings({ "unchecked", "serial" })
99 public class ScopedConfigMap extends HashMap
100 {
101 @Override
102 public Object get(Object identifier)
103 {
104 if (logger.isDebugEnabled())
105 logger.debug("Getting scoped config for '" + identifier + "'");
106
107 Map<String, ConfigElement> map = null;
108
109 if (configService != null)
110 {
111 Config result = configService.getConfig(identifier);
112 map = result.getConfigElements();
113 }
114 else
115 {
116 map = Collections.emptyMap();
117 }
118
119 if (logger.isDebugEnabled())
120 logger.debug("Returning config for '" + identifier + "': " + map);
121
122 return map;
123 }
124 }
125 }
126
127
128
129