Source Code Cross Referenced for ControllerRequest.java in  » J2EE » Expresso » com » jcorporate » expresso » core » controller » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Expresso » com.jcorporate.expresso.core.controller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003:         *
004:         * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * 1. Redistributions of source code must retain the above copyright
011:         *    notice, this list of conditions and the following disclaimer.
012:         *
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in
015:         *    the documentation and/or other materials provided with the
016:         *    distribution.
017:         *
018:         * 3. The end-user documentation included with the redistribution,
019:         *    if any, must include the following acknowledgment:
020:         *       "This product includes software developed by Jcorporate Ltd.
021:         *        (http://www.jcorporate.com/)."
022:         *    Alternately, this acknowledgment may appear in the software itself,
023:         *    if and wherever such third-party acknowledgments normally appear.
024:         *
025:         * 4. "Jcorporate" and product names such as "Expresso" must
026:         *    not be used to endorse or promote products derived from this
027:         *    software without prior written permission. For written permission,
028:         *    please contact info@jcorporate.com.
029:         *
030:         * 5. Products derived from this software may not be called "Expresso",
031:         *    or other Jcorporate product names; nor may "Expresso" or other
032:         *    Jcorporate product names appear in their name, without prior
033:         *    written permission of Jcorporate Ltd.
034:         *
035:         * 6. No product derived from this software may compete in the same
036:         *    market space, i.e. framework, without prior written permission
037:         *    of Jcorporate Ltd. For written permission, please contact
038:         *    partners@jcorporate.com.
039:         *
040:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043:         * DISCLAIMED.  IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044:         * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046:         * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051:         * SUCH DAMAGE.
052:         * ====================================================================
053:         *
054:         * This software consists of voluntary contributions made by many
055:         * individuals on behalf of the Jcorporate Ltd. Contributions back
056:         * to the project(s) are encouraged when you make modifications.
057:         * Please send them to support@jcorporate.com. For more information
058:         * on Jcorporate Ltd. and its products, please see
059:         * <http://www.jcorporate.com/>.
060:         *
061:         * Portions of this software are based upon other open source
062:         * products and are subject to their respective licenses.
063:         */
064:
065:        package com.jcorporate.expresso.core.controller;
066:
067:        import com.jcorporate.expresso.core.controller.session.PersistentSession;
068:        import com.jcorporate.expresso.core.db.DBException;
069:        import com.jcorporate.expresso.core.dbobj.DBObject;
070:        import com.jcorporate.expresso.core.misc.ConfigManager;
071:        import com.jcorporate.expresso.core.misc.ConfigurationException;
072:        import com.jcorporate.expresso.core.misc.StringUtil;
073:        import com.jcorporate.expresso.core.security.User;
074:        import com.jcorporate.expresso.kernel.util.ClassLocator;
075:        import org.apache.log4j.Logger;
076:        import org.apache.struts.Globals;
077:
078:        import java.io.Serializable;
079:        import java.util.HashMap;
080:        import java.util.Hashtable;
081:        import java.util.Iterator;
082:        import java.util.Locale;
083:        import java.util.Map;
084:
085:        /**
086:         * ControllerRequest is a simple "wrapper" object that holds the parameters and data required
087:         * for a controller to be able to transition to a new state. <br />
088:         * <b>Developer Notes</b> Because this class can be cloned, please make sure that
089:         * you add any fields to this class to the clone function.
090:         */
091:        public class ControllerRequest implements  Serializable,
092:                com.jcorporate.expresso.core.dbobj.RequestContext, Cloneable {
093:
094:            private Hashtable params = null;
095:            private Map initParams = null;
096:            private Map objectParams = null;
097:            private String userName = null;
098:            private int uid = 0;
099:            private String mySchema = null;
100:            private Locale currentLocale = null;
101:
102:            /* The ActionForm session key for this request, if any ActionForm is specified */
103:            private String formAttribute = null;
104:
105:            /* The name of the state which is the "initial" state of this controller */
106:
107:            /* E.g. where the controller starts if no state parameter is specified */
108:            private String initialState = null;
109:
110:            /**
111:             * Hashtable of the possibles states of this controller
112:             */
113:            //    private Hashtable states = new Hashtable(3);
114:            /**
115:             * The attributes of this Controller object
116:             */
117:            private Map attributes = null;
118:            private String dbName = null;
119:
120:            private static transient final Logger log = Logger
121:                    .getLogger(ControllerRequest.class);
122:
123:            /**
124:             * A PersistentSession object is a place to store attributes between states. It
125:             * is used when an error collection is stored for use in a subsequent state.
126:             * The exact mechanism used for this depends on the view mechanism being used
127:             * and how it handles sessions, so we must be given a PersistentSession object
128:             * in order to be able to store attributes
129:             */
130:            private PersistentSession mySession = null;
131:
132:            /* If any of our parameters as parsed from the request contained an uploaded file
133:             * instead of just a string, then this hash contains the list of parameter names
134:             * and associated uploaded filenames.
135:             */
136:            private Hashtable fileParams = null;
137:
138:            /**
139:             * the formResponseCache allows user input to be saved, so it can
140:             * be used later to prepopulate forms, etc.
141:             */
142:            private Hashtable formResponseCache = null;
143:
144:            /**
145:             * Default Constructor.  Initializes Logging
146:             */
147:            public ControllerRequest() {
148:
149:            } /* ControllerRequest() */
150:
151:            public void setFileParameter(String paramName, String paramValue,
152:                    String fileName) throws ControllerException {
153:                setParameter(paramName, paramValue);
154:                StringUtil.assertNotBlank(fileName,
155:                        "File name must not be blank here");
156:
157:                if (fileParams == null) {
158:                    fileParams = new Hashtable();
159:                }
160:
161:                fileParams.put(paramName, fileName);
162:            }
163:
164:            /**
165:             * If a particular parameter represents an uploaded file (which can be determined
166:             * by the isFileParameter(String) method) then this method retrieves the server-side
167:             * file name - e.g. the location that has the data that was uploaded stored in it.
168:             *
169:             * @param paramName the name of the paramter to get the filename for.
170:             * @return java.lang.String
171:             */
172:            public String getFileName(String paramName) {
173:                if (isFileParameter(paramName)) {
174:                    return (String) fileParams.get(paramName);
175:                } else {
176:                    return null;
177:                }
178:            }
179:
180:            /**
181:             * Set the named attribute of this Controller to the given value
182:             *
183:             * @param attrib The name of an "attribtue" for this ControllerElement item
184:             * @param val    The value for this attribute
185:             * @deprecated v5.5, 4/2004; use setAttrib() instead
186:             */
187:            public void setAttribute(String attrib, String val) {
188:                if (attributes == null) {
189:                    attributes = new HashMap(3);
190:                }
191:
192:                attributes.put(attrib, val);
193:            } /* setAttributes(String, String) */
194:
195:            /**
196:             * Set the named attribute to the given value
197:             *
198:             * @param attrib The name of an "attribtue" for this ControllerElement item
199:             * @param val    The value for this attribute
200:             */
201:            public void setAttrib(String attrib, Object val) {
202:                if (attributes == null) {
203:                    attributes = new HashMap(3);
204:                }
205:
206:                attributes.put(attrib, val);
207:            } /* setAttributes(String, String) */
208:
209:            /**
210:             * get the named attribute of this Controller
211:             *
212:             * @param attrib The name of an "attribute" for this ControllerElement item
213:             * @return java.lang.String
214:             * @deprecated v5.5, 4/2004; use getAttrib() instead, and cast to string
215:             */
216:            public String getAttribute(String attrib) {
217:                if (attributes == null) {
218:                    return null;
219:                } else {
220:                    return (String) attributes.get(attrib);
221:                }
222:            } /* setAttributes(String, String) */
223:
224:            /**
225:             * get the named attribute of this Controller
226:             *
227:             * @param attrib The name of an "attribute" for this ControllerElement item
228:             * @return java.lang.String
229:             */
230:            public Object getAttrib(String attrib) {
231:                if (attributes == null) {
232:                    return null;
233:                } else {
234:                    return attributes.get(attrib);
235:                }
236:            } /* setAttributes(String, String) */
237:
238:            /**
239:             * Get the attributes Map
240:             *
241:             * @return java.util.Map of objects keyed by String.
242:             *         todo return new HashMap(attributes) to encapsulate the data member properly?  // 4/04 LAH
243:             */
244:            public Map getAttributes() {
245:                return attributes;
246:            } /* getAttributes() */
247:
248:            /**
249:             * Set the attributes Map to the supplied Map
250:             *
251:             * @param attributes a Map of attribute values
252:             */
253:            public void setAttributes(Map attributes) {
254:                this .attributes = attributes;
255:            } /* setAttributes(Map) */
256:
257:            /**
258:             * remove the attribute
259:             *
260:             * @param key the name of the attribute to remove
261:             */
262:            public void removeAttrib(String key) {
263:                attributes.remove(key);
264:            }
265:
266:            /**
267:             * Our caller can pass us initialization parameters. For example,
268:             * if we're being called by a client that has information on connecting
269:             * to a database, the connection parameters can be passed to us.
270:             *
271:             * @param paramName  the name of the parameter
272:             * @param paramValue the value of the parameter
273:             */
274:            public void setInitParameter(String paramName, String paramValue) {
275:                if (initParams == null) {
276:                    initParams = new HashMap();
277:                }
278:
279:                initParams.put(paramName, paramValue);
280:            } /* setInitialParameter(String, String) */
281:
282:            /**
283:             * @param paramName  The name of the parameter
284:             * @param paramValue The value of the parameter
285:             * @throws ControllerException upon error
286:             */
287:            public void setParameter(String paramName, String paramValue)
288:                    throws ControllerException {
289:                if (params == null) {
290:                    params = new Hashtable(10);
291:                }
292:                if (paramName == null) {
293:                    throw new ControllerException(
294:                            "Parameter name may not be null");
295:                }
296:                if (paramValue == null) {
297:                    throw new ControllerException("Parameter value may not be"
298:                            + " null for parameter '" + paramName + "'");
299:                }
300:
301:                params.put(paramName, paramValue);
302:            } /* setParameter(String, String) */
303:
304:            /**
305:             * Set a parameter as an object
306:             *
307:             * @param paramName  The name of the parameter
308:             * @param paramValue The value object
309:             * @throws ControllerException upon error
310:             */
311:            public void setObjectParameter(String paramName, Object paramValue)
312:                    throws ControllerException {
313:                StringUtil.assertNotBlank(paramName,
314:                        "Parameter name may not be blank or null here");
315:
316:                if (paramValue == null) {
317:                    throw new IllegalArgumentException(
318:                            "Parameter value may not be null here");
319:                }
320:                if (objectParams == null) {
321:                    objectParams = new HashMap();
322:                }
323:
324:                objectParams.put(paramName, paramValue);
325:            } /* setObjectParameter(String, Object) */
326:
327:            /**
328:             * @param paramName The name of the parameter to retrieve
329:             * @return the Object retrieved from the object parameters list.
330:             * @throws ControllerException if unable to get the object parameters
331:             */
332:            public Object getObjectParameter(String paramName)
333:                    throws ControllerException {
334:                StringUtil.assertNotBlank(paramName,
335:                        "Parameter name may not be blank or null here");
336:
337:                if (objectParams == null) {
338:                    return null;
339:                } else {
340:                    return objectParams.get(paramName);
341:                }
342:            } /* getObjectParameter(String) */
343:
344:            /**
345:             * Set the parameters for this request.
346:             *
347:             * @param h The hashtable for the bulk copies.
348:             */
349:            public void setParameters(Hashtable h) {
350:
351:                /* We can validate the parameters against the required parameters */
352:
353:                /* of a given state */
354:                if (h != null) {
355:                    params = h;
356:                } else {
357:                    params = new Hashtable(1);
358:                }
359:            } /* setParameters(Hashtable) */
360:
361:            /**
362:             * The client of the controller must tell us who is accessing us,
363:             * and we decide if they're allowed to access the given state.
364:             *
365:             * @param newUser The user's string id to set this user to.
366:             */
367:            public void setUser(String newUser) {
368:                userName = newUser;
369:            } /* setUser(String) */
370:
371:            /**
372:             * Sets the current integer user id.
373:             *
374:             * @param newUid - the user ID integer to set this request to.
375:             */
376:            public void setUid(int newUid) {
377:                uid = newUid;
378:            }
379:
380:            /**
381:             * Provide the controller with a PersitentSession object, which it can use
382:             * to hold values between invokations. It is essential to use the PersistentSession
383:             * rather than handing the controller the HTTPSession or HTTPServletRequest, for
384:             * example, to preserve it's portability across all UI environments.
385:             *
386:             * @param newSession A PersistentSession object
387:             */
388:            public void setSession(PersistentSession newSession)
389:                    throws ControllerException {
390:                if (newSession == null) {
391:                    throw new ControllerException(
392:                            "Cannot set a null PersistentSession object");
393:                }
394:
395:                mySession = newSession;
396:            } /* setSession(PersistentSession) */
397:
398:            /**
399:             * Returns the Persistant Session Wrapper object to store requests between
400:             * environments.  Use this instead of HTTPSession or HTTPServletRequest
401:             *
402:             * @return a Persistant Session Object
403:             * @throws ControllerException upon error
404:             */
405:            public PersistentSession getSession() throws ControllerException {
406:                if (mySession == null) {
407:                    throw new ControllerException(
408:                            "No PersistentSession object available");
409:                }
410:
411:                return mySession;
412:            }
413:
414:            /**
415:             * Retrieve the initialization parameter
416:             *
417:             * @param paramName the name of the parameter to retrieve
418:             * @return java.lang.String
419:             */
420:            public String getInitParameter(String paramName) {
421:                if (initParams == null) {
422:                    return null;
423:                } else {
424:                    return (String) initParams.get(paramName);
425:                }
426:            } /* getInitialParameter(String) */
427:
428:            /**
429:             * Get the user name
430:             *
431:             * @return the currently logged in user or NONE if there's no user logged in
432:             */
433:            public String getUser() {
434:                if (userName == null) {
435:                    return User.UNKNOWN_USER;
436:                }
437:
438:                return userName;
439:            } /* getUser() */
440:
441:            /**
442:             * Get the user id as an integer
443:             *
444:             * @return an integer representing the internal UID
445:             */
446:            public int getUid() {
447:                return uid;
448:            }
449:
450:            /**
451:             * Return the complete hashtable of parameters all keyed by parameter names
452:             *
453:             * @return a Hashtable containing all the parameter values, keyed by name; this is a CLONE of the source hashtable, not the original
454:             */
455:            public Hashtable getParameters() {
456:                if (params != null) {
457:                    return (Hashtable) params.clone();
458:                } else {
459:                    return new Hashtable();
460:                }
461:            } /* getParameters() */
462:
463:            /**
464:             * Fetch the value for the given parameter. Return null
465:             * if there is no such parameter
466:             *
467:             * @param paramCode Code of the parameter desired
468:             * @return java.lang.String
469:             */
470:            public String getParameter(String paramCode) {
471:                if (params == null) {
472:                    return null;
473:                }
474:
475:                return (String) params.get(paramCode);
476:            } /* getParameter(String) */
477:
478:            /**
479:             * Does a specified parameter refer to an uploaded file?
480:             *
481:             * @param paramName the name of the parameter to check if it is a file
482:             * @return boolean
483:             */
484:            public boolean isFileParameter(String paramName) {
485:                if (fileParams == null) {
486:                    return false;
487:                }
488:                if (fileParams.containsKey(paramName)) {
489:                    return true;
490:                }
491:
492:                return false;
493:            } /* isFileParameter(String) */
494:
495:            /**
496:             * Return the name of the database connection we use - or null
497:             * for the default connection
498:             *
499:             * @return The current DBContext
500:             * @deprecated 10/2004 v.5.6 use getDataContext instead
501:             */
502:            public String getDBName() {
503:                if (StringUtil.notNull(dbName).equals("")) {
504:                    return "default";
505:                }
506:
507:                return dbName;
508:            } /* getDBName() */
509:
510:            /**
511:             * Return the name of the database connection we use - or null
512:             * for the default connection
513:             *
514:             * @return The current DBContext
515:             */
516:            public String getDataContext() {
517:                if (StringUtil.notNull(dbName).equals("")) {
518:                    return "default";
519:                }
520:                return dbName;
521:            }
522:
523:            /**
524:             * Set this DB Controller to operate on a database other than the default
525:             *
526:             * @param newDBName The dbcontext to set this request to.
527:             */
528:            public synchronized void setDBName(String newDBName) {
529:                if (StringUtil.notNull(newDBName).equals("")) {
530:                    dbName = "default";
531:                } else {
532:                    dbName = newDBName;
533:                }
534:            } /* setDBName(String) */
535:
536:            /**
537:             * Set this DB Controller to operate on a database other than the default
538:             *
539:             * @param newDBName The dbcontext to set this request to.
540:             */
541:            public synchronized void setDataContext(String newDBName) {
542:                this .setDBName(newDBName);
543:            }
544:
545:            /**
546:             * Convenience method to populate a dbobject from the parameters supplied,
547:             * by looking for parameters with the same name as the field name in the db object
548:             *
549:             * @param myDBObj the dbobject to populate
550:             * @throws ControllerException upon error
551:             */
552:            public void populate(DBObject myDBObj) throws ControllerException {
553:                try {
554:                    String oneFieldName = null;
555:
556:                    for (Iterator e = myDBObj.getJDBCMetaData()
557:                            .getFieldListArray().iterator(); e.hasNext();) {
558:                        oneFieldName = (String) e.next();
559:
560:                        if (getParameter(oneFieldName) != null) {
561:                            myDBObj.setField(oneFieldName,
562:                                    getParameter(oneFieldName));
563:                        }
564:                    } /* for each field */
565:
566:                } catch (DBException de) {
567:                    throw new ControllerException(de);
568:                }
569:            } /* addAutoInput(DBOBject) */
570:
571:            /**
572:             * Returns the Error collection that exists in the current session.
573:             *
574:             * @return an ErrorCollection object or NULL if an error collection doesn't
575:             *         exist.
576:             * @throws ControllerException if there is an error getting the Session object
577:             */
578:            public ErrorCollection getErrorCollection()
579:                    throws ControllerException {
580:                ErrorCollection ec = (ErrorCollection) getSession()
581:                        .getAttribute(Globals.ERROR_KEY);
582:
583:                //
584:                //We also now check the session.... if the error collection exists there,
585:                //then we MOVE it to the request context, thus preventing lots of memory
586:                //usage
587:                //
588:                if (ec == null) {
589:                    // retrieve errors from persistent attributes, if any
590:                    ec = (ErrorCollection) getSession().getPersistentAttribute(
591:                            Globals.ERROR_KEY);
592:
593:                    // move to active session
594:                    if (ec != null) {
595:                        getSession().removePersistentAttribute(
596:                                Globals.ERROR_KEY);
597:                        getSession().setAttribute(Globals.ERROR_KEY, ec);
598:                    }
599:                }
600:
601:                return ec;
602:            }
603:
604:            public synchronized void setFormAttribute(String newAttribute) {
605:                formAttribute = newAttribute;
606:            }
607:
608:            public String getFormAttribute() {
609:                return formAttribute;
610:            }
611:
612:            /**
613:             * Checks if the described parameter is a defined parameter
614:             * for this request
615:             *
616:             * @param paramName the parameter to check against.
617:             * @return true if the name given IS a valid defined parameter
618:             */
619:            public boolean isParameter(String paramName) {
620:                Hashtable allParams = getParameters();
621:
622:                if (allParams == null) {
623:                    return false;
624:                }
625:
626:                return allParams.containsKey(paramName);
627:            }
628:
629:            /**
630:             * Convenience method that retrieves parameters/field values and populates a specified
631:             * db object. Once the object is populated, the fields are validated
632:             * and the error collection populated if necessary.
633:             *
634:             * @param oneObject the object to validate
635:             * @param ec        The error collection that gets filled out.
636:             * @throws ControllerException upon internal or data error
637:             * @throws ValidationException if there is an error validating the object
638:             */
639:            public void validateDBObject(DBObject oneObject, ErrorCollection ec)
640:                    throws ControllerException, ValidationException {
641:                try {
642:                    String oneFieldName = null;
643:                    for (Iterator af = oneObject.getMetaData()
644:                            .getFieldListArray().iterator(); af.hasNext();) {
645:                        oneFieldName = (String) af.next();
646:                        validateDBField(oneFieldName, oneObject, ec);
647:                    }
648:                } catch (DBException de) {
649:                    throw new ControllerException(de);
650:                }
651:            } /* validateDBObj(DBObject, ErrorCollection) */
652:
653:            /**
654:             * Convenience method that retrieves the validates
655:             * against that one database object field.  Assumes
656:             * that the parameter name in the request is the same as the
657:             * DB field name.
658:             *
659:             * @param dbFieldName the name of the field to validate
660:             * @param oneObject   the DBOBject to validate
661:             * @param ec          The ErrorCollection to fill out if there is an error
662:             * @throws DBException         upon data error
663:             * @throws ControllerException upon internal error
664:             */
665:            public void validateDBField(String dbFieldName, DBObject oneObject,
666:                    ErrorCollection ec) throws ControllerException, DBException {
667:
668:                validateField(dbFieldName, dbFieldName, oneObject, ec);
669:            }
670:
671:            /**
672:             * Convenience method that retrieves the validates
673:             * against that one database object field.
674:             *
675:             * @param dbFieldName  the name of the field to validate
676:             * @param reqFieldName ???
677:             * @param oneObject    the DBOBject to validate
678:             * @param ec           The ErrorCollection to fill out if there is an error
679:             * @throws DBException         upon data error
680:             * @throws ControllerException upon internal error
681:             */
682:            public void validateField(String dbFieldName, String reqFieldName,
683:                    DBObject oneObject, ErrorCollection ec)
684:                    throws ControllerException, DBException {
685:
686:                Hashtable allParams = getParameters();
687:
688:                if ((!oneObject.getMetaData().getFieldMetadata(dbFieldName)
689:                        .isReadOnly())
690:                        && (!oneObject.getMetaData().getFieldMetadata(
691:                                dbFieldName).isVirtual())) {
692:                    if (allParams.containsKey(reqFieldName)) {
693:                        String oneFieldParam = getParameter(reqFieldName);
694:
695:                        try {
696:                            oneObject.checkField(dbFieldName, oneFieldParam);
697:                        } catch (DBException de) {
698:                            if (log.isInfoEnabled()) {
699:                                log.info("Validation error for field:", de);
700:                            }
701:
702:                            ec.addError(de.getMessage());
703:                        }
704:
705:                        oneObject.setField(dbFieldName, oneFieldParam);
706:                    }
707:                }
708:            }
709:
710:            /**
711:             * Sets the Locale of this request
712:             *
713:             * @param newLocale the new Locale to set this request to.
714:             */
715:            public synchronized void setLocale(Locale newLocale) {
716:                currentLocale = newLocale;
717:            }
718:
719:            /**
720:             * Returns the locale of this request.
721:             *
722:             * @return a Locale Object based upon current locale settings.
723:             */
724:            public Locale getLocale() {
725:                if (currentLocale != null) {
726:                    return currentLocale;
727:                }
728:
729:                Locale l = null;
730:
731:                try {
732:                    l = new Locale(ConfigManager.getContext(getDataContext())
733:                            .getLanguage(), ConfigManager.getContext(
734:                            getDataContext()).getCountry());
735:                } catch (ConfigurationException ce) {
736:                    l = null;
737:                }
738:                if (l == null) {
739:                    l = Locale.getDefault();
740:                }
741:
742:                return l;
743:            }
744:
745:            /**
746:             * Returns a clone of this object.
747:             *
748:             * @return a newly cloned ControllerRequest object.
749:             */
750:            public Object clone() {
751:                Object o = null;
752:                String className = this .getClass().getName();
753:
754:                try {
755:                    Class c = ClassLocator.loadClass(className);
756:                    o = c.newInstance();
757:                } catch (ClassNotFoundException cn) {
758:                    throw new IllegalArgumentException("State object '"
759:                            + className + "' not found");
760:                } catch (InstantiationException ie) {
761:                    throw new IllegalArgumentException("State object '"
762:                            + className + "' cannot be instantiated");
763:                } catch (IllegalArgumentException e) {
764:                    throw new IllegalArgumentException(
765:                            "State object '"
766:                                    + className
767:                                    + "' cannot be instantiated (IllegalArgumentException)");
768:                } catch (IllegalAccessException iae) {
769:                    throw new IllegalArgumentException("llegal access loading "
770:                            + "State object '" + className + "'");
771:                }
772:                synchronized (this ) {
773:                    ControllerRequest cr = (ControllerRequest) o;
774:
775:                    if (this .attributes != null) {
776:                        cr.attributes = new HashMap(this .attributes);
777:                    }
778:
779:                    cr.currentLocale = this .currentLocale;
780:                    cr.dbName = this .dbName;
781:
782:                    if (this .fileParams != null) {
783:                        cr.fileParams = (Hashtable) this .fileParams.clone();
784:                    }
785:
786:                    cr.formAttribute = this .formAttribute;
787:
788:                    if (this .formResponseCache != null) {
789:                        cr.formResponseCache = (Hashtable) this .formResponseCache
790:                                .clone();
791:                    }
792:
793:                    cr.initialState = this .initialState;
794:
795:                    if (this .initParams != null) {
796:                        cr.initParams = new HashMap(this .initParams);
797:                    }
798:
799:                    cr.mySchema = this .mySchema;
800:                    cr.mySession = this .mySession;
801:
802:                    if (this .objectParams != null) {
803:                        cr.objectParams = new HashMap(this .objectParams);
804:                    }
805:                    if (this .params != null) {
806:                        cr.params = (Hashtable) this .params.clone();
807:                    }
808:
809:                    cr.uid = this .uid;
810:                    cr.userName = this .userName;
811:                }
812:
813:                return o;
814:            }
815:
816:            /**
817:             * Remove a parameter from this controller request.
818:             *
819:             * @param paramName the name of the parameter to remove
820:             */
821:            public void removeParameter(String paramName) {
822:                params.remove(paramName);
823:            }
824:
825:            /**
826:             * get requesting user
827:             *
828:             * @return user object for requesting user; will throw if UID is not found
829:             */
830:            public User getUserInfo() throws DBException {
831:                return User.getUser(this );
832:            }
833:        } /* ControllerRequest */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.