01: /*
02: * Copyright 2006 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.myfaces.el.convert;
18:
19: import javax.el.ELException;
20: import javax.el.ELResolver;
21: import javax.el.PropertyNotFoundException;
22: import javax.faces.context.FacesContext;
23: import javax.faces.el.EvaluationException;
24: import javax.faces.el.VariableResolver;
25:
26: /**
27: * Provides ELResolver wrapper so that legacy apps which rely on a
28: * VariableResolver can still work.
29: *
30: * @author Stan Silvert
31: */
32: public class ELResolverToVariableResolver extends VariableResolver {
33:
34: private ELResolver elResolver;
35:
36: /**
37: * Creates a new instance of ELResolverToVariableResolver
38: */
39: public ELResolverToVariableResolver(ELResolver elResolver) {
40: if (elResolver == null)
41: throw new NullPointerException();
42: this .elResolver = elResolver;
43: }
44:
45: public Object resolveVariable(FacesContext facesContext, String name)
46: throws EvaluationException {
47:
48: try {
49: return elResolver.getValue(facesContext.getELContext(),
50: null, name);
51: } catch (PropertyNotFoundException e) {
52: throw new EvaluationException(e);
53: } catch (ELException e) {
54: throw new EvaluationException(e);
55: }
56: }
57:
58: }
|