Source Code Cross Referenced for BaseFactory.java in  » Web-Framework » Strecks » org » strecks » validator » factory » 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 » Web Framework » Strecks » org.strecks.validator.factory 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2006 the original author or authors.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005:         * in compliance with the License. You may obtain a copy of the License at
006:         * 
007:         * http://www.apache.org/licenses/LICENSE-2.0
008:         * 
009:         * Unless required by applicable law or agreed to in writing, software distributed under the License
010:         * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011:         * or implied. See the License for the specific language governing permissions and limitations under
012:         * the License.
013:         */
014:
015:        package org.strecks.validator.factory;
016:
017:        import java.lang.reflect.Method;
018:        import java.util.List;
019:
020:        import org.strecks.util.ReflectHelper;
021:        import org.strecks.validator.Validator;
022:        import org.strecks.validator.internal.ValidatorWrapper;
023:        import org.strecks.validator.message.DefaultMessageParameterProvider;
024:        import org.strecks.validator.message.MessageParameterProvider;
025:
026:        /**
027:         * Convenience base class of <code>ValidatorFactory</code> implementations
028:         * @author Phil Zoio
029:         */
030:        public abstract class BaseFactory implements  ValidatorFactory {
031:
032:            /**
033:             * Returns a <code>ValidatorWrapper</code> which encapsulates all the validations for a property
034:             * @param validator
035:             *            the <code>Validator</code> instance wrapped by the <code>ValidatorWrapper</code>
036:             * @param key
037:             *            the message key used to look up the relevant error message on validation failure
038:             * @param order
039:             *            the order in which this validator should be called. Validators are called in ascending order
040:             * @param parameters
041:             *            additional parameters supplied to the validator. For example, a date validator will require a pattern
042:             *            parameter, and an integer range validator will require minimum and maximum ranges
043:             * @param method
044:             *            the setter method for the property being validated
045:             * @return
046:             */
047:            protected ValidatorWrapper create(Validator validator, String key,
048:                    int order, List<Object> parameters, Method method) {
049:                MessageParameterProvider provider = newMessageParameterProvider();
050:                ValidatorWrapper wrapper = newWrapper(validator, key, order,
051:                        parameters, method, provider);
052:                return wrapper;
053:            }
054:
055:            ValidatorWrapper newWrapper(Validator validator, String key,
056:                    int order, List<Object> parameters, Method method,
057:                    MessageParameterProvider provider) {
058:
059:                Class<?> parameterizedType = ReflectHelper.getGenericType(
060:                        validator.getClass(), Validator.class);
061:
062:                boolean useConvertedValue = shouldUseConvertedValue(validator,
063:                        method);
064:
065:                if (useConvertedValue) {
066:                    return new ValidatorWrapper(key, order, parameters,
067:                            validator, method, provider, useConvertedValue,
068:                            parameterizedType);
069:                } else {
070:                    return new ValidatorWrapper(key, order, parameters,
071:                            validator, method, provider);
072:                }
073:            }
074:
075:            boolean shouldUseConvertedValue(Validator validator, Method method) {
076:                Class<?> returnType = method.getReturnType();
077:                Class<?> parameterizedType = ReflectHelper.getGenericType(
078:                        validator.getClass(), Validator.class);
079:
080:                boolean useConvertedValue = false;
081:
082:                // if no parametized type, then use the raw value for validation
083:                if (parameterizedType == null)
084:                    useConvertedValue = false;
085:
086:                else {
087:                    if (parameterizedType.isAssignableFrom(returnType)) {
088:                        // if return type can be assigned to parameterized type, then use the raw value for validation
089:                        useConvertedValue = false;
090:                    } else {
091:                        // if return type cannot be assigned to parameterized type, then use converted value for validation
092:                        // e.g. return type is String, parameterized type is Integer
093:                        useConvertedValue = true;
094:                    }
095:                }
096:                return useConvertedValue;
097:            }
098:
099:            MessageParameterProvider newMessageParameterProvider() {
100:                MessageParameterProvider provider = getMessageParameterProvider();
101:
102:                if (provider == null)
103:                    return new DefaultMessageParameterProvider();
104:                else
105:                    return provider;
106:            }
107:
108:            protected MessageParameterProvider getMessageParameterProvider() {
109:                return null;
110:            }
111:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.