KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > support > AbstractFlowAttributeMapper


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.engine.support;
17
18 import java.io.Serializable JavaDoc;
19
20 import org.springframework.binding.mapping.AttributeMapper;
21 import org.springframework.binding.mapping.MappingContext;
22 import org.springframework.webflow.core.collection.AttributeMap;
23 import org.springframework.webflow.core.collection.LocalAttributeMap;
24 import org.springframework.webflow.core.collection.MutableAttributeMap;
25 import org.springframework.webflow.engine.FlowAttributeMapper;
26 import org.springframework.webflow.execution.RequestContext;
27
28 /**
29  * Convenient base class for attribute mapper implementations. Encapsulates
30  * common attribute mapper workflow. Contains no state. Subclasses must override
31  * the {@link #getInputMapper()} and {@link #getOutputMapper()} methods to
32  * return the input mapper and output mapper, respectively.
33  *
34  * @author Keith Donald
35  */

36 public abstract class AbstractFlowAttributeMapper implements FlowAttributeMapper, Serializable JavaDoc {
37
38     /**
39      * Returns the input mapper to use to map attributes of a parent flow
40      * {@link RequestContext} to a subflow input attribute {@link AttributeMap map}.
41      * @return the input mapper, or null if none
42      * @see #createFlowInput(RequestContext)
43      */

44     protected abstract AttributeMapper getInputMapper();
45
46     /**
47      * Returns the output mapper to use to map attributes from a subflow output
48      * attribute map to the {@link RequestContext}.
49      * @return the output mapper, or null if none
50      * @see #mapFlowOutput(AttributeMap, RequestContext)
51      */

52     protected abstract AttributeMapper getOutputMapper();
53
54     public MutableAttributeMap createFlowInput(RequestContext context) {
55         if (getInputMapper() != null) {
56             LocalAttributeMap input = new LocalAttributeMap();
57             // map from request context to input map
58
getInputMapper().map(context, input, getMappingContext(context));
59             return input;
60         }
61         else {
62             // an empty, but modifiable map
63
return new LocalAttributeMap();
64         }
65     }
66
67     public void mapFlowOutput(AttributeMap subflowOutput, RequestContext context) {
68         if (getOutputMapper() != null && subflowOutput != null) {
69             // map from subflow output map to request context
70
getOutputMapper().map(subflowOutput, context, getMappingContext(context));
71         }
72     }
73
74     /**
75      * Returns a map of contextual data available during mapping.
76      * This implementation just returns null.
77      */

78     protected MappingContext getMappingContext(RequestContext context) {
79         return null;
80     }
81 }
Popular Tags