01: /*
02: * Copyright 2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.myfaces.shared_impl.el;
17:
18: import javax.faces.component.StateHolder;
19: import javax.faces.context.FacesContext;
20: import javax.faces.el.EvaluationException;
21: import javax.faces.el.MethodBinding;
22: import javax.faces.el.MethodNotFoundException;
23:
24: /**
25: * Convenient method binding that does nothing other than returning a fixed outcome String when invoked.
26: *
27: * @author Manfred Geiler
28: */
29: public class SimpleActionMethodBinding extends MethodBinding implements
30: StateHolder {
31: private String _outcome;
32:
33: public SimpleActionMethodBinding(String outcome) {
34: _outcome = outcome;
35: }
36:
37: public Object invoke(FacesContext facescontext, Object aobj[])
38: throws EvaluationException, MethodNotFoundException {
39: return _outcome;
40: }
41:
42: public Class getType(FacesContext facescontext)
43: throws MethodNotFoundException {
44: return String.class;
45: }
46:
47: //~ StateHolder support ----------------------------------------------------------------------------
48:
49: private boolean _transient = false;
50:
51: /**
52: * Empty constructor, so that new instances can be created when restoring state.
53: */
54: public SimpleActionMethodBinding() {
55: _outcome = null;
56: }
57:
58: public Object saveState(FacesContext facescontext) {
59: return _outcome;
60: }
61:
62: public void restoreState(FacesContext facescontext, Object obj) {
63: _outcome = (String) obj;
64: }
65:
66: public boolean isTransient() {
67: return _transient;
68: }
69:
70: public void setTransient(boolean flag) {
71: _transient = flag;
72: }
73:
74: public String toString() {
75: return _outcome;
76: }
77: }
|