1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.config; |
20 | |
|
21 | |
import java.util.ArrayList; |
22 | |
import java.util.Collection; |
23 | |
import java.util.Collections; |
24 | |
import java.util.HashMap; |
25 | |
import java.util.Map; |
26 | |
|
27 | |
import javax.el.CompositeELResolver; |
28 | |
import javax.el.ELResolver; |
29 | |
import javax.el.ExpressionFactory; |
30 | |
import javax.faces.context.ExternalContext; |
31 | |
import javax.faces.el.PropertyResolver; |
32 | |
import javax.faces.el.VariableResolver; |
33 | |
|
34 | |
import org.apache.commons.logging.Log; |
35 | |
import org.apache.commons.logging.LogFactory; |
36 | |
import org.apache.myfaces.config.element.ManagedBean; |
37 | |
import org.apache.myfaces.config.element.NavigationRule; |
38 | |
import org.apache.myfaces.config.impl.digester.elements.ResourceBundle; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
@SuppressWarnings("deprecation") |
49 | 0 | public class RuntimeConfig |
50 | |
{ |
51 | 0 | private static final Log log = LogFactory.getLog(RuntimeConfig.class); |
52 | |
|
53 | 0 | private static final String APPLICATION_MAP_PARAM_NAME = RuntimeConfig.class.getName(); |
54 | |
|
55 | 0 | private final Collection<NavigationRule> _navigationRules = new ArrayList<NavigationRule>(); |
56 | 0 | private final Map<String, ManagedBean> _managedBeans = new HashMap<String, ManagedBean>(); |
57 | 0 | private boolean _navigationRulesChanged = false; |
58 | 0 | private final Map<String, ResourceBundle> _resourceBundles = new HashMap<String, ResourceBundle>(); |
59 | 0 | private final Map<String, ManagedBean> _oldManagedBeans = new HashMap<String, ManagedBean>(); |
60 | |
|
61 | |
private CompositeELResolver facesConfigElResolvers; |
62 | |
private CompositeELResolver applicationElResolvers; |
63 | |
|
64 | |
private VariableResolver _variableResolver; |
65 | |
private PropertyResolver _propertyResolver; |
66 | |
|
67 | |
private ExpressionFactory _expressionFactory; |
68 | |
|
69 | |
private PropertyResolver _propertyResolverChainHead; |
70 | |
|
71 | |
private VariableResolver _variableResolverChainHead; |
72 | |
|
73 | |
public static RuntimeConfig getCurrentInstance(ExternalContext externalContext) |
74 | |
{ |
75 | 0 | RuntimeConfig runtimeConfig = (RuntimeConfig) externalContext.getApplicationMap().get( |
76 | |
APPLICATION_MAP_PARAM_NAME); |
77 | 0 | if (runtimeConfig == null) |
78 | |
{ |
79 | 0 | runtimeConfig = new RuntimeConfig(); |
80 | 0 | externalContext.getApplicationMap().put(APPLICATION_MAP_PARAM_NAME, runtimeConfig); |
81 | |
} |
82 | 0 | return runtimeConfig; |
83 | |
} |
84 | |
|
85 | |
public void purge() |
86 | |
{ |
87 | 0 | _navigationRules.clear(); |
88 | 0 | _oldManagedBeans.clear(); |
89 | 0 | _oldManagedBeans.putAll(_managedBeans); |
90 | 0 | _managedBeans.clear(); |
91 | 0 | _navigationRulesChanged = false; |
92 | 0 | } |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public Collection<NavigationRule> getNavigationRules() |
100 | |
{ |
101 | 0 | return Collections.unmodifiableCollection(_navigationRules); |
102 | |
} |
103 | |
|
104 | |
public void addNavigationRule(NavigationRule navigationRule) |
105 | |
{ |
106 | 0 | _navigationRules.add(navigationRule); |
107 | |
|
108 | 0 | _navigationRulesChanged = true; |
109 | 0 | } |
110 | |
|
111 | |
public boolean isNavigationRulesChanged() |
112 | |
{ |
113 | 0 | return _navigationRulesChanged; |
114 | |
} |
115 | |
|
116 | |
public void setNavigationRulesChanged(boolean navigationRulesChanged) |
117 | |
{ |
118 | 0 | _navigationRulesChanged = navigationRulesChanged; |
119 | 0 | } |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
public ManagedBean getManagedBean(String name) |
127 | |
{ |
128 | 0 | return _managedBeans.get(name); |
129 | |
} |
130 | |
|
131 | |
public Map<String, ManagedBean> getManagedBeans() |
132 | |
{ |
133 | 0 | return Collections.unmodifiableMap(_managedBeans); |
134 | |
} |
135 | |
|
136 | |
public void addManagedBean(String name, ManagedBean managedBean) |
137 | |
{ |
138 | 0 | _managedBeans.put(name, managedBean); |
139 | 0 | if(_oldManagedBeans!=null) |
140 | 0 | _oldManagedBeans.remove(name); |
141 | 0 | } |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public ResourceBundle getResourceBundle(String name) |
151 | |
{ |
152 | 0 | return _resourceBundles.get(name); |
153 | |
} |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
public Map<String, ResourceBundle> getResourceBundles() |
159 | |
{ |
160 | 0 | return _resourceBundles; |
161 | |
} |
162 | |
|
163 | |
public void addResourceBundle(ResourceBundle bundle) |
164 | |
{ |
165 | 0 | if (bundle == null) |
166 | |
{ |
167 | 0 | throw new IllegalArgumentException("bundle must not be null"); |
168 | |
} |
169 | 0 | String var = bundle.getVar(); |
170 | 0 | if (_resourceBundles.containsKey(var) && log.isWarnEnabled()) |
171 | |
{ |
172 | 0 | log.warn("Another resource bundle for var '" + var + "' with base name '" |
173 | |
+ _resourceBundles.get(var).getBaseName() + "' is already registered. '" |
174 | |
+ _resourceBundles.get(var).getBaseName() + "' will be replaced with '" + bundle.getBaseName() |
175 | |
+ "'."); |
176 | |
} |
177 | 0 | _resourceBundles.put(var, bundle); |
178 | 0 | } |
179 | |
|
180 | |
public void addFacesConfigElResolver(ELResolver resolver) |
181 | |
{ |
182 | 0 | if (facesConfigElResolvers == null) |
183 | |
{ |
184 | 0 | facesConfigElResolvers = new org.apache.myfaces.el.CompositeELResolver(); |
185 | |
} |
186 | 0 | facesConfigElResolvers.add(resolver); |
187 | 0 | } |
188 | |
|
189 | |
public ELResolver getFacesConfigElResolvers() |
190 | |
{ |
191 | 0 | return facesConfigElResolvers; |
192 | |
} |
193 | |
|
194 | |
public void addApplicationElResolver(ELResolver resolver) |
195 | |
{ |
196 | 0 | if (applicationElResolvers == null) |
197 | |
{ |
198 | 0 | applicationElResolvers = new org.apache.myfaces.el.CompositeELResolver(); |
199 | |
} |
200 | 0 | applicationElResolvers.add(resolver); |
201 | 0 | } |
202 | |
|
203 | |
public ELResolver getApplicationElResolvers() |
204 | |
{ |
205 | 0 | return applicationElResolvers; |
206 | |
} |
207 | |
|
208 | |
public void setVariableResolver(VariableResolver variableResolver) |
209 | |
{ |
210 | 0 | _variableResolver = variableResolver; |
211 | 0 | } |
212 | |
|
213 | |
public VariableResolver getVariableResolver() |
214 | |
{ |
215 | 0 | return _variableResolver; |
216 | |
} |
217 | |
|
218 | |
public void setPropertyResolver(PropertyResolver propertyResolver) |
219 | |
{ |
220 | 0 | _propertyResolver = propertyResolver; |
221 | 0 | } |
222 | |
|
223 | |
public PropertyResolver getPropertyResolver() |
224 | |
{ |
225 | 0 | return _propertyResolver; |
226 | |
} |
227 | |
|
228 | |
public ExpressionFactory getExpressionFactory() |
229 | |
{ |
230 | 0 | return _expressionFactory; |
231 | |
} |
232 | |
|
233 | |
public void setExpressionFactory(ExpressionFactory expressionFactory) |
234 | |
{ |
235 | 0 | _expressionFactory = expressionFactory; |
236 | 0 | } |
237 | |
|
238 | |
public void setPropertyResolverChainHead(PropertyResolver resolver) |
239 | |
{ |
240 | 0 | _propertyResolverChainHead = resolver; |
241 | 0 | } |
242 | |
|
243 | |
public PropertyResolver getPropertyResolverChainHead() |
244 | |
{ |
245 | 0 | return _propertyResolverChainHead; |
246 | |
} |
247 | |
|
248 | |
public void setVariableResolverChainHead(VariableResolver resolver) |
249 | |
{ |
250 | 0 | _variableResolverChainHead = resolver; |
251 | 0 | } |
252 | |
|
253 | |
public VariableResolver getVariableResolverChainHead() |
254 | |
{ |
255 | 0 | return _variableResolverChainHead; |
256 | |
} |
257 | |
|
258 | |
public Map getManagedBeansNotReaddedAfterPurge() |
259 | |
{ |
260 | 0 | return _oldManagedBeans; |
261 | |
} |
262 | |
|
263 | |
public void resetManagedBeansNotReaddedAfterPurge() |
264 | |
{ |
265 | 0 | _oldManagedBeans.clear(); |
266 | 0 | } |
267 | |
} |