View Javadoc

1   /*
2    * Copyright 2002-2004 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 net.sf.fridaymvc.controllers;
18  
19  import javax.servlet.http.HttpServletRequest;
20  import javax.servlet.http.HttpServletResponse;
21  
22  import net.sf.fridaymvc.RunData;
23  
24  import org.springframework.context.ApplicationContext;
25  import org.springframework.context.ApplicationContextAware;
26  import org.springframework.web.context.WebApplicationContext;
27  import org.springframework.web.servlet.ModelAndView;
28  import org.springframework.web.servlet.mvc.Controller;
29  
30  /***
31   * @author <a href="mailto:arto.pastinen@ofw.fi">Arto Pastinen</a>
32   * @version $Id: FridayController.java,v 1.2 2004/11/23 20:35:58 artsi Exp $
33   */
34  
35  public class FridayController implements Controller, ApplicationContextAware {
36      protected WebApplicationContext webApplicationContext;
37      protected RunData runData;
38      
39      /* (non-Javadoc)
40       * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
41       */
42      public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
43          RunData runData = getRunData();        
44          runData.setHttpServletRequest(httpServletRequest);
45          runData.setHttpServletResponse(httpServletResponse);        
46          runData.handleRequest();        
47          return null;        
48      }
49      /***
50       * @param webApplicationContext The webApplicationContext to set.
51       */
52      public void setApplicationContext(ApplicationContext applicationContext) {
53          this.webApplicationContext = (WebApplicationContext) applicationContext;
54      }
55      /***
56       * @return Returns the runData.
57       */
58      public RunData getRunData() {
59          if(this.runData == null) {
60              synchronized(this) {
61                  if(this.runData == null) {
62                      this.runData = new RunData();
63                      this.runData.setApplicationContext(this.webApplicationContext);
64                  }
65              }
66          }
67          return this.runData;
68      }
69      /***
70       * @param runData The runData to set.
71       */
72      public void setRunData(RunData runData) {
73          this.runData = runData;
74      }
75  }