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.el.convert;
20  
21  import javax.el.ELContext;
22  import javax.el.ELException;
23  import javax.el.ELResolver;
24  import javax.faces.context.FacesContext;
25  import javax.faces.el.EvaluationException;
26  import javax.faces.el.PropertyNotFoundException;
27  import javax.faces.el.PropertyResolver;
28  
29  /**
30   * 
31   * @author Stan Silvert
32   */
33  public final class ELResolverToPropertyResolver extends PropertyResolver
34  {
35  
36      private final ELResolver elResolver;
37  
38      /**
39       * Creates a new instance of ELResolverToPropertyResolver
40       */
41      public ELResolverToPropertyResolver(final ELResolver elResolver)
42      {
43          this.elResolver = elResolver;
44      }
45  
46      @Override
47      public boolean isReadOnly(final Object base, final int index)
48              throws EvaluationException, PropertyNotFoundException
49      {
50  
51          try
52          {
53              return elResolver.isReadOnly(elContext(), base, Integer.valueOf(index));
54          }
55          catch (javax.el.PropertyNotFoundException e)
56          {
57              throw new javax.faces.el.PropertyNotFoundException(e);
58          }
59          catch (ELException e)
60          {
61              throw new EvaluationException(e);
62          }
63  
64      }
65  
66      @Override
67      public boolean isReadOnly(final Object base, final Object property)
68              throws EvaluationException, PropertyNotFoundException
69      {
70  
71          try
72          {
73              return elResolver.isReadOnly(elContext(), base, property);
74          }
75          catch (javax.el.PropertyNotFoundException e)
76          {
77              throw new javax.faces.el.PropertyNotFoundException(e);
78          }
79          catch (ELException e)
80          {
81              throw new EvaluationException(e);
82          }
83  
84      }
85  
86      @Override
87      public Object getValue(final Object base, final int index) throws EvaluationException, PropertyNotFoundException
88      {
89  
90          try
91          {
92              return elResolver.getValue(elContext(), base, Integer.valueOf(index));
93          }
94          catch (javax.el.PropertyNotFoundException e)
95          {
96              throw new javax.faces.el.PropertyNotFoundException(e);
97          }
98          catch (ELException e)
99          {
100             throw new EvaluationException(e);
101         }
102 
103     }
104 
105     @Override
106     public Object getValue(final Object base, final Object property)
107             throws EvaluationException, PropertyNotFoundException
108     {
109 
110         try
111         {
112             return elResolver.getValue(elContext(), base, property);
113         }
114         catch (javax.el.PropertyNotFoundException e)
115         {
116             throw new javax.faces.el.PropertyNotFoundException(e);
117         }
118         catch (ELException e)
119         {
120             throw new EvaluationException(e);
121         }
122     }
123 
124     @Override
125     public Class getType(final Object base, int index) throws EvaluationException, PropertyNotFoundException
126     {
127 
128         try
129         {
130             return elResolver.getType(elContext(), base, Integer.valueOf(index));
131         }
132         catch (javax.el.PropertyNotFoundException e)
133         {
134             throw new javax.faces.el.PropertyNotFoundException(e);
135         }
136         catch (ELException e)
137         {
138             throw new EvaluationException(e);
139         }
140     }
141 
142     @Override
143     public Class getType(final Object base, final Object property)
144             throws EvaluationException, PropertyNotFoundException
145     {
146 
147         try
148         {
149             return elResolver.getType(elContext(), base, property);
150         }
151         catch (javax.el.PropertyNotFoundException e)
152         {
153             throw new javax.faces.el.PropertyNotFoundException(e);
154         }
155         catch (ELException e)
156         {
157             throw new EvaluationException(e);
158         }
159     }
160 
161     @Override
162     public void setValue(final Object base, final Object property, final Object value)
163             throws EvaluationException, PropertyNotFoundException
164     {
165 
166         try
167         {
168             elResolver.setValue(elContext(), base, property, value);
169         }
170         catch (javax.el.PropertyNotFoundException e)
171         {
172             throw new javax.faces.el.PropertyNotFoundException(e);
173         }
174         catch (ELException e)
175         {
176             throw new EvaluationException(e);
177         }
178     }
179 
180     @Override
181     public void setValue(final Object base, int index, final Object value)
182             throws EvaluationException, PropertyNotFoundException
183     {
184 
185         try
186         {
187             elResolver.setValue(elContext(), base, Integer.valueOf(index), value);
188         }
189         catch (javax.el.PropertyNotFoundException e)
190         {
191             throw new javax.faces.el.PropertyNotFoundException(e);
192         }
193         catch (ELException e)
194         {
195             throw new EvaluationException(e);
196         }
197 
198     }
199 
200     private ELContext elContext()
201     {
202         return FacesContext.getCurrentInstance().getELContext();
203     }
204 
205 }