KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > ActionExecutor


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;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.springframework.webflow.execution.Action;
21 import org.springframework.webflow.execution.Event;
22 import org.springframework.webflow.execution.RequestContext;
23
24 /**
25  * A simple static helper that performs action execution that encapsulates
26  * common logging and exception handling logic. This is an internal helper class
27  * that is not normally used by application code.
28  *
29  * @author Keith Donald
30  * @author Erwin Vervaet
31  */

32 public class ActionExecutor {
33
34     private static final Log logger = LogFactory.getLog(ActionExecutor.class);
35
36     /**
37      * Private constructor to avoid instantiation.
38      */

39     private ActionExecutor() {
40     }
41
42     /**
43      * Execute the given action.
44      * @param action the action to execute
45      * @param context the flow execution request context
46      * @return result of action execution
47      * @throws ActionExecutionException if the action threw an exception while
48      * executing, the orginal exception is available as the cause if this exception
49      */

50     public static Event execute(Action action, RequestContext context) throws ActionExecutionException {
51         try {
52             if (logger.isDebugEnabled()) {
53                 if (context.getCurrentState() == null) {
54                     logger.debug("Executing start " + action + " for flow '" + context.getActiveFlow().getId() + "'");
55                 }
56                 else {
57                     logger.debug("Executing " + action + " in state '" + context.getCurrentState().getId()
58                             + "' of flow '" + context.getActiveFlow().getId() + "'");
59                 }
60             }
61             return action.execute(context);
62         }
63         catch (ActionExecutionException e) {
64             throw e;
65         }
66         catch (Exception JavaDoc e) {
67             // wrap the action as an ActionExecutionException
68
throw new ActionExecutionException(context.getActiveFlow().getId(),
69                     context.getCurrentState() != null ? context.getCurrentState().getId() : null, action, context
70                             .getAttributes(), e);
71         }
72     }
73 }
Popular Tags