KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > actionflow > ActionFlowControllerHandler


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.controller.actionflow;
8
9
10 import javax.servlet.http.HttpServletRequest JavaDoc;
11 import javax.servlet.http.HttpServletResponse JavaDoc;
12
13 import com.inversoft.verge.mvc.MVCConstants;
14 import com.inversoft.verge.mvc.MVCException;
15 import com.inversoft.verge.mvc.MVCRequest;
16 import com.inversoft.verge.mvc.controller.ControllerHandler;
17 import com.inversoft.verge.mvc.controller.Result;
18 import com.inversoft.verge.mvc.controller.actionflow.config.ActionFlowConfigStruct;
19 import com.inversoft.verge.mvc.controller.actionflow.config.Node;
20 import com.inversoft.verge.mvc.controller.actionflow.config.RenderableNode;
21
22
23 /**
24  * <p>
25  * This class is the controller handler implementation for
26  * the ActionFlow system. Since the {@link ActionFlowExecutor
27  * ActionFlowExecutor} uses the HttpServletRequest to
28  * determine execution, this class is just a delegate. It
29  * passes the HttpServletRequest, HttpServletResponse and
30  * extra parameters passed to the handle method.
31  * </p>
32  *
33  * @author Brian Pontarelli
34  * @since 2.0
35  * @version 2.0
36  */

37 public class ActionFlowControllerHandler implements ControllerHandler {
38
39     /**
40      * Allows the ActionFlow system to turn on and off the model and the validation.
41      *
42      * @param mvcRequest The MVCRequest to setup
43      * @throws com.inversoft.verge.mvc.MVCException If there were any problems during setting
44      */

45     public void preExecute(MVCRequest mvcRequest) throws MVCException {
46
47         HttpServletRequest JavaDoc request = mvcRequest.getRequest();
48         ActionFlowMetaData md = ActionFlowURLTools.decodeURL(
49             mvcRequest.getControllerInfo().getURLValues());
50         if (md.getAction() == null) {
51             ActionFlowURLTools.locateAction(request, md);
52         }
53
54         // Set the model and validation switches
55
mvcRequest.setModelEnabled(md.isModelEnabled());
56         mvcRequest.setValidationEnabled(md.isValidationEnabled());
57
58         // Create the action and store it
59
HttpServletResponse JavaDoc response = mvcRequest.getResponse();
60         ActionFlowAction afa = new ActionFlowAction(md.getAction(), request,
61             response, null, mvcRequest.getRequestContext());
62         mvcRequest.setAction(afa);
63
64         // Get the action flow meta data and the form meta data and store it
65
ActionFlowConfigStruct config = new ActionFlowConfigStruct(null, md);
66
67         if (md.getForm() != null && md.getNamespace() != null) {
68             config.baseFormConfig = config.actionFlowMetaData.findFormConfig(request);
69             mvcRequest.addValidatorHandlerToCall(MVCConstants.ACTIONFLOW_NAME);
70         }
71
72         mvcRequest.setConfiguration(config);
73     }
74
75     /**
76      * Delegate control to the ActionFlowExecutor
77      */

78     public Result execute(MVCRequest mvcRequest) throws MVCException {
79         HttpServletRequest JavaDoc request = mvcRequest.getRequest();
80         HttpServletResponse JavaDoc response = mvcRequest.getResponse();
81         ActionFlowConfigStruct config =
82             (ActionFlowConfigStruct) mvcRequest.getConfiguration();
83
84         // Execute the action flow. This may error out if anything is invalid
85
String JavaDoc namespace = config.actionFlowMetaData.getNamespace();
86         Node node = null;
87
88         // Determine if the action is from a failure or from the request
89
if (config.failedValidatorConfig != null) {
90             node = ActionFlowExecutor.execute(request, response, namespace,
91                 config.actionFlowMetaData.getEntry(),
92                 config.failedValidatorConfig.getFailureDefinition(), null);
93         } else {
94             node = ActionFlowExecutor.execute(request, response, namespace,
95                 config.actionFlowMetaData.getEntry(),
96                 (ActionFlowAction) mvcRequest.getAction());
97         }
98
99         Result result = null;
100         if (node != null && node instanceof RenderableNode) {
101             result = (RenderableNode) node;
102         }
103
104         return result;
105     }
106 }
Popular Tags