001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jsf.el;
030:
031: import javax.el.*;
032: import javax.faces.application.*;
033: import javax.faces.component.*;
034: import javax.faces.context.*;
035: import javax.faces.el.*;
036:
037: public class MethodBindingAdapter extends MethodBinding implements
038: StateHolder {
039: private MethodExpression _expr;
040: private Class[] _param;
041:
042: public MethodBindingAdapter() {
043: }
044:
045: public MethodBindingAdapter(MethodExpression expr, Class[] param) {
046: _expr = expr;
047: _param = param;
048: }
049:
050: public String getExpressionString() {
051: return _expr.getExpressionString();
052: }
053:
054: @Deprecated
055: public Object invoke(FacesContext context, Object[] param)
056: throws EvaluationException,
057: javax.faces.el.MethodNotFoundException {
058: if (context == null)
059: throw new NullPointerException();
060:
061: try {
062: return _expr.invoke(context.getELContext(), param);
063: } catch (javax.el.MethodNotFoundException e) {
064: throw new javax.faces.el.MethodNotFoundException(e);
065: } catch (ELException e) {
066: if (e.getCause() != null)
067: throw new EvaluationException(e.getCause());
068: else
069: throw new EvaluationException(e);
070: } catch (Exception e) {
071: throw new EvaluationException(e);
072: }
073: }
074:
075: @Deprecated
076: public Class getType(FacesContext context)
077: throws EvaluationException,
078: javax.faces.el.PropertyNotFoundException {
079: try {
080: MethodInfo info = _expr.getMethodInfo(context
081: .getELContext());
082:
083: return info.getReturnType();
084: } catch (javax.el.MethodNotFoundException e) {
085: throw new javax.faces.el.MethodNotFoundException(e);
086: } catch (RuntimeException e) {
087: throw e;
088: } catch (Exception e) {
089: throw new EvaluationException(e);
090: }
091: }
092:
093: public Object saveState(FacesContext context) {
094: ELContext elContext = context.getELContext();
095:
096: String expr = _expr.getExpressionString();
097:
098: return new Object[] { expr, _param };
099: }
100:
101: public void restoreState(FacesContext context, Object value) {
102: Object[] state = (Object[]) value;
103:
104: Application app = context.getApplication();
105: ELContext elContext = context.getELContext();
106: ExpressionFactory factory = app.getExpressionFactory();
107:
108: String expr = (String) state[0];
109: Class[] param = (Class[]) state[1];
110:
111: _expr = factory.createMethodExpression(context.getELContext(),
112: expr, Object.class, param);
113: _param = param;
114: }
115:
116: public boolean isTransient() {
117: return false;
118: }
119:
120: public void setTransient(boolean isTransient) {
121: }
122:
123: public String toString() {
124: return "MethodBindingAdapter[" + _expr.getExpressionString()
125: + "]";
126: }
127: }
|