View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.orchestra.lib.jsf;
20  
21  import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
22  
23  import javax.faces.FacesException;
24  import javax.faces.application.Application;
25  import javax.faces.application.NavigationHandler;
26  import javax.faces.application.StateManager;
27  import javax.faces.application.ViewHandler;
28  import javax.faces.component.UIComponent;
29  import javax.faces.context.FacesContext;
30  import javax.faces.convert.Converter;
31  import javax.faces.el.MethodBinding;
32  import javax.faces.el.PropertyResolver;
33  import javax.faces.el.ReferenceSyntaxException;
34  import javax.faces.el.ValueBinding;
35  import javax.faces.el.VariableResolver;
36  import javax.faces.event.ActionListener;
37  import javax.faces.validator.Validator;
38  import javax.el.ELResolver;
39  import javax.el.ValueExpression;
40  import javax.el.ExpressionFactory;
41  import javax.el.ELContextListener;
42  import javax.el.ELException;
43  import java.util.Collection;
44  import java.util.Iterator;
45  import java.util.Locale;
46  import java.util.ResourceBundle;
47  
48  /***
49   * Allows a better spring configuration, currently it allows one to:
50   * <ul>
51   *	<li>configure a converter in the spring configuration to get in use of the persistence dependency injections</li>
52   * </ul>
53   */
54  
55  // There is a technical problem here: Orchestra should be usable on both JSF1.1 and JSF1.2.
56  // Ideally we would compile against JSF1.1, and JSF1.2 would be backwards-compatible with it.
57  // Unfortunately, that is surprisingly hard to achieve. Any suggestions welcome!
58  // In the meantime, we compile against JSF1.2 then test against JSF1.1 to verify compatibility :-(.
59  
60  public class OrchestraApplication extends Application
61  {
62  	private final Application original;
63  
64  	public OrchestraApplication(Application original)
65  	{
66  		this.original = original;
67  	}
68  
69  	public Converter createConverter(String converterId)
70  	{
71  		try
72  		{
73  			return original.createConverter(converterId);
74  		}
75  		catch (FacesException e)
76  		{
77  			// looks like there is no converter configured, try to find a spring-configured one
78  			Converter converter = (Converter) FrameworkAdapter.getCurrentInstance().getBean(converterId);
79  			if (converter == null)
80  			{
81  				// no spring converter ... now re-throw the exception
82  				throw e;
83  			}
84  
85  			return new SerializableConverter(converterId, converter);
86  		}
87  	}
88  
89  	public Converter createConverter(Class aClass)
90  	{
91  		return original.createConverter(aClass);
92  	}
93  
94  	public Iterator getConverterIds()
95  	{
96  		return original.getConverterIds();
97  	}
98  
99  	public Iterator getConverterTypes()
100 	{
101 		return original.getConverterTypes();
102 	}
103 
104 	public MethodBinding createMethodBinding(String s, Class[] classes)
105 		throws ReferenceSyntaxException
106 	{
107 		return original.createMethodBinding(s, classes);
108 	}
109 
110 	public Iterator getSupportedLocales()
111 	{
112 		return original.getSupportedLocales();
113 	}
114 
115 	public void setSupportedLocales(Collection locales)
116 	{
117 		original.setSupportedLocales(locales);
118 	}
119 
120 	public void addValidator(String s, String s1)
121 	{
122 		original.addValidator(s, s1);
123 	}
124 
125 	public Validator createValidator(String s)
126 		throws FacesException
127 	{
128 		return original.createValidator(s);
129 	}
130 
131 	public Iterator getValidatorIds()
132 	{
133 		return original.getValidatorIds();
134 	}
135 
136 	public ValueBinding createValueBinding(String s)
137 		throws ReferenceSyntaxException
138 	{
139 		return original.createValueBinding(s);
140 	}
141 
142 	public void addELResolver(ELResolver elResolver)
143 	{
144 		original.addELResolver(elResolver);
145 	}
146 
147 	public ELResolver getELResolver()
148 	{
149 		return original.getELResolver();
150 	}
151 
152 	public ResourceBundle getResourceBundle(FacesContext facesContext, String s)
153 		throws FacesException, NullPointerException
154 	{
155 		return original.getResourceBundle(facesContext, s);
156 	}
157 
158 	public UIComponent createComponent(ValueExpression valueExpression, FacesContext facesContext, String s)
159 		throws FacesException, NullPointerException
160 	{
161 		return original.createComponent(valueExpression, facesContext, s);
162 	}
163 
164 	public ExpressionFactory getExpressionFactory()
165 	{
166 		return original.getExpressionFactory();
167 	}
168 
169 	public void addELContextListener(ELContextListener elContextListener)
170 	{
171 		original.addELContextListener(elContextListener);
172 	}
173 
174 	public void removeELContextListener(ELContextListener elContextListener)
175 	{
176 		original.removeELContextListener(elContextListener);
177 	}
178 
179 	public ELContextListener[] getELContextListeners()
180 	{
181 		return original.getELContextListeners();
182 	}
183 
184 	public Object evaluateExpressionGet(FacesContext facesContext, String s, Class aClass)
185 		throws ELException
186 	{
187 		return original.evaluateExpressionGet(facesContext, s, aClass);
188 	}
189 
190 	public ActionListener getActionListener()
191 	{
192 		return original.getActionListener();
193 	}
194 
195 	public void setActionListener(ActionListener actionListener)
196 	{
197 		original.setActionListener(actionListener);
198 	}
199 
200 	public Locale getDefaultLocale()
201 	{
202 		return original.getDefaultLocale();
203 	}
204 
205 	public void setDefaultLocale(Locale locale)
206 	{
207 		original.setDefaultLocale(locale);
208 	}
209 
210 	public String getDefaultRenderKitId()
211 	{
212 		return original.getDefaultRenderKitId();
213 	}
214 
215 	public void setDefaultRenderKitId(String s)
216 	{
217 		original.setDefaultRenderKitId(s);
218 	}
219 
220 	public String getMessageBundle()
221 	{
222 		return original.getMessageBundle();
223 	}
224 
225 	public void setMessageBundle(String s)
226 	{
227 		original.setMessageBundle(s);
228 	}
229 
230 	public NavigationHandler getNavigationHandler()
231 	{
232 		return original.getNavigationHandler();
233 	}
234 
235 	public void setNavigationHandler(NavigationHandler navigationHandler)
236 	{
237 		original.setNavigationHandler(navigationHandler);
238 	}
239 
240 	public PropertyResolver getPropertyResolver()
241 	{
242 		return original.getPropertyResolver();
243 	}
244 
245 	public void setPropertyResolver(PropertyResolver propertyResolver)
246 	{
247 		original.setPropertyResolver(propertyResolver);
248 	}
249 
250 	public VariableResolver getVariableResolver()
251 	{
252 		return original.getVariableResolver();
253 	}
254 
255 	public void setVariableResolver(VariableResolver variableResolver)
256 	{
257 		original.setVariableResolver(variableResolver);
258 	}
259 
260 	public ViewHandler getViewHandler()
261 	{
262 		return original.getViewHandler();
263 	}
264 
265 	public void setViewHandler(ViewHandler viewHandler)
266 	{
267 		original.setViewHandler(viewHandler);
268 	}
269 
270 	public StateManager getStateManager()
271 	{
272 		return original.getStateManager();
273 	}
274 
275 	public void setStateManager(StateManager stateManager)
276 	{
277 		original.setStateManager(stateManager);
278 	}
279 
280 	public void addComponent(String s, String s1)
281 	{
282 		original.addComponent(s, s1);
283 	}
284 
285 	public UIComponent createComponent(String s)
286 		throws FacesException
287 	{
288 		return original.createComponent(s);
289 	}
290 
291 	public UIComponent createComponent(ValueBinding valueBinding, FacesContext facesContext, String s)
292 		throws FacesException
293 	{
294 		return original.createComponent(valueBinding, facesContext, s);
295 	}
296 
297 	public Iterator getComponentTypes()
298 	{
299 		return original.getComponentTypes();
300 	}
301 
302 	public void addConverter(String s, String s1)
303 	{
304 		original.addConverter(s, s1);
305 	}
306 
307 	public void addConverter(Class aClass, String s)
308 	{
309 		original.addConverter(aClass, s);
310 	}
311 }