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 javax.faces.component;
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: * org.apache.myfaces.el.convert.MethodExpressionToMethodBinding
033: * accordingly.
034: *
035: * @author Stan Silvert
036: * @see org.apache.myfaces.el.convert.MethodExpressionToMethodBinding
037: */
038: class _MethodExpressionToMethodBinding extends MethodBinding implements
039: 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: } catch (ELException e) {
069: throw new EvaluationException(e);
070: }
071: }
072:
073: public Object invoke(FacesContext facesContext, Object[] params)
074: throws EvaluationException, MethodNotFoundException {
075:
076: try {
077: return methodExpression.invoke(facesContext.getELContext(),
078: params);
079: } catch (javax.el.MethodNotFoundException e) {
080: throw new javax.faces.el.MethodNotFoundException(e);
081: } catch (ELException e) {
082: throw new EvaluationException(e);
083: }
084: }
085:
086: // -------- StateHolder methods -------------------------------------------
087:
088: public void restoreState(FacesContext context, Object state) {
089: if (state != null)
090: methodExpression = (MethodExpression) state;
091: }
092:
093: public Object saveState(FacesContext context) {
094: if (!isTransient)
095: return methodExpression;
096: return null;
097: }
098:
099: public void setTransient(boolean newTransientValue) {
100: isTransient = newTransientValue;
101: }
102:
103: public boolean isTransient() {
104: return isTransient;
105: }
106:
107: }
|