KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > Action


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;
8
9
10 import javax.servlet.http.HttpServletRequest JavaDoc;
11 import javax.servlet.http.HttpServletResponse JavaDoc;
12 import javax.servlet.http.HttpSession JavaDoc;
13
14 import com.inversoft.verge.util.RequestContext;
15
16
17 /**
18  * <p>
19  * This class is the base class for all Actions used in
20  * controller part of the Inversoft MVC
21  * </p>
22  *
23  * @author Brian Pontarelli
24  * @since 2.0
25  * @version 2.0
26  */

27 public class Action {
28
29     private HttpServletRequest JavaDoc request;
30     private HttpServletResponse JavaDoc response;
31     private Object JavaDoc action;
32     private RequestContext requestContext;
33
34
35     /**
36      * Creates a new <code>Action</code>
37      */

38     public Action(Object JavaDoc action, HttpServletRequest JavaDoc request,
39             HttpServletResponse JavaDoc response) {
40         this.action = action;
41         this.request = request;
42         this.response = response;
43         this.requestContext = new RequestContext(request);
44     }
45
46     /**
47      * Creates a new <code>Action</code>
48      */

49     public Action(Object JavaDoc action, HttpServletRequest JavaDoc request,
50             HttpServletResponse JavaDoc response, RequestContext requestContext) {
51         this.action = action;
52         this.request = request;
53         this.response = response;
54         this.requestContext = requestContext;
55     }
56
57
58     /**
59      * Gets the http servlet request object
60      *
61      * @return The HttpServletRequest
62      */

63     public HttpServletRequest JavaDoc getHttpServletRequest() {
64         return request;
65     }
66     
67     /**
68      * Detaches the HttpServletRequest so that circular references do not cause
69      * a memory leak.
70      */

71     public void detachHttpServletRequest() {
72         request = null;
73     }
74     
75     /**
76      * Gets the http servlet response object
77      *
78      * @return The HttpServletResponse
79      */

80     public HttpServletResponse JavaDoc getHttpServletResponse() {
81         return response;
82     }
83
84     /**
85      * Convenience method that retrieves the HttpSession from the HttpServletRequest
86      *
87      * @return The HttpSession
88      */

89     public HttpSession JavaDoc getHttpSession() {
90         return request.getSession();
91     }
92     
93     /**
94      * Gets the action that generated this event. Normally this is the name of
95      * the handle method de-capitalized in the JavaBean style. For example, if
96      * this form event is passed to the handleLogin method, then the action would
97      * be 'login'. This event can be any object though. For example, it could be
98      * an exception.
99      */

100     public Object JavaDoc getAction() {
101         return action;
102     }
103
104     /**
105      * Sets the action that generated this event. Normally this is the name of
106      * the handle method de-capitalized in the JavaBean style. For example, if
107      * this form event is passed to the handleLogin method, then the action would
108      * be 'login'. This event can be any object though. For example, it could be
109      * an exception.
110      */

111     protected void setAction(Object JavaDoc action) {
112         this.action = action;
113     }
114
115     /**
116      * Returns the RequestContext for this request
117      *
118      * @return The RequestContext object for this request
119      */

120     public RequestContext getRequestContext() {
121         return requestContext;
122     }
123 }
Popular Tags