1 /**************************************************************************
2 Copyright 2005 Webstersmalley
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
18
19 package com.webstersmalley.chessweb.web;
20
21 import java.io.IOException;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import javax.servlet.ServletException;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.springframework.web.servlet.ModelAndView;
32 import org.springframework.web.servlet.mvc.Controller;
33
34 import com.webstersmalley.chessweb.model.Board;
35
36 /***
37 * Main controller servlet for the game.
38 *
39 * @author Matthew Smalley
40 */
41 public final class GameController implements Controller {
42
43 /*** Logger for the class. */
44 private final Log logger = LogFactory.getLog(getClass());
45
46 /*** The all important board. * */
47 private Board board;
48
49 /***
50 * @return Returns the board.
51 */
52 public Board getBoard() {
53 return board;
54 }
55
56 /***
57 * @param board
58 * The board to set.
59 */
60 public void setBoard(final Board board) {
61 this.board = board;
62 }
63
64 /***
65 * Handles the request and forwards onto a model and view.
66 *
67 * @implements org.springframework.web.servlet.mvc.Controller.handleRequest
68 * @param request
69 * the request
70 * @param response
71 * the response
72 * @throws ServletException
73 * when there's servlet problems
74 * @throws IOException
75 * when there's IO problems
76 * @return ModelAndView the model and view.
77 */
78 public ModelAndView handleRequest(final HttpServletRequest request,
79 final HttpServletResponse response) throws ServletException,
80 IOException {
81 Map model = new HashMap();
82 model.put("board", board);
83 logger.info("Forwarding to jsp now");
84 return new ModelAndView("ShowBoard", "model", model);
85 }
86 }