KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.springframework.binding.mapping.AttributeMapper;
19 import org.springframework.binding.mapping.MappingContext;
20 import org.springframework.util.Assert;
21 import org.springframework.webflow.execution.Event;
22 import org.springframework.webflow.execution.RequestContext;
23
24 /**
25  * Action that executes an attribute mapper to map information in the request
26  * context. Both the source and the target of the mapping will be the request
27  * context. This allows for maximum flexibility when defining attribute mapping
28  * expressions (e.g. "${flowScope.someAttribute}").
29  * <p>
30  * This action always returns the
31  * {@link org.springframework.webflow.action.AbstractAction#success() success}
32  * event. If something goes wrong while executing the mapping, an exception
33  * is thrown.
34  *
35  * @see org.springframework.binding.mapping.AttributeMapper
36  * @see org.springframework.webflow.execution.RequestContext
37  *
38  * @author Keith Donald
39  * @author Erwin Vervaet
40  */

41 public class AttributeMapperAction extends AbstractAction {
42
43     /**
44      * The attribute mapper strategy to delegate to perform the mapping.
45      */

46     private AttributeMapper attributeMapper;
47
48     /**
49      * Creates a new attribute mapper action that delegates to the configured
50      * attribute mapper to complete the mapping process.
51      * @param attributeMapper the mapper
52      */

53     public AttributeMapperAction(AttributeMapper attributeMapper) {
54         Assert.notNull(attributeMapper, "The attribute mapper is required");
55         this.attributeMapper = attributeMapper;
56     }
57
58     protected Event doExecute(RequestContext context) throws Exception JavaDoc {
59         // map attributes from and to the request context
60
attributeMapper.map(context, context, getMappingContext(context));
61         return success();
62     }
63
64     /**
65      * Returns a context containing extra data available during attribute mapping.
66      * The default implementation just returns null. Subclasses can
67      * override this if necessary.
68      */

69     protected MappingContext getMappingContext(RequestContext context) {
70         return null;
71     }
72 }
Popular Tags