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.custom.facelets.tag;
20  
21  import java.io.Serializable;
22  
23  import javax.el.ELException;
24  import javax.el.MethodExpression;
25  import javax.faces.context.FacesContext;
26  import javax.faces.el.EvaluationException;
27  import javax.faces.el.MethodBinding;
28  import javax.faces.el.MethodNotFoundException;
29  
30  public final class LegacyMethodBinding extends MethodBinding implements
31          Serializable
32  {
33  
34      private static final long serialVersionUID = 1L;
35  
36      private final MethodExpression m;
37  
38      public LegacyMethodBinding(MethodExpression m)
39      {
40          this.m = m;
41      }
42  
43      public Class getType(FacesContext context) throws MethodNotFoundException
44      {
45          try
46          {
47              return m.getMethodInfo(context.getELContext()).getReturnType();
48          }
49          catch (javax.el.MethodNotFoundException e)
50          {
51              throw new MethodNotFoundException(e.getMessage(), e.getCause());
52          }
53          catch (ELException e)
54          {
55              throw new EvaluationException(e.getMessage(), e.getCause());
56          }
57      }
58  
59      public Object invoke(FacesContext context, Object[] params)
60              throws EvaluationException, MethodNotFoundException
61      {
62          try
63          {
64              return m.invoke(context.getELContext(), params);
65          }
66          catch (javax.el.MethodNotFoundException e)
67          {
68              throw new MethodNotFoundException(e.getMessage(), e.getCause());
69          }
70          catch (ELException e)
71          {
72              throw new EvaluationException(e.getMessage(), e.getCause());
73          }
74      }
75  
76      public String getExpressionString()
77      {
78          return m.getExpressionString();
79      }
80  }