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  
20  package org.apache.myfaces.tobago.component;
21  
22  import javax.el.ELException;
23  import javax.el.MethodExpression;
24  import javax.faces.component.StateHolder;
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  /**
31   * @deprecated since 2.0.0
32   */
33  @Deprecated
34  public class MethodExpressionToMethodBinding extends MethodBinding implements StateHolder {
35  
36    private MethodExpression methodExpression;
37  
38    private boolean isTransient = false;
39  
40    public MethodExpressionToMethodBinding() {
41      methodExpression = null;
42    }
43  
44    /**
45     * Creates a new instance of MethodExpressionToMethodBinding
46     */
47    public MethodExpressionToMethodBinding(final MethodExpression methodExpression) {
48      this.methodExpression = methodExpression;
49    }
50  
51    @Override
52    public String getExpressionString() {
53      return methodExpression.getExpressionString();
54    }
55  
56    @Override
57    public Class getType(final FacesContext facesContext)
58        throws MethodNotFoundException {
59  
60      try {
61        return methodExpression.getMethodInfo(facesContext.getELContext()).getReturnType();
62      } catch (final javax.el.MethodNotFoundException e) {
63        throw new javax.faces.el.MethodNotFoundException(e);
64      } catch (final ELException e) {
65        throw new EvaluationException(e);
66      }
67    }
68  
69    @Override
70    public Object invoke(final FacesContext facesContext, final Object[] params)
71        throws EvaluationException {
72  
73      try {
74        return methodExpression.invoke(facesContext.getELContext(), params);
75      } catch (final javax.el.MethodNotFoundException e) {
76        throw new javax.faces.el.MethodNotFoundException(e);
77      } catch (final ELException e) {
78        throw new EvaluationException(e);
79      }
80    }
81  
82  
83    @Override
84    public void restoreState(final FacesContext context, final Object state) {
85      if (state != null) {
86        methodExpression = (MethodExpression) state;
87      }
88    }
89  
90    @Override
91    public Object saveState(final FacesContext context) {
92      if (!isTransient) {
93        return methodExpression;
94      }
95      return null;
96    }
97  
98    @Override
99    public void setTransient(final boolean newTransientValue) {
100     isTransient = newTransientValue;
101   }
102 
103   @Override
104   public boolean isTransient() {
105     return isTransient;
106   }
107 
108 }