Source Code Cross Referenced for ValidationException.java in  » Development » iScreen » org » iscreen » 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 » Development » iScreen » org.iscreen 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007 Dan Shellman
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.iscreen;
017:
018:        import java.util.List;
019:        import java.util.ArrayList;
020:        import java.util.Collections;
021:        import java.util.HashMap;
022:        import java.util.Map;
023:
024:        /**
025:         * When a validation failure occurs, eventually a ValidationException is
026:         * thrown to the caller.  This is a checked exception that should be
027:         * handled by the caller.  The exception contains the list of ValidationFailures
028:         * that represent the validations that have failed.  Ultimately, the failures
029:         * should be used to notify the end user (or system).
030:         *
031:         * @author Shellman, Dan
032:         */
033:        public class ValidationException extends Exception {
034:            protected List failures = new ArrayList();
035:            protected List warnings = new ArrayList();
036:            protected Map namedFailures = new HashMap();
037:
038:            /**
039:             * Default constructor with no pre-defined validation failures.
040:             */
041:            public ValidationException() {
042:            } //end ValidationException()
043:
044:            /**
045:             * Constructor with pre-defined validation failures.
046:             *
047:             * @param   validationFailures The List of ValidationFailures for this exception.
048:             */
049:            public ValidationException(List validationFailures) {
050:                int count;
051:
052:                count = validationFailures.size();
053:                for (int i = 0; i < count; i++) {
054:                    addFailure((ValidationFailure) validationFailures.get(i));
055:                }
056:            } //end ValidationException()
057:
058:            /**
059:             * Constructor with pre-defined validation failures and warnings.  Each
060:             * List must contain ValidationFailure objects.
061:             *
062:             * @param   validationFailures The List of failures for this exception.
063:             * @param   validationWarnings The List of warnings for this exception.
064:             */
065:            public ValidationException(List validationFailures,
066:                    List validationWarnings) {
067:                int count;
068:
069:                count = validationFailures.size();
070:                for (int i = 0; i < count; i++) {
071:                    addFailure((ValidationFailure) validationFailures.get(i));
072:                }
073:
074:                count = validationWarnings.size();
075:                for (int i = 0; i < count; i++) {
076:                    addWarning((ValidationFailure) validationWarnings.get(i));
077:                }
078:            } //end ValidationException()
079:
080:            /**
081:             * Add a failure to this exception.  This failure will be appended
082:             * to the end of the internal list of failures.
083:             *
084:             * @param   failure The ValidationFailure to add to this exception.
085:             */
086:            public void addFailure(ValidationFailure failure) {
087:                failures.add(failure);
088:                updateNamedFailures(failure);
089:            } //and addFailure()
090:
091:            /**
092:             * Add a warning to this exception.  This warning will be appended
093:             * to the end of the internal list of warnings.
094:             *
095:             * @param   warning The warning to add to this exception.
096:             */
097:            public void addWarning(ValidationFailure warning) {
098:                warnings.add(warning);
099:                updateNamedFailures(warning);
100:            } //and addWarning()
101:
102:            /**
103:             * Retrieves the List of ValidationFailures associated with this exception
104:             * that represent the failures.
105:             *
106:             * @return Returns a List of ValidationFailures.
107:             */
108:            public List getFailures() {
109:                return Collections.unmodifiableList(failures);
110:            } //end getFailures()
111:
112:            /**
113:             * Retrieves the List of ValidationFailures associated with this exception
114:             * that represent the warnings.
115:             *
116:             * @return Returns a List of warnings.
117:             */
118:            public List getWarnings() {
119:                return Collections.unmodifiableList(warnings);
120:            } //end getWarnings()
121:
122:            /**
123:             * Retrieves the List of failures (and warnings) that are associated with
124:             * a particular "name."  The name is defined in the configuration, and is
125:             * associated with a particular use of a validator.  This is interesting
126:             * when mapping back to some form of presentation layer.
127:             *
128:             * @param   validatorName The name to find failures against.
129:             *
130:             * @return Returns a List of ValidationFailure objects (or an empty
131:             *         List if there are none associated with the given name).
132:             *         Will not return null.
133:             */
134:            public List getNamedFailures(String validatorName) {
135:                List list;
136:
137:                list = (List) namedFailures.get(validatorName);
138:                if (list == null) {
139:                    return new ArrayList();
140:                }
141:
142:                return Collections.unmodifiableList(list);
143:            } //end getNamedFailures()
144:
145:            /**
146:             * Retrieves the list of failure messages (List of String objects).
147:             *
148:             * @return Returns the List of failure messages (as Strings).
149:             */
150:            public List getFailureMessages() {
151:                List list = new ArrayList();
152:
153:                for (int i = 0; i < failures.size(); i++) {
154:                    list
155:                            .add(((ValidationFailure) failures.get(i))
156:                                    .getMessage());
157:                }
158:
159:                return list;
160:            } //end getFailureMessages()
161:
162:            /**
163:             * Retrieves the list of warning messages (List of String objects).
164:             *
165:             * @return Returns the List of warning messages (as Strings).
166:             */
167:            public List getWarningMessages() {
168:                List list = new ArrayList();
169:
170:                for (int i = 0; i < warnings.size(); i++) {
171:                    list
172:                            .add(((ValidationFailure) warnings.get(i))
173:                                    .getMessage());
174:                }
175:
176:                return list;
177:            } //end getWarningMessages()
178:
179:            private void updateNamedFailures(ValidationFailure theFailure) {
180:                List list;
181:                String name;
182:
183:                name = theFailure.getName();
184:                list = (List) namedFailures.get(name);
185:                if (list == null) {
186:                    list = new ArrayList();
187:                    namedFailures.put(name, list);
188:                }
189:
190:                list.add(theFailure);
191:            } //end updateNamedFailures()
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.