KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infohazard > maverick > ctl > Throwaway


1 /*
2  * $Id: Throwaway.java,v 1.7 2003/10/27 11:00:39 thusted Exp $
3  * $Source: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/ctl/Throwaway.java,v $
4  */

5
6 package org.infohazard.maverick.ctl;
7
8 import org.infohazard.maverick.flow.Controller;
9 import org.infohazard.maverick.flow.ControllerContext;
10 import javax.servlet.*;
11 import javax.servlet.http.*;
12
13 /**
14  * Note: While not formally deprecated, use of this class is
15  * discouraged. You should use Throwaway2 instead.
16  *
17  * Throwaway is a base class for simple controllers which implements
18  * the single-use controller pattern (a fresh controller instance is
19  * created to service each request). No population of properties is
20  * performed by this class.
21  */

22 public abstract class Throwaway implements Controller
23 {
24     /**
25      * Common name for the typical "success" view.
26      */

27     public static final String JavaDoc SUCCESS = "success";
28
29     /**
30      * Common name for the typical "error" view.
31      */

32     public static final String JavaDoc ERROR = "error";
33
34     /**
35      */

36     private ControllerContext controllerCtx;
37     
38     /**
39      * Sets up the servlet parameters and calls through to the
40      * parameterless rawPerform() method. Does not result in
41      * bean population.
42      *
43      * @see Controller#go
44      */

45     public final String JavaDoc go(ControllerContext cctx) throws ServletException
46     {
47         try
48         {
49             this.controllerCtx = cctx;
50
51             String JavaDoc result = this.rawPerform();
52             
53             this.controllerCtx.setModel(this.model());
54             
55             return result;
56         }
57         catch (Exception JavaDoc ex)
58         {
59             throw new ServletException(ex);
60         }
61     }
62
63     /**
64      * This is the method you should override to implement application logic.
65      */

66     protected abstract String JavaDoc rawPerform() throws Exception JavaDoc;
67
68     /**
69      * This is the method you should override to return the data model after
70      * rawPerform() is executed.
71      */

72     public abstract Object JavaDoc model();
73     
74     /**
75      * @return the ControllerContext
76      */

77     protected ControllerContext getCtx()
78     {
79         return this.controllerCtx;
80     }
81
82     /**
83      * @return the servlet request object
84      */

85     protected HttpServletRequest getRequest()
86     {
87         return this.controllerCtx.getRequest();
88     }
89
90     /**
91      * @return the servlet response object
92      */

93     protected HttpServletResponse getResponse()
94     {
95         return this.controllerCtx.getResponse();
96     }
97
98     /**
99      * @return the servlet session
100      */

101     protected HttpSession getSession()
102     {
103         return this.getRequest().getSession();
104     }
105
106     /**
107      * @return the servlet configuration object
108      */

109     protected ServletConfig getServletConfig()
110     {
111         return this.controllerCtx.getServletConfig();
112     }
113
114     /**
115      * @return the webapp context object
116      */

117     protected ServletContext getServletContext()
118     {
119         return this.getServletConfig().getServletContext();
120     }
121 }
Popular Tags