KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > action > ActionResultExposer


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
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 JavaDoc {
35
36     /**
37      * The name of the attribute to index the return value with.
38      */

39     private String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc result, RequestContext context) {
79         resultScope.getScope(context).put(resultName, result);
80     }
81
82     public String JavaDoc toString() {
83         return new ToStringCreator(this).append("resultName", resultName).append("resultScope", resultScope).toString();
84     }
85 }
Popular Tags