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.webflow.action.MultiAction.MethodResolver;
19: import org.springframework.webflow.execution.RequestContext;
20:
21: /**
22: * Default method resolver used by the MultiAction class. It uses the following
23: * algorithm to calculate a method name:
24: * <ol>
25: * <li>If the currently executing action has a "method" property defined, use
26: * the value as method name.</li>
27: * <li>Else use the name of the current state of the flow execution as a method
28: * name.</li>
29: * </ol>
30: *
31: * @see org.springframework.webflow.action.MultiAction
32: *
33: * @author Erwin Vervaet
34: */
35: public class DefaultMultiActionMethodResolver implements MethodResolver {
36:
37: public String resolveMethod(RequestContext context) {
38: // implementation note: not using AnnotatedAction.METHOD_ATTRIBUTE since
39: // that resides in the engine subsystem
40: String method = context.getAttributes().getString("method");
41: if (method == null) {
42: if (context.getCurrentState() != null) {
43: // default to the state id
44: method = context.getCurrentState().getId();
45: } else {
46: throw new IllegalStateException(
47: "Unable to resolve action method; no 'method' context attribute set");
48: }
49: }
50: return method;
51: }
52: }
|