Source Code Cross Referenced for XValidationFactory.java in  » XML-UI » XUI » net » xoetrope » xui » validation » 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 » XML UI » XUI » net.xoetrope.xui.validation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.xoetrope.xui.validation;
002:
003:        import java.io.Reader;
004:        import java.lang.reflect.Method;
005:        import java.util.Enumeration;
006:        import java.util.Hashtable;
007:
008:        import net.xoetrope.xml.XmlElement;
009:        import net.xoetrope.xml.XmlSource;
010:        import java.awt.Container;
011:        import net.xoetrope.xui.XPage;
012:        import net.xoetrope.xui.build.BuildProperties;
013:        import net.xoetrope.debug.DebugLogger;
014:
015:        /**
016:         * <p>Constucts validations be reading rules from a configuration file</p>
017:         * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003<br>
018:         * License:      see license.txt</p>
019:         * $Revision: 1.16 $
020:         */
021:        public class XValidationFactory {
022:            protected Hashtable validations;
023:
024:            public XValidationFactory() {
025:            }
026:
027:            /**
028:             * Constructor which reads validations from the reader
029:             * @param reader Reader of file containing validations
030:             */
031:            public XValidationFactory(Reader reader) {
032:                read(reader);
033:            }
034:
035:            /**
036:             * Loads XmlElements from the file and puts the element into the validations
037:             * Hashtable with the name of the validation as the key.
038:             * @param read
039:             */
040:            public void read(Reader read) {
041:                XmlElement element = XmlSource.read(read);
042:                Enumeration e = element.getChildren().elements();
043:                validations = new Hashtable();
044:                while (e.hasMoreElements()) {
045:                    XmlElement ele = (XmlElement) e.nextElement();
046:                    String name = ele.getAttribute("name");
047:                    validations.put(name, ele);
048:                }
049:
050:            }
051:
052:            /**
053:             * Creates an XValidation object which validates against a value returned from
054:             * a function call
055:             * @param validationName The name of the validation
056:             * @param m The Method to call in order to get the value to validate against
057:             * @param mask
058:             * @param page The page object which contains the function
059:             * @return The new XValidator
060:             */
061:            public XValidator getValidation(String validationName, Method m,
062:                    int mask, Container page) {
063:                XValidator validator = getValidation(validationName, mask, page);
064:                if (validator != null)
065:                    validator.setValidationMethod(m, page);
066:                return validator;
067:            }
068:
069:            /**
070:             * Gets the validation for the validationName. Checks first to see if the
071:             * validation is a predefined type in which case it reads it's required
072:             * attributes. If the validation type is custom we just need to create a
073:             * validator from the class attribute
074:             * @param validationName The name of the validation
075:             * @param mask
076:             * @return The new XValidator
077:             */
078:            public XValidator getValidation(String validationName, int mask,
079:                    Container page) {
080:                XmlElement ele = (XmlElement) validations.get(validationName);
081:                if (BuildProperties.DEBUG) {
082:                    if (ele == null) {
083:                        DebugLogger
084:                                .logError("Cannot find the validation rule: "
085:                                        + validationName);
086:                        return null;
087:                    }
088:                }
089:
090:                String type = ele.getAttribute("type");
091:
092:                if (type.compareTo("minmax") == 0) {
093:                    XMinMaxValidator mmValidator = new XMinMaxValidator(
094:                            validationName, mask);
095:                    mmValidator.setup(ele);
096:                    return mmValidator;
097:                } else if (type.compareTo("mandatory") == 0) {
098:                    XMandatoryValidator mandatoryValidator = new XMandatoryValidator(
099:                            validationName, mask);
100:                    mandatoryValidator.setup(ele);
101:                    return mandatoryValidator;
102:                } else if (type.compareTo("custom") == 0) {
103:                    String className = ele.getAttribute("class");
104:                    XBaseValidator validator = null;
105:                    try {
106:                        validator = (XBaseValidator) Class.forName(className)
107:                                .newInstance();
108:                        validator.setName(validationName);
109:                        validator.setMask(mask);
110:                        validator.setup(ele);
111:                    } catch (Exception ex) {
112:                        ex.printStackTrace();
113:                    }
114:                    return validator;
115:                }
116:                return null;
117:            }
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.