01: /*
02: * Copyright 2004-2007 the original author or authors.
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.springframework.webflow.action;
17:
18: import java.io.Serializable;
19:
20: import org.springframework.core.style.ToStringCreator;
21: import org.springframework.util.Assert;
22: import org.springframework.webflow.execution.RequestContext;
23: import org.springframework.webflow.execution.ScopeType;
24:
25: /**
26: * Specifies how an action result value should be exposed to an executing flow.
27: * The return value is exposed as an attribute in a configured scope.
28: *
29: * @see EvaluateAction
30: * @see AbstractBeanInvokingAction
31: *
32: * @author Keith Donald
33: */
34: public class ActionResultExposer implements Serializable {
35:
36: /**
37: * The name of the attribute to index the return value with.
38: */
39: private String resultName;
40:
41: /**
42: * The scope of the attribute indexing the return value.
43: */
44: private ScopeType resultScope;
45:
46: /**
47: * Creates a action result exposer
48: * @param resultName the result name
49: * @param resultScope the result scope
50: */
51: public ActionResultExposer(String resultName, ScopeType resultScope) {
52: Assert.notNull(resultName, "The result name is required");
53: Assert.notNull(resultScope, "The result scope is required");
54: this .resultName = resultName;
55: this .resultScope = resultScope;
56: }
57:
58: /**
59: * Returns name of the attribute to index the return value with.
60: */
61: public String getResultName() {
62: return resultName;
63: }
64:
65: /**
66: * Returns the scope the attribute indexing the return value.
67: */
68: public ScopeType getResultScope() {
69: return resultScope;
70: }
71:
72: /**
73: * Expose given bean method return value in given flow execution request
74: * context.
75: * @param result the return value
76: * @param context the request context
77: */
78: public void exposeResult(Object result, RequestContext context) {
79: resultScope.getScope(context).put(resultName, result);
80: }
81:
82: public String toString() {
83: return new ToStringCreator(this ).append("resultName",
84: resultName).append("resultScope", resultScope)
85: .toString();
86: }
87: }
|