KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > jtrac > web > AbstractMultiActionController


1 /*
2  * Copyright 2002-2005 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
17 package info.jtrac.web;
18
19 import info.jtrac.Jtrac;
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
26 import org.springframework.webflow.context.ExternalContext;
27 import org.springframework.webflow.context.ExternalContextHolder;
28 import org.springframework.webflow.context.servlet.ServletExternalContext;
29 import org.springframework.webflow.execution.FlowExecution;
30 import org.springframework.webflow.execution.repository.FlowExecutionRepository;
31 import org.springframework.webflow.executor.FlowExecutor;
32 import org.springframework.webflow.executor.FlowExecutorImpl;
33
34 /**
35  * base class for all Spring MVC MultiActionControllers
36  * also contains code for getting hold of a Spring WebFlow context
37  * from request, response
38  */

39 public abstract class AbstractMultiActionController extends MultiActionController {
40     
41     protected final Log logger = LogFactory.getLog(getClass());
42     
43     protected Jtrac jtrac;
44     private FlowExecutionRepository repository;
45     
46     public void setJtrac(Jtrac jtrac) {
47         this.jtrac = jtrac;
48     }
49
50     public void setFlowExecutor(FlowExecutor flowExecutor) {
51         FlowExecutorImpl executor = (FlowExecutorImpl) flowExecutor;
52         this.repository = executor.getExecutionRepository();
53     }
54     
55     /**
56      * this is the bridge between the Spring WebFlow world and the Spring MVC world
57      * needed for getting access to "stateful" objects within a flow
58      */

59     protected FlowExecution getFlowExecution(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
60         ExternalContext externalContext = new ServletExternalContext(getServletContext(), request, response);
61         ExternalContextHolder.setExternalContext(externalContext);
62         String JavaDoc flowExecutionKey = request.getParameter("_flowExecutionKey");
63         return repository.getFlowExecution(repository.parseFlowExecutionKey(flowExecutionKey));
64     }
65     
66 }
67
Popular Tags