KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > core > controller > ServletControllerResponse


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.core.controller;
66
67 import org.apache.struts.action.ActionForward;
68 import org.apache.struts.action.ActionMapping;
69
70
71 /**
72  * A ServletControllerResponse object is an extension that provides
73  * wide access to the pure Struts API and Servlet environment.
74  * For example you may want to generate dynamic <code>ActionForwards</code>
75  * or retrieve access to the <code>ActionMapping</code> class.
76  * <p/>
77  * <pre>
78  * public AcmeController extends DBController {
79  * <p/>
80  * protected void runProcessOrderState(
81  * ControllerRequest req,
82  * ControllerRequest res )
83  * {
84  * ServletControllerRequest request =
85  * (ServletControllerRequest)req;
86  * ActionMapping mapping = request.getMapping();
87  * <p/>
88  * ServletControllerResponse request =
89  * (ServletControllerRequest)req;
90  * ActionMapping mapping = response.getMapping();
91  * <p/>
92  * <p/>
93  * // ... after processing this state ...
94  * <p/>
95  * <p/>
96  * response.setActionForward(
97  * new ActionForward( ... ));
98  * <p/>
99  * // OR
100  * <p/>
101  * response.setActionForward(
102  * repsonse.findForward( "logical-forward-name" ));
103  * <p/>
104  * // OR
105  * <p/>
106  * response.setFindForwardStore( "logical-forward-name" );
107  * <p/>
108  * // OR
109  * <p/>
110  * response.setForwardName( "logical-forward-name" );
111  * // equivalent to
112  * response.setStyle( "logical-forward-name" )
113  * }
114  * ...
115  * }
116  * </pre>
117  *
118  * @author Peter Pilgrim, Fri Nov 22 03:11:09 GMT 2002
119  * @version $Id: ServletControllerResponse.java,v 1.6 2004/11/17 20:48:06 lhamel Exp $
120  */

121 public class ServletControllerResponse extends ControllerResponse {
122     /**
123      * The associated action forward
124      */

125     protected ActionForward myForward = null;
126
127     /**
128      * Default constructor for the servlet controller response
129      */

130     public ServletControllerResponse() {
131         super();
132     }
133
134     /**
135      * Gets the ActionMapping associated with the controller .
136      * Functionally to equivalent to
137      * <code> ((ServletControllerRequest)getRequest()).getMapping() </code>
138      *
139      * @throws ClassCastException if the associated controller request object
140      * is not a <code>ServletControllerRequest</code> type.
141      * @throws ControllerException if there is no associated controller
142      * request object at all.
143      * @see ServletControllerRequest#getMapping
144      */

145     public ActionMapping getMapping()
146             throws ControllerException {
147         ServletControllerRequest req = (ServletControllerRequest) getRequest();
148         return req.getMapping();
149     }
150
151     /**
152      * Gets the action forward that the controller should forward or redirect to
153      *
154      * @return forward the action forward object
155      * @see #setActionForward
156      */

157     public ActionForward getActionForward() {
158         return myForward;
159     }
160
161     /**
162      * Sets the action forward that the controller should forward or redirect to
163      *
164      * @param forward the action forward object
165      * @see #getActionForward
166      */

167     public void setActionForward(ActionForward forward) {
168         this.myForward = forward;
169     }
170
171     /**
172      * Searches for the action forward associated with the action mapping
173      * (controller). A convenience function for pure Struts programmer
174      * function equivalent to
175      * <code>getMapping().findForward("{logical-forward-name}")</code>
176      *
177      * @param forwardName the logical name of the action forward
178      * @return ActionForward with matching logical name or <code>null</code>
179      * if none can be found.
180      * @throws ClassCastException if the associated controller request object
181      * is not a <code>ServletControllerRequest</code> type.
182      * @throws ControllerException if there is no associated controller
183      * request object at all.
184      * @see getMapping()
185      */

186     public ActionForward findForward(String JavaDoc forwardName)
187             throws ControllerException {
188         return getMapping().findForward(forwardName);
189     }
190
191
192     /**
193      * Searches for the action forward associated with the action mapping
194      * (controller), with the side-effect of storing the action forward
195      * in the controller response.
196      * <p/>
197      * <p/>
198      * Functionally equivalent to
199      * <code>
200      * setActionForward( getMapping().findForward( "{logical-fwd-name}" ))
201      * </code>
202      *
203      * @param forwardName the logical name of the action forward
204      * @return ActionForward with matching logical name or <code>null</code>
205      * if none can be found.
206      * @throws ClassCastException if the associated controller request object
207      * is not a <code>ServletControllerRequest</code> type.
208      * @throws ControllerException if there is no associated controller
209      * request object at all.
210      * @see getMapping()
211      */

212     public ActionForward findForwardStore(String JavaDoc forwardName)
213             throws ControllerException {
214         ActionForward fwd = getMapping().findForward(forwardName);
215         setActionForward(fwd);
216         return fwd;
217     }
218
219     /**
220      * Gets the logical name of the action forward that the controller
221      * should forward or redirect to. This is an <em>alias</em> for
222      * <code>setStyle</code> method. It makes a lot more sense
223      * to pure Struts developers who moving upto Expresso.
224      * Functionally equivalent to <code>setStyle()</code>
225      *
226      * @return the logical name of the action forward
227      * @see #setForwardName
228      * @see ControllerResponse#getStyle
229      */

230     public String JavaDoc getForwardName() {
231         return getStyle();
232     }
233
234     /**
235      * Sets the logical name of the action forward that the controller
236      * should forward or redirect to. This is an <em>alias</em> for
237      * <code>setStyle</code> method. It makes a lot more sense
238      * to pure Struts developers who moving upto Expresso.
239      * Functionally equivalent to <code>setStyle()</code>
240      *
241      * @param forwardName the logical name of the action forward
242      * @see #getForwardName
243      * @see ControllerResponse#setStyle
244      */

245     public void setForwardName(String JavaDoc forwardName) {
246         setStyle(forwardName);
247     }
248
249 }
250
Popular Tags