Source Code Cross Referenced for BaseValidationService.java in  » Development » iScreen » org » iscreen » impl » 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.impl 
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.impl;
017:
018:        import java.util.List;
019:        import java.util.Locale;
020:        import org.iscreen.DocumentationIterator;
021:        import org.iscreen.ObjectValidationException;
022:
023:        import org.iscreen.ValidationException;
024:        import org.iscreen.ValidationService;
025:
026:        /**
027:         * This is the base class implementation of the ValidationService interface.
028:         *
029:         * @author Shellman, Dan
030:         */
031:        public abstract class BaseValidationService implements 
032:                ValidationService {
033:            protected String id;
034:            protected Locale defaultLocale;
035:
036:            /**
037:             * Constructor taking unique id.  The unique id is required.  In addition,
038:             * the default locale is provided.
039:             *
040:             * @param   uniqueId The unique id for this service.
041:             * @param   locale The default locale for this service.
042:             */
043:            public BaseValidationService(String uniqueId, Locale locale) {
044:                id = uniqueId;
045:                defaultLocale = locale;
046:            } //end BaseValidationService()
047:
048:            public void validate(Object obj) throws ValidationException {
049:                validate(obj, defaultLocale);
050:            } //end validate()
051:
052:            public void validate(Object obj, Locale locale)
053:                    throws ValidationException {
054:                ContextBean contextBean;
055:                DefaultValidatorContext context;
056:                ValidatorWrapper wrapper;
057:                List failures;
058:
059:                //Basic algorithm:
060:                //Loop through validators and perform the following:
061:                // -Initialize an ContextBean and ValidatorContext
062:                // -Call the validator wrapper's validate() method with context and bean
063:                // -Store any validation failures
064:                //Once done looping through validators, if there are more than zero
065:                //validation failures, create a ValidationException, stuff the validation
066:                //failures in there, and throw it.  Otherwise, return.
067:                contextBean = constructContextBean(obj);
068:                context = constructContext(contextBean, locale);
069:
070:                resetValidatorIteration();
071:                wrapper = getNextValidator();
072:                while (wrapper != null) {
073:                    boolean continueFlag;
074:
075:                    context.setValidator(wrapper);
076:                    continueFlag = wrapper.validate(context, contextBean, obj);
077:                    if (continueFlag == false) {
078:                        break;
079:                    }
080:
081:                    wrapper = getNextValidator();
082:                }
083:
084:                //Finally, check to see if there were any failures.
085:                if (context.getCount() > 0) {
086:                    throw new ValidationException(context.getFailures(),
087:                            context.getWarnings());
088:                }
089:            } //end validate()
090:
091:            public void validateObject(Object obj, Locale locale) {
092:                try {
093:                    validate(obj, locale);
094:                } catch (ValidationException e) {
095:                    throw new ObjectValidationException(e);
096:                }
097:            } //end validateObject()
098:
099:            public void validateObject(Object obj) {
100:                validateObject(obj, defaultLocale);
101:            } //end validateObject()
102:
103:            public String getServiceName() {
104:                return id;
105:            } //end getServiceName()
106:
107:            /**
108:             * Retrieves an iterator of String values representing the documentation
109:             * configured for this validation service (the underlying validation set).
110:             *
111:             * @return Returns an iterator of Strings representing documentation.
112:             */
113:            public DocumentationIterator getDocumentation() {
114:                DocumentationIterator docIt = new DocumentationIterator();
115:                ValidatorWrapper wrapper;
116:
117:                resetValidatorIteration();
118:                wrapper = getNextValidator();
119:                while (wrapper != null) {
120:                    docIt.addIterator(wrapper.getDoc());
121:
122:                    wrapper = getNextValidator();
123:                }
124:
125:                return docIt;
126:            } //end getDocumentation()
127:
128:            // ***
129:            // Protected methods
130:            // ***
131:
132:            /**
133:             * Retrieves the "next" Validator in the set of Validators that this
134:             * validation service is configured to use.  If there are no more
135:             * Validators, then this method should return null.  It should return
136:             * the first Validator after a call to resetValidatorIteration().
137:             *
138:             * @return Returns the next ValidatorWrapper in the set of validators.
139:             */
140:            protected abstract ValidatorWrapper getNextValidator();
141:
142:            /**
143:             * Resets the iteration of Validators using the getNextValidator() method.
144:             */
145:            protected abstract void resetValidatorIteration();
146:
147:            /**
148:             * This can be over-written by sub-classes, but it's not really necessary,
149:             * since this service requires a particular implementation of the
150:             * ValidatorContext.
151:             * 
152:             * 
153:             * @param root The ContextBean that the context needs.
154:             * @param locale The locale to use in generating error messages.
155:             * @return Returns a constructed and configured DefaultValidatorContext.
156:             */
157:            protected DefaultValidatorContext constructContext(
158:                    ContextBean root, Locale locale) {
159:                return new DefaultValidatorContext(root, locale);
160:            } //end constructContext()
161:
162:            /**
163:             * This can be over-written by sub-classes, but it's not really necessary,
164:             * since this service requires an OGNL root object.
165:             * 
166:             * 
167:             * @return Returns an instance of ContextBean fully configured.
168:             */
169:            protected ContextBean constructContextBean(Object objToValidate) {
170:                ContextBean root;
171:
172:                root = new ContextBean();
173:                root.setBean(objToValidate);
174:
175:                return root;
176:            } //end constructContextBean()
177:        } //end BaseValidationService
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.