KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.jcorporate.expresso.core.controller.session.PersistentSession;
68 import com.jcorporate.expresso.core.db.DBException;
69 import com.jcorporate.expresso.core.dbobj.DBObject;
70 import com.jcorporate.expresso.core.misc.ConfigManager;
71 import com.jcorporate.expresso.core.misc.ConfigurationException;
72 import com.jcorporate.expresso.core.misc.StringUtil;
73 import com.jcorporate.expresso.core.security.User;
74 import com.jcorporate.expresso.kernel.util.ClassLocator;
75 import org.apache.log4j.Logger;
76 import org.apache.struts.Globals;
77
78 import java.io.Serializable JavaDoc;
79 import java.util.HashMap JavaDoc;
80 import java.util.Hashtable JavaDoc;
81 import java.util.Iterator JavaDoc;
82 import java.util.Locale JavaDoc;
83 import java.util.Map JavaDoc;
84
85
86 /**
87  * ControllerRequest is a simple "wrapper" object that holds the parameters and data required
88  * for a controller to be able to transition to a new state. <br />
89  * <b>Developer Notes</b> Because this class can be cloned, please make sure that
90  * you add any fields to this class to the clone function.
91  */

92 public class ControllerRequest
93         implements Serializable JavaDoc,
94         com.jcorporate.expresso.core.dbobj.RequestContext,
95         Cloneable JavaDoc {
96
97     private Hashtable JavaDoc params = null;
98     private Map JavaDoc initParams = null;
99     private Map JavaDoc objectParams = null;
100     private String JavaDoc userName = null;
101     private int uid = 0;
102     private String JavaDoc mySchema = null;
103     private Locale JavaDoc currentLocale = null;
104
105     /* The ActionForm session key for this request, if any ActionForm is specified */
106     private String JavaDoc formAttribute = null;
107
108     /* The name of the state which is the "initial" state of this controller */
109
110     /* E.g. where the controller starts if no state parameter is specified */
111     private String JavaDoc initialState = null;
112
113     /**
114      * Hashtable of the possibles states of this controller
115      */

116     // private Hashtable states = new Hashtable(3);
117
/**
118      * The attributes of this Controller object
119      */

120     private Map JavaDoc attributes = null;
121     private String JavaDoc dbName = null;
122
123     private static transient final Logger log = Logger.getLogger(ControllerRequest.class);
124
125
126     /**
127      * A PersistentSession object is a place to store attributes between states. It
128      * is used when an error collection is stored for use in a subsequent state.
129      * The exact mechanism used for this depends on the view mechanism being used
130      * and how it handles sessions, so we must be given a PersistentSession object
131      * in order to be able to store attributes
132      */

133     private PersistentSession mySession = null;
134
135     /* If any of our parameters as parsed from the request contained an uploaded file
136      * instead of just a string, then this hash contains the list of parameter names
137      * and associated uploaded filenames.
138      */

139     private Hashtable JavaDoc fileParams = null;
140
141     /**
142      * the formResponseCache allows user input to be saved, so it can
143      * be used later to prepopulate forms, etc.
144      */

145     private Hashtable JavaDoc formResponseCache = null;
146
147     /**
148      * Default Constructor. Initializes Logging
149      */

150     public ControllerRequest() {
151
152     } /* ControllerRequest() */
153
154
155     public void setFileParameter(String JavaDoc paramName, String JavaDoc paramValue,
156                                  String JavaDoc fileName)
157             throws ControllerException {
158         setParameter(paramName, paramValue);
159         StringUtil.assertNotBlank(fileName, "File name must not be blank here");
160
161         if (fileParams == null) {
162             fileParams = new Hashtable JavaDoc();
163         }
164
165         fileParams.put(paramName, fileName);
166     }
167
168     /**
169      * If a particular parameter represents an uploaded file (which can be determined
170      * by the isFileParameter(String) method) then this method retrieves the server-side
171      * file name - e.g. the location that has the data that was uploaded stored in it.
172      *
173      * @param paramName the name of the paramter to get the filename for.
174      * @return java.lang.String
175      */

176     public String JavaDoc getFileName(String JavaDoc paramName) {
177         if (isFileParameter(paramName)) {
178             return (String JavaDoc) fileParams.get(paramName);
179         } else {
180             return null;
181         }
182     }
183
184     /**
185      * Set the named attribute of this Controller to the given value
186      *
187      * @param attrib The name of an "attribtue" for this ControllerElement item
188      * @param val The value for this attribute
189      * @deprecated v5.5, 4/2004; use setAttrib() instead
190      */

191     public void setAttribute(String JavaDoc attrib, String JavaDoc val) {
192         if (attributes == null) {
193             attributes = new HashMap JavaDoc(3);
194         }
195
196         attributes.put(attrib, val);
197     } /* setAttributes(String, String) */
198
199     /**
200      * Set the named attribute to the given value
201      *
202      * @param attrib The name of an "attribtue" for this ControllerElement item
203      * @param val The value for this attribute
204      */

205     public void setAttrib(String JavaDoc attrib, Object JavaDoc val) {
206         if (attributes == null) {
207             attributes = new HashMap JavaDoc(3);
208         }
209
210         attributes.put(attrib, val);
211     } /* setAttributes(String, String) */
212
213     /**
214      * get the named attribute of this Controller
215      *
216      * @param attrib The name of an "attribute" for this ControllerElement item
217      * @return java.lang.String
218      * @deprecated v5.5, 4/2004; use getAttrib() instead, and cast to string
219      */

220     public String JavaDoc getAttribute(String JavaDoc attrib) {
221         if (attributes == null) {
222             return null;
223         } else {
224             return (String JavaDoc) attributes.get(attrib);
225         }
226     } /* setAttributes(String, String) */
227
228     /**
229      * get the named attribute of this Controller
230      *
231      * @param attrib The name of an "attribute" for this ControllerElement item
232      * @return java.lang.String
233      */

234     public Object JavaDoc getAttrib(String JavaDoc attrib) {
235         if (attributes == null) {
236             return null;
237         } else {
238             return attributes.get(attrib);
239         }
240     } /* setAttributes(String, String) */
241
242     /**
243      * Get the attributes Map
244      *
245      * @return java.util.Map of objects keyed by String.
246      * todo return new HashMap(attributes) to encapsulate the data member properly? // 4/04 LAH
247      */

248     public Map JavaDoc getAttributes() {
249         return attributes;
250     } /* getAttributes() */
251
252     /**
253      * Set the attributes Map to the supplied Map
254      *
255      * @param attributes a Map of attribute values
256      */

257     public void setAttributes(Map JavaDoc attributes) {
258         this.attributes = attributes;
259     } /* setAttributes(Map) */
260
261     /**
262      * remove the attribute
263      *
264      * @param key the name of the attribute to remove
265      */

266     public void removeAttrib(String JavaDoc key) {
267         attributes.remove(key);
268     }
269
270     /**
271      * Our caller can pass us initialization parameters. For example,
272      * if we're being called by a client that has information on connecting
273      * to a database, the connection parameters can be passed to us.
274      *
275      * @param paramName the name of the parameter
276      * @param paramValue the value of the parameter
277      */

278     public void setInitParameter(String JavaDoc paramName, String JavaDoc paramValue) {
279         if (initParams == null) {
280             initParams = new HashMap JavaDoc();
281         }
282
283         initParams.put(paramName, paramValue);
284     } /* setInitialParameter(String, String) */
285
286     /**
287      * @param paramName The name of the parameter
288      * @param paramValue The value of the parameter
289      * @throws ControllerException upon error
290      */

291     public void setParameter(String JavaDoc paramName, String JavaDoc paramValue)
292             throws ControllerException {
293         if (params == null) {
294             params = new Hashtable JavaDoc(10);
295         }
296         if (paramName == null) {
297             throw new ControllerException("Parameter name may not be null");
298         }
299         if (paramValue == null) {
300             throw new ControllerException("Parameter value may not be" +
301                     " null for parameter '" + paramName +
302                     "'");
303         }
304
305         params.put(paramName, paramValue);
306     } /* setParameter(String, String) */
307
308
309     /**
310      * Set a parameter as an object
311      *
312      * @param paramName The name of the parameter
313      * @param paramValue The value object
314      * @throws ControllerException upon error
315      */

316     public void setObjectParameter(String JavaDoc paramName, Object JavaDoc paramValue)
317             throws ControllerException {
318         StringUtil.assertNotBlank(paramName,
319                 "Parameter name may not be blank or null here");
320
321         if (paramValue == null) {
322             throw new IllegalArgumentException JavaDoc("Parameter value may not be null here");
323         }
324         if (objectParams == null) {
325             objectParams = new HashMap JavaDoc();
326         }
327
328         objectParams.put(paramName, paramValue);
329     } /* setObjectParameter(String, Object) */
330
331
332     /**
333      * @param paramName The name of the parameter to retrieve
334      * @return the Object retrieved from the object parameters list.
335      * @throws ControllerException if unable to get the object parameters
336      */

337     public Object JavaDoc getObjectParameter(String JavaDoc paramName)
338             throws ControllerException {
339         StringUtil.assertNotBlank(paramName,
340                 "Parameter name may not be blank or null here");
341
342         if (objectParams == null) {
343             return null;
344         } else {
345             return objectParams.get(paramName);
346         }
347     } /* getObjectParameter(String) */
348
349
350     /**
351      * Set the parameters for this request.
352      *
353      * @param h The hashtable for the bulk copies.
354      */

355     public void setParameters(Hashtable JavaDoc h) {
356
357         /* We can validate the parameters against the required parameters */
358
359         /* of a given state */
360         if (h != null) {
361             params = h;
362         } else {
363             params = new Hashtable JavaDoc(1);
364         }
365     } /* setParameters(Hashtable) */
366
367     /**
368      * The client of the controller must tell us who is accessing us,
369      * and we decide if they're allowed to access the given state.
370      *
371      * @param newUser The user's string id to set this user to.
372      */

373     public void setUser(String JavaDoc newUser) {
374         userName = newUser;
375     } /* setUser(String) */
376
377     /**
378      * Sets the current integer user id.
379      *
380      * @param newUid - the user ID integer to set this request to.
381      */

382     public void setUid(int newUid) {
383         uid = newUid;
384     }
385
386     /**
387      * Provide the controller with a PersitentSession object, which it can use
388      * to hold values between invokations. It is essential to use the PersistentSession
389      * rather than handing the controller the HTTPSession or HTTPServletRequest, for
390      * example, to preserve it's portability across all UI environments.
391      *
392      * @param newSession A PersistentSession object
393      */

394     public void setSession(PersistentSession newSession)
395             throws ControllerException {
396         if (newSession == null) {
397             throw new ControllerException("Cannot set a null PersistentSession object");
398         }
399
400         mySession = newSession;
401     } /* setSession(PersistentSession) */
402
403
404     /**
405      * Returns the Persistant Session Wrapper object to store requests between
406      * environments. Use this instead of HTTPSession or HTTPServletRequest
407      *
408      * @return a Persistant Session Object
409      * @throws ControllerException upon error
410      */

411     public PersistentSession getSession()
412             throws ControllerException {
413         if (mySession == null) {
414             throw new ControllerException("No PersistentSession object available");
415         }
416
417         return mySession;
418     }
419
420     /**
421      * Retrieve the initialization parameter
422      *
423      * @param paramName the name of the parameter to retrieve
424      * @return java.lang.String
425      */

426     public String JavaDoc getInitParameter(String JavaDoc paramName) {
427         if (initParams == null) {
428             return null;
429         } else {
430             return (String JavaDoc) initParams.get(paramName);
431         }
432     } /* getInitialParameter(String) */
433
434     /**
435      * Get the user name
436      *
437      * @return the currently logged in user or NONE if there's no user logged in
438      */

439     public String JavaDoc getUser() {
440         if (userName == null) {
441             return User.UNKNOWN_USER;
442         }
443
444         return userName;
445     } /* getUser() */
446
447     /**
448      * Get the user id as an integer
449      *
450      * @return an integer representing the internal UID
451      */

452     public int getUid() {
453         return uid;
454     }
455
456     /**
457      * Return the complete hashtable of parameters all keyed by parameter names
458      *
459      * @return a Hashtable containing all the parameter values, keyed by name; this is a CLONE of the source hashtable, not the original
460      */

461     public Hashtable JavaDoc getParameters() {
462         if (params != null) {
463             return (Hashtable JavaDoc) params.clone();
464         } else {
465             return new Hashtable JavaDoc();
466         }
467     } /* getParameters() */
468
469     /**
470      * Fetch the value for the given parameter. Return null
471      * if there is no such parameter
472      *
473      * @param paramCode Code of the parameter desired
474      * @return java.lang.String
475      */

476     public String JavaDoc getParameter(String JavaDoc paramCode) {
477         if (params == null) {
478             return null;
479         }
480
481         return (String JavaDoc) params.get(paramCode);
482     } /* getParameter(String) */
483
484
485     /**
486      * Does a specified parameter refer to an uploaded file?
487      *
488      * @param paramName the name of the parameter to check if it is a file
489      * @return boolean
490      */

491     public boolean isFileParameter(String JavaDoc paramName) {
492         if (fileParams == null) {
493             return false;
494         }
495         if (fileParams.containsKey(paramName)) {
496             return true;
497         }
498
499         return false;
500     } /* isFileParameter(String) */
501
502     /**
503      * Return the name of the database connection we use - or null
504      * for the default connection
505      *
506      * @return The current DBContext
507      * @deprecated 10/2004 v.5.6 use getDataContext instead
508      */

509     public String JavaDoc getDBName() {
510         if (StringUtil.notNull(dbName).equals("")) {
511             return "default";
512         }
513
514         return dbName;
515     } /* getDBName() */
516
517     /**
518      * Return the name of the database connection we use - or null
519      * for the default connection
520      *
521      * @return The current DBContext
522      */

523     public String JavaDoc getDataContext() {
524         if (StringUtil.notNull(dbName).equals("")) {
525             return "default";
526         }
527         return dbName;
528     }
529
530     /**
531      * Set this DB Controller to operate on a database other than the default
532      *
533      * @param newDBName The dbcontext to set this request to.
534      */

535     public synchronized void setDBName(String JavaDoc newDBName) {
536         if (StringUtil.notNull(newDBName).equals("")) {
537             dbName = "default";
538         } else {
539             dbName = newDBName;
540         }
541     } /* setDBName(String) */
542
543     /**
544      * Set this DB Controller to operate on a database other than the default
545      *
546      * @param newDBName The dbcontext to set this request to.
547      */

548     public synchronized void setDataContext(String JavaDoc newDBName) {
549         this.setDBName(newDBName);
550     }
551
552     /**
553      * Convenience method to populate a dbobject from the parameters supplied,
554      * by looking for parameters with the same name as the field name in the db object
555      *
556      * @param myDBObj the dbobject to populate
557      * @throws ControllerException upon error
558      */

559     public void populate(DBObject myDBObj)
560             throws ControllerException {
561         try {
562             String JavaDoc oneFieldName = null;
563
564             for (Iterator JavaDoc e = myDBObj.getJDBCMetaData().getFieldListArray().iterator()
565                     ; e.hasNext();) {
566                 oneFieldName = (String JavaDoc) e.next();
567
568                 if (getParameter(oneFieldName) != null) {
569                     myDBObj.setField(oneFieldName, getParameter(oneFieldName));
570                 }
571             } /* for each field */
572
573         } catch (DBException de) {
574             throw new ControllerException(de);
575         }
576     } /* addAutoInput(DBOBject) */
577
578
579     /**
580      * Returns the Error collection that exists in the current session.
581      *
582      * @return an ErrorCollection object or NULL if an error collection doesn't
583      * exist.
584      * @throws ControllerException if there is an error getting the Session object
585      */

586     public ErrorCollection getErrorCollection()
587             throws ControllerException {
588         ErrorCollection ec = (ErrorCollection) getSession().getAttribute(Globals.ERROR_KEY);
589
590 //
591
//We also now check the session.... if the error collection exists there,
592
//then we MOVE it to the request context, thus preventing lots of memory
593
//usage
594
//
595
if (ec == null) {
596 // retrieve errors from persistent attributes, if any
597
ec = (ErrorCollection) getSession().getPersistentAttribute(Globals.ERROR_KEY);
598
599 // move to active session
600
if (ec != null) {
601                 getSession().removePersistentAttribute(Globals.ERROR_KEY);
602                 getSession().setAttribute(Globals.ERROR_KEY, ec);
603             }
604         }
605
606         return ec;
607     }
608
609     public synchronized void setFormAttribute(String JavaDoc newAttribute) {
610         formAttribute = newAttribute;
611     }
612
613     public String JavaDoc getFormAttribute() {
614         return formAttribute;
615     }
616
617     /**
618      * Checks if the described parameter is a defined parameter
619      * for this request
620      *
621      * @param paramName the parameter to check against.
622      * @return true if the name given IS a valid defined parameter
623      */

624     public boolean isParameter(String JavaDoc paramName) {
625         Hashtable JavaDoc allParams = getParameters();
626
627         if (allParams == null) {
628             return false;
629         }
630
631         return allParams.containsKey(paramName);
632     }
633
634     /**
635      * Convenience method that retrieves parameters/field values and populates a specified
636      * db object. Once the object is populated, the fields are validated
637      * and the error collection populated if necessary.
638      *
639      * @param oneObject the object to validate
640      * @param ec The error collection that gets filled out.
641      * @throws ControllerException upon internal or data error
642      * @throws ValidationException if there is an error validating the object
643      */

644     public void validateDBObject(DBObject oneObject, ErrorCollection ec)
645             throws ControllerException, ValidationException {
646         try {
647             String JavaDoc oneFieldName = null;
648             for (Iterator JavaDoc af = oneObject.getMetaData().getFieldListArray().iterator(); af.hasNext();) {
649                 oneFieldName = (String JavaDoc) af.next();
650                 validateDBField(oneFieldName, oneObject, ec);
651             }
652         } catch (DBException de) {
653             throw new ControllerException(de);
654         }
655     } /* validateDBObj(DBObject, ErrorCollection) */
656
657
658     /**
659      * Convenience method that retrieves the validates
660      * against that one database object field. Assumes
661      * that the parameter name in the request is the same as the
662      * DB field name.
663      *
664      * @param dbFieldName the name of the field to validate
665      * @param oneObject the DBOBject to validate
666      * @param ec The ErrorCollection to fill out if there is an error
667      * @throws DBException upon data error
668      * @throws ControllerException upon internal error
669      */

670     public void validateDBField(String JavaDoc dbFieldName,
671                                 DBObject oneObject,
672                                 ErrorCollection ec)
673             throws ControllerException, DBException {
674
675         validateField(dbFieldName, dbFieldName, oneObject, ec);
676     }
677
678
679     /**
680      * Convenience method that retrieves the validates
681      * against that one database object field.
682      *
683      * @param dbFieldName the name of the field to validate
684      * @param reqFieldName ???
685      * @param oneObject the DBOBject to validate
686      * @param ec The ErrorCollection to fill out if there is an error
687      * @throws DBException upon data error
688      * @throws ControllerException upon internal error
689      */

690     public void validateField(String JavaDoc dbFieldName,
691                               String JavaDoc reqFieldName,
692                               DBObject oneObject,
693                               ErrorCollection ec)
694             throws ControllerException, DBException {
695
696         Hashtable JavaDoc allParams = getParameters();
697
698         if ((!oneObject.getMetaData().getFieldMetadata(dbFieldName).isReadOnly()) &&
699                 (!oneObject.getMetaData().getFieldMetadata(dbFieldName).isVirtual())) {
700             if (allParams.containsKey(reqFieldName)) {
701                 String JavaDoc oneFieldParam = getParameter(reqFieldName);
702
703                 try {
704                     oneObject.checkField(dbFieldName, oneFieldParam);
705                 } catch (DBException de) {
706                     if (log.isInfoEnabled()) {
707                         log.info("Validation error for field:", de);
708                     }
709
710                     ec.addError(de.getMessage());
711                 }
712
713                 oneObject.setField(dbFieldName, oneFieldParam);
714             }
715         }
716     }
717
718
719     /**
720      * Sets the Locale of this request
721      *
722      * @param newLocale the new Locale to set this request to.
723      */

724     public synchronized void setLocale(Locale JavaDoc newLocale) {
725         currentLocale = newLocale;
726     }
727
728     /**
729      * Returns the locale of this request.
730      *
731      * @return a Locale Object based upon current locale settings.
732      */

733     public Locale JavaDoc getLocale() {
734         if (currentLocale != null) {
735             return currentLocale;
736         }
737
738         Locale JavaDoc l = null;
739
740         try {
741             l = new Locale JavaDoc(ConfigManager.getContext(getDataContext()).getLanguage(),
742                     ConfigManager.getContext(getDataContext()).getCountry());
743         } catch (ConfigurationException ce) {
744             l = null;
745         }
746         if (l == null) {
747             l = Locale.getDefault();
748         }
749
750         return l;
751     }
752
753     /**
754      * Returns a clone of this object.
755      *
756      * @return a newly cloned ControllerRequest object.
757      */

758     public Object JavaDoc clone() {
759         Object JavaDoc o = null;
760         String JavaDoc className = this.getClass().getName();
761
762         try {
763             Class JavaDoc c = ClassLocator.loadClass(className);
764             o = c.newInstance();
765         } catch (ClassNotFoundException JavaDoc cn) {
766             throw new IllegalArgumentException JavaDoc("State object '" + className +
767                     "' not found");
768         } catch (InstantiationException JavaDoc ie) {
769             throw new IllegalArgumentException JavaDoc("State object '" + className +
770                     "' cannot be instantiated");
771         } catch (IllegalArgumentException JavaDoc e) {
772             throw new IllegalArgumentException JavaDoc("State object '" + className +
773                     "' cannot be instantiated (IllegalArgumentException)");
774         } catch (IllegalAccessException JavaDoc iae) {
775             throw new IllegalArgumentException JavaDoc("llegal access loading " +
776                     "State object '" + className +
777                     "'");
778         }
779         synchronized (this) {
780             ControllerRequest cr = (ControllerRequest) o;
781
782             if (this.attributes != null) {
783                 cr.attributes = new HashMap JavaDoc(this.attributes);
784             }
785
786             cr.currentLocale = this.currentLocale;
787             cr.dbName = this.dbName;
788
789             if (this.fileParams != null) {
790                 cr.fileParams = (Hashtable JavaDoc) this.fileParams.clone();
791             }
792
793             cr.formAttribute = this.formAttribute;
794
795             if (this.formResponseCache != null) {
796                 cr.formResponseCache = (Hashtable JavaDoc) this.formResponseCache.clone();
797             }
798
799             cr.initialState = this.initialState;
800
801             if (this.initParams != null) {
802                 cr.initParams = new HashMap JavaDoc(this.initParams);
803             }
804
805             cr.mySchema = this.mySchema;
806             cr.mySession = this.mySession;
807
808             if (this.objectParams != null) {
809                 cr.objectParams = new HashMap JavaDoc(this.objectParams);
810             }
811             if (this.params != null) {
812                 cr.params = (Hashtable JavaDoc) this.params.clone();
813             }
814
815             cr.uid = this.uid;
816             cr.userName = this.userName;
817         }
818
819         return o;
820     }
821
822     /**
823      * Remove a parameter from this controller request.
824      *
825      * @param paramName the name of the parameter to remove
826      */

827     public void removeParameter(String JavaDoc paramName) {
828         params.remove(paramName);
829     }
830
831
832     /**
833      * get requesting user
834      *
835      * @return user object for requesting user; will throw if UID is not found
836      */

837     public User getUserInfo() throws DBException {
838         return User.getUser(this);
839     }
840 } /* ControllerRequest */
841
Popular Tags