001: /*
002: * Copyright 2006 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.myfaces.el.convert;
018:
019: import javax.el.ELException;
020: import javax.el.MethodExpression;
021: import javax.faces.component.StateHolder;
022: import javax.faces.context.FacesContext;
023: import javax.faces.el.EvaluationException;
024: import javax.faces.el.MethodBinding;
025: import javax.faces.el.MethodNotFoundException;
026:
027: /**
028: * Converts a MethodExpression to a MethodBinding.
029: * See JSF 1.2 spec section 5.8.4
030: *
031: * ATTENTION: If you make changes to this class, treat
032: * javax.faces.component._MethodExpressionToMethodBinding
033: * accordingly.
034: *
035: * @author Stan Silvert
036: * @see javax.faces.component._MethodExpressionToMethodBinding
037: */
038: public class MethodExpressionToMethodBinding extends MethodBinding
039: implements StateHolder {
040:
041: private MethodExpression methodExpression;
042:
043: private boolean isTransient = false;
044:
045: public MethodExpressionToMethodBinding() {
046: methodExpression = null;
047: }
048:
049: /** Creates a new instance of MethodExpressionToMethodBinding */
050: public MethodExpressionToMethodBinding(
051: MethodExpression methodExpression) {
052: this .methodExpression = methodExpression;
053: }
054:
055: @Override
056: public String getExpressionString() {
057: return methodExpression.getExpressionString();
058: }
059:
060: public Class getType(FacesContext facesContext)
061: throws MethodNotFoundException {
062:
063: try {
064: return methodExpression.getMethodInfo(
065: facesContext.getELContext()).getReturnType();
066: } catch (javax.el.MethodNotFoundException e) {
067: throw new javax.faces.el.MethodNotFoundException(e);
068: }
069: }
070:
071: public Object invoke(FacesContext facesContext, Object[] params)
072: throws EvaluationException, MethodNotFoundException {
073:
074: try {
075: return methodExpression.invoke(facesContext.getELContext(),
076: params);
077: } catch (javax.el.MethodNotFoundException e) {
078: throw new javax.faces.el.MethodNotFoundException(e);
079: } catch (ELException e) {
080: throw new EvaluationException(e.getCause());
081: }
082: }
083:
084: // -------- StateHolder methods -------------------------------------------
085:
086: public void restoreState(FacesContext context, Object state) {
087: methodExpression = (MethodExpression) state;
088: }
089:
090: public Object saveState(FacesContext context) {
091: return methodExpression;
092: }
093:
094: public void setTransient(boolean newTransientValue) {
095: isTransient = newTransientValue;
096: }
097:
098: public boolean isTransient() {
099: return isTransient;
100: }
101:
102: }
|