Source Code Cross Referenced for ValidationHelper.java in  » Workflow-Engines » osbl-1_0 » org » osbl » 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 » Workflow Engines » osbl 1_0 » org.osbl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.osbl;
002:
003:        import org.conform.*;
004:        import org.conform.format.DefaultFormatFactory;
005:        import org.conform.modifier.AnnotationModifier;
006:
007:        import java.util.*;
008:
009:        public class ValidationHelper {
010:            private Set<Issue> issues = new HashSet<Issue>();
011:
012:            private ValidationListener forwarder = new ValidationListener() {
013:                public void addIssues(ValidationEvent event) {
014:                    issues.addAll(event.getIssues());
015:                }
016:
017:                public void removeIssues(ValidationEvent event) {
018:                }
019:
020:                public void clearIssues(Meta meta) {
021:                }
022:            };
023:
024:            private BeanMetaProvider getBeanMetaProvider() {
025:                return (BeanMetaProvider) ServiceProvider.getInstance()
026:                        .getService("StaticBeanMetaProvider");
027:            }
028:
029:            public void staticValidation(Object object) {
030:                if (object == null)
031:                    throw new NullPointerException("Object must not be null!");
032:
033:                BeanMeta beanMeta = getBeanMetaProvider().getBeanMeta(
034:                        object.getClass());
035:                DefaultBeanData beanData = new DefaultBeanData(beanMeta);
036:                beanData.setValue(object);
037:
038:                beanData.addValidationListener(forwarder);
039:                beanData.setIssuePublishingActive(true);
040:                beanData.revalidateAll();
041:            }
042:
043:            public void validation(Object object, Validator validator,
044:                    String... affectedPropertyNames) {
045:                if (object == null)
046:                    throw new NullPointerException("Object must not be null!");
047:                if (affectedPropertyNames == null
048:                        || affectedPropertyNames.length == 0)
049:                    throw new NullPointerException(
050:                            "Affected property names are required!");
051:
052:                try {
053:                    validator.validate(object);
054:                } catch (ValidationException e) {
055:                    PropertyMeta[] affectedPropertyMetas = propertyMetas(object
056:                            .getClass(), affectedPropertyNames);
057:
058:                    for (ValidationException.Message message : e.getMessages()) {
059:                        issues.add(new Issue(
060:                                System.identityHashCode(validator),
061:                                affectedPropertyMetas, message.getCode(),
062:                                message.getArguments()));
063:                    }
064:                }
065:            }
066:
067:            public void validation(Object object, BeanValidator validator) {
068:                if (object == null)
069:                    throw new NullPointerException("Object must not be null!");
070:
071:                try {
072:                    validator.validate(object);
073:                } catch (ValidationException e) {
074:                    PropertyMeta[] affectedPropertyMetas = propertyMetas(object
075:                            .getClass(), validator.getAffectedPropertyNames());
076:
077:                    for (ValidationException.Message message : e.getMessages()) {
078:                        issues.add(new Issue(
079:                                System.identityHashCode(validator),
080:                                affectedPropertyMetas, message.getCode(),
081:                                message.getArguments()));
082:                    }
083:                }
084:            }
085:
086:            public void addIssue(Class type, String[] propertyNames,
087:                    String code, Object... arguments) {
088:                issues.add(new Issue(-issues.size(), propertyMetas(type,
089:                        propertyNames), code, arguments));
090:            }
091:
092:            public void addIssue(Class type, String propertyName, String code,
093:                    Object... arguments) {
094:                issues.add(new Issue(-issues.size(), propertyMeta(type,
095:                        propertyName), code, arguments));
096:            }
097:
098:            public void throwIfIssues() throws ValidationIssueException {
099:                if (issues.size() > 0)
100:                    throw new ValidationIssueException(issues);
101:            }
102:
103:            private PropertyMeta[] propertyMetas(Class type,
104:                    String[] affectedPropertyNames) {
105:                BeanMeta beanMeta = getBeanMetaProvider().getBeanMeta(type);
106:                PropertyMeta[] affectedPropertyMetas = new PropertyMeta[affectedPropertyNames.length];
107:                for (int i = 0; i < affectedPropertyNames.length; i++) {
108:                    String affectedPropertyName = affectedPropertyNames[i];
109:                    affectedPropertyMetas[i] = beanMeta
110:                            .getProperty(affectedPropertyName);
111:                }
112:                return affectedPropertyMetas;
113:            }
114:
115:            private PropertyMeta propertyMeta(Class type,
116:                    String affectedPropertyName) {
117:                BeanMeta beanMeta = getBeanMetaProvider().getBeanMeta(type);
118:                return beanMeta.getProperty(affectedPropertyName);
119:            }
120:
121:            public static void main(String[] args) {
122:                new DefaultFormatFactory();
123:                ServiceProvider.INSTANCE = new ServiceProvider() {
124:                    public List<String> getServiceNames() {
125:                        return null;
126:                    }
127:
128:                    public Object getService(String name) {
129:                        VariationBeanMetaProvider metaProvider = new VariationBeanMetaProvider(
130:                                new Beans());
131:                        metaProvider.addModifier(new AnnotationModifier(
132:                                metaProvider));
133:                        return metaProvider;
134:                    }
135:
136:                    public <T> T getService(Class<T> type) {
137:                        return null;
138:                    }
139:
140:                    public void autowireServices(Object bean) {
141:                    }
142:                };
143:                Address address = new Address();
144:
145:                ValidationHelper validationHelper = new ValidationHelper();
146:                validationHelper.staticValidation(address);
147:
148:                // callback validator
149:                validationHelper.validation(address, new Validator() {
150:                    public Object validate(Object value)
151:                            throws ValidationException {
152:                        throw new ValidationException(
153:                                new ValidationException.Message("blub",
154:                                        new Object[] { value }));
155:                    }
156:                }, "city", "postcode");
157:
158:                // callback bean validator
159:                validationHelper.validation(address, new BeanValidator() {
160:                    public Object validate(Object value)
161:                            throws ValidationException {
162:                        throw new ValidationException(
163:                                new ValidationException.Message("bla",
164:                                        new Object[] { value }));
165:                    }
166:
167:                    public String[] getAffectedPropertyNames() {
168:                        return new String[] { "street" };
169:                    }
170:                });
171:
172:                // inline
173:                if (true)
174:                    validationHelper.addIssue(Address.class, new String[] {
175:                            "street", "postcode", "city" }, "fasel", 7);
176:
177:                System.out.println("Issues: " + validationHelper.issues);
178:            }
179:
180:            public static class Address {
181:                Long id;
182:
183:                String street;
184:                String postcode;
185:                String city;
186:
187:                public Long getId() {
188:                    return id;
189:                }
190:
191:                public void setId(Long id) {
192:                    this .id = id;
193:                }
194:
195:                public String getStreet() {
196:                    return street;
197:                }
198:
199:                public void setStreet(String street) {
200:                    this .street = street;
201:                }
202:
203:                public String getPostcode() {
204:                    return postcode;
205:                }
206:
207:                public void setPostcode(String postcode) {
208:                    this .postcode = postcode;
209:                }
210:
211:                public String getCity() {
212:                    return city;
213:                }
214:
215:                public void setCity(String city) {
216:                    this.city = city;
217:                }
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.