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(MethodExpression methodExpression) {
48      this.methodExpression = methodExpression;
49    }
50  
51    @Override
52    public String getExpressionString() {
53      return methodExpression.getExpressionString();
54    }
55  
56    public Class getType(FacesContext facesContext)
57        throws MethodNotFoundException {
58  
59      try {
60        return methodExpression.getMethodInfo(facesContext.getELContext()).getReturnType();
61      } catch (javax.el.MethodNotFoundException e) {
62        throw new javax.faces.el.MethodNotFoundException(e);
63      } catch (ELException e) {
64        throw new EvaluationException(e);
65      }
66    }
67  
68    public Object invoke(FacesContext facesContext, Object[] params)
69        throws EvaluationException {
70  
71      try {
72        return methodExpression.invoke(facesContext.getELContext(), params);
73      } catch (javax.el.MethodNotFoundException e) {
74        throw new javax.faces.el.MethodNotFoundException(e);
75      } catch (ELException e) {
76        throw new EvaluationException(e);
77      }
78    }
79  
80  
81    public void restoreState(FacesContext context, Object state) {
82      if (state != null) {
83        methodExpression = (MethodExpression) state;
84      }
85    }
86  
87    public Object saveState(FacesContext context) {
88      if (!isTransient) {
89        return methodExpression;
90      }
91      return null;
92    }
93  
94    public void setTransient(boolean newTransientValue) {
95      isTransient = newTransientValue;
96    }
97  
98    public boolean isTransient() {
99      return isTransient;
100   }
101 
102 }