Source Code Cross Referenced for ValidationFactory.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.HashMap;
019:        import java.util.Hashtable;
020:        import java.util.Locale;
021:        import java.util.Map;
022:
023:        /**
024:         * This class represents factories that can generate validation services from
025:         * configuration files (or however the factory generates them).  The
026:         * static portion of this factory implementation is thread-safe.
027:         *
028:         * @author Shellman, Dan
029:         */
030:        public class ValidationFactory {
031:            /**
032:             * @deprecated This is no longer used for version 1.1 or later.  For OGNL,
033:             *             use FACTORY_OGNL_XML.  For MVEL, use FACTORY_MVEL_XML.
034:             */
035:            public static final String FACTORY_DEFAULT_XML = "FACTORY_DEFAULT_XML";
036:            public static final String FACTORY_OGNL_XML = "FACTORY_OGNL_XML";
037:            public static final String FACTORY_MVEL_XML = "FACTORY_MVEL_XML";
038:
039:            private static Hashtable factoryMap = new Hashtable();
040:
041:            protected Map serviceMap = new HashMap();
042:            protected String configLocation;
043:            protected Locale defaultLocale = Locale.getDefault();
044:
045:            /**
046:             * Register default factories.
047:             */
048:            static {
049:                try {
050:                    registerFactory(Class
051:                            .forName("org.iscreen.ognl.OgnlXmlServiceFactory"),
052:                            FACTORY_DEFAULT_XML);
053:                    registerFactory(Class
054:                            .forName("org.iscreen.ognl.OgnlXmlServiceFactory"),
055:                            FACTORY_OGNL_XML);
056:                } catch (Exception e) {
057:                    //TODO: Do something here.
058:                }
059:
060:                try {
061:                    registerFactory(Class
062:                            .forName("org.iscreen.mvel.MvelXmlServiceFactory"),
063:                            FACTORY_MVEL_XML);
064:                } catch (Exception e) {
065:                    //TODO: Do something here.
066:                }
067:            }
068:
069:            /**
070:             * Protected constructor.  In general, validation factories shouldn't
071:             * be constructed directly (hence the need to register them, etc.).
072:             */
073:            protected ValidationFactory() {
074:            } //end ValidationFactory()
075:
076:            /**
077:             * Builds a registered factory.  The factory is tied to the
078:             * configuration type (such as XML, etc.).  Pre-defined factories
079:             * (constants defined as FACTORY_xxx) are always available.
080:             *
081:             * @param   factoryId The id of the factory to retrieve.
082:             * @param   configLocation Classpath location of the configuration
083:             * @param   theDefaultLocale The default locale
084:             * @param   services Services that are necessary for the factory
085:             *
086:             * @return Returns a ValidationFactory.  If none exist with the given
087:             *         id, then a runtime exception is thrown.
088:             */
089:            public static ValidationFactory buildFactory(String factoryId,
090:                    String configLocation, Locale theDefaultLocale, Map services) {
091:                Class factoryClass;
092:                ValidationFactory factory;
093:
094:                factoryClass = (Class) factoryMap.get(factoryId);
095:                if (factoryClass == null) {
096:                    throw new ConfigurationException(
097:                            "No validation factory with factory id of "
098:                                    + factoryId);
099:                }
100:
101:                try {
102:                    factory = (ValidationFactory) factoryClass.newInstance();
103:
104:                    factory.setDefaultLocale(theDefaultLocale);
105:                    factory.setServices(services);
106:                    factory.setConfigLocation(configLocation);
107:                    factory.loadConfig();
108:                } catch (InstantiationException e) {
109:                    throw new ConfigurationException(
110:                            "Unable to instantiate validation factory.  Factory id is "
111:                                    + factoryId + " and class name is "
112:                                    + factoryClass.getName(), e);
113:                } catch (IllegalAccessException e) {
114:                    throw new ConfigurationException(
115:                            "Illegal access trying to instantiate validation factory.  Factory id is "
116:                                    + factoryId + " and class name is "
117:                                    + factoryClass.getName(), e);
118:                }
119:
120:                return factory;
121:            } //end buildFactory()
122:
123:            /**
124:             * Builds a registered factory.  The factory is tied to the
125:             * configuration type (such as XML, etc.).  Pre-defined factories
126:             * (constants defined as FACTORY_xxx) are always available.
127:             *
128:             * @param   factoryId The id of the factory to retrieve.
129:             * @param   configLocation Classpath location of the configuration
130:             * @param   services Services that are necessary for the factory
131:             *
132:             * @return Returns a ValidationFactory.  If none exist with the given
133:             *         id, then a runtime exception is thrown.
134:             */
135:            public static ValidationFactory buildFactory(String factoryId,
136:                    String configLocation, Map services) {
137:                return buildFactory(factoryId, configLocation, Locale
138:                        .getDefault(), services);
139:            } //end buildFactory()
140:
141:            /**
142:             * Registers a factory with a given factory id.  Use this method to
143:             * register a custom-built factory.  If a factory of the given id already
144:             * exists, it will be replaced.
145:             *
146:             * @param   factoryClass The class of the factory to register
147:             * @param   factoryId The id of the factory (used to retrieve it later)
148:             */
149:            public static void registerFactory(Class factoryClass,
150:                    String factoryId) {
151:                factoryMap.put(factoryId, factoryClass);
152:            } //end registerFactory()
153:
154:            /**
155:             * Retrieves a validation service with the given service name.
156:             *
157:             * @param   serviceName The name of the validation service.
158:             *
159:             * @return Returns the validation service with the given name.
160:             */
161:            public ValidationService getValidationService(String serviceName) {
162:                return null;
163:            } //end getValidationService()
164:
165:            // ***
166:            // Protected methods
167:            // ***
168:
169:            /**
170:             * This is called right after the validation factory is instantiated
171:             * and the services call (setServices()) has been called.  This method
172:             * informs the factory of the config file that will be used.  If it's not
173:             * in the format that the factory expects, the factory should throw an
174:             * unchecked exception.
175:             *
176:             * @param   location The location of the configuration file for the factory.
177:             *                   The location is classpath-based.
178:             */
179:            protected void setConfigLocation(String location) {
180:                configLocation = location;
181:            } //end setConfigLocation()
182:
183:            /**
184:             * Retrieves the configuration file location for this validation factory.
185:             *
186:             * @return Returns the location of the config file.  This may be null.
187:             */
188:            protected String getConfigLocation() {
189:                return configLocation;
190:            } //end getConfigLocation()
191:
192:            /**
193:             * Sets the default locale for this factory.
194:             *
195:             * @param   locale The default locale for this factory.
196:             */
197:            protected void setDefaultLocale(Locale locale) {
198:                defaultLocale = locale;
199:            } //end setDefaultLocale()
200:
201:            /**
202:             * Retrieves the default locale for this factory.
203:             *
204:             * @return Returns the default locale for this factory.
205:             */
206:            protected Locale getDefaultLocale() {
207:                return defaultLocale;
208:            } //end getDefaultLocale()
209:
210:            /**
211:             * This is called right after the validation factory is instantiated.
212:             * This map of services is meant to provide the factory with additional,
213:             * external services that the factory can make available to validation
214:             * services.
215:             *
216:             * @param   theServices The services to provide to the factory.
217:             */
218:            protected void setServices(Map theServices) {
219:                serviceMap.clear();
220:
221:                if (theServices != null) {
222:                    serviceMap.putAll(theServices);
223:                }
224:            } //end setServices()
225:
226:            /**
227:             * Retrieves the map of services available to this factory.
228:             *
229:             * @return Returns the map of services.
230:             */
231:            protected Map getServices() {
232:                return serviceMap;
233:            } //end getServices()
234:
235:            /**
236:             * This method is called to initialize the factory.  It is called after
237:             * the services and configuration location have been set.  After this
238:             * call, the factory should be in a state that it can retrieve
239:             * validation services.
240:             */
241:            protected void loadConfig() {
242:            } //end loadConfig()
243:        } //end ValidationFactory
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.