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) throws EvaluationException, PropertyNotFoundException
48      {
49  
50          try
51          {
52              return elResolver.isReadOnly(elContext(), base, Integer.valueOf(index));
53          }
54          catch (javax.el.PropertyNotFoundException e)
55          {
56              throw new javax.faces.el.PropertyNotFoundException(e);
57          }
58          catch (ELException e)
59          {
60              throw new EvaluationException(e);
61          }
62  
63      }
64  
65      @Override
66      public boolean isReadOnly(final Object base, final Object property) throws EvaluationException, PropertyNotFoundException
67      {
68  
69          try
70          {
71              return elResolver.isReadOnly(elContext(), base, property);
72          }
73          catch (javax.el.PropertyNotFoundException e)
74          {
75              throw new javax.faces.el.PropertyNotFoundException(e);
76          }
77          catch (ELException e)
78          {
79              throw new EvaluationException(e);
80          }
81  
82      }
83  
84      @Override
85      public Object getValue(final Object base, final int index) throws EvaluationException, PropertyNotFoundException
86      {
87  
88          try
89          {
90              return elResolver.getValue(elContext(), base, Integer.valueOf(index));
91          }
92          catch (javax.el.PropertyNotFoundException e)
93          {
94              throw new javax.faces.el.PropertyNotFoundException(e);
95          }
96          catch (ELException e)
97          {
98              throw new EvaluationException(e);
99          }
100 
101     }
102 
103     @Override
104     public Object getValue(final Object base, final Object property) throws EvaluationException, PropertyNotFoundException
105     {
106 
107         try
108         {
109             return elResolver.getValue(elContext(), base, property);
110         }
111         catch (javax.el.PropertyNotFoundException e)
112         {
113             throw new javax.faces.el.PropertyNotFoundException(e);
114         }
115         catch (ELException e)
116         {
117             throw new EvaluationException(e);
118         }
119     }
120 
121     @Override
122     public Class getType(final Object base, int index) throws EvaluationException, PropertyNotFoundException
123     {
124 
125         try
126         {
127             return elResolver.getType(elContext(), base, Integer.valueOf(index));
128         }
129         catch (javax.el.PropertyNotFoundException e)
130         {
131             throw new javax.faces.el.PropertyNotFoundException(e);
132         }
133         catch (ELException e)
134         {
135             throw new EvaluationException(e);
136         }
137     }
138 
139     @Override
140     public Class getType(final Object base, final Object property) throws EvaluationException, PropertyNotFoundException
141     {
142 
143         try
144         {
145             return elResolver.getType(elContext(), base, property);
146         }
147         catch (javax.el.PropertyNotFoundException e)
148         {
149             throw new javax.faces.el.PropertyNotFoundException(e);
150         }
151         catch (ELException e)
152         {
153             throw new EvaluationException(e);
154         }
155     }
156 
157     @Override
158     public void setValue(final Object base, final Object property, final Object value) throws EvaluationException,
159                                                                                       PropertyNotFoundException
160     {
161 
162         try
163         {
164             elResolver.setValue(elContext(), base, property, value);
165         }
166         catch (javax.el.PropertyNotFoundException e)
167         {
168             throw new javax.faces.el.PropertyNotFoundException(e);
169         }
170         catch (ELException e)
171         {
172             throw new EvaluationException(e);
173         }
174     }
175 
176     @Override
177     public void setValue(final Object base, int index, final Object value) throws EvaluationException, PropertyNotFoundException
178     {
179 
180         try
181         {
182             elResolver.setValue(elContext(), base, Integer.valueOf(index), value);
183         }
184         catch (javax.el.PropertyNotFoundException e)
185         {
186             throw new javax.faces.el.PropertyNotFoundException(e);
187         }
188         catch (ELException e)
189         {
190             throw new EvaluationException(e);
191         }
192 
193     }
194 
195     private ELContext elContext()
196     {
197         return FacesContext.getCurrentInstance().getELContext();
198     }
199 
200 }