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 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,
55: "The attribute mapper is required");
56: this .attributeMapper = attributeMapper;
57: }
58:
59: protected Event doExecute(RequestContext context) throws Exception {
60: // map attributes from and to the request context
61: attributeMapper.map(context, context,
62: getMappingContext(context));
63: return success();
64: }
65:
66: /**
67: * Returns a context containing extra data available during attribute mapping.
68: * The default implementation just returns null. Subclasses can
69: * override this if necessary.
70: */
71: protected MappingContext getMappingContext(RequestContext context) {
72: return null;
73: }
74: }
|