KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > util > typevalidator > TypeValidatorRegistry


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.util.typevalidator;
8
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13
14 /**
15  * <p>
16  * This class is used to store implementations of the {@link
17  * TypeValidator TypeValidator} interface. This class is not
18  * thread safe so it should not be used to add Validators in
19  * a thread-unsafe manner.
20  * </p>
21  *
22  * @author Brian Pontarelli
23  * @since 2.0
24  * @version 2.0
25  */

26 public class TypeValidatorRegistry {
27
28     /**
29      * The map used to store the validator implementations.
30      */

31     private static final Map JavaDoc validators = new HashMap JavaDoc();
32
33     /**
34      * The name the Inversoft number validator is stored under
35      */

36     public static final String JavaDoc NUMBER_VALIDATOR = "number";
37
38     /**
39      * The name the Inversoft String validator is stored under
40      */

41     public static final String JavaDoc STRING_VALIDATOR = "string";
42
43     /**
44      * The name the Inversoft phone validator is stored under
45      */

46     public static final String JavaDoc PHONE_VALIDATOR = "phone";
47
48     /**
49      * The name the Inversoft zipcode validator is stored under
50      */

51     public static final String JavaDoc ZIPCODE_VALIDATOR = "zipcode";
52
53     /**
54      * The name the Inversoft email validator is stored under
55      */

56     public static final String JavaDoc EMAIL_VALIDATOR = "email";
57
58     /**
59      * The name the Inversoft required validator is stored under
60      */

61     public static final String JavaDoc REQUIRED_VALIDATOR = "required";
62
63     static {
64         validators.put(NUMBER_VALIDATOR, new NumberTypeValidator());
65         validators.put(STRING_VALIDATOR, new StringTypeValidator());
66         validators.put(PHONE_VALIDATOR, new PhoneTypeValidator());
67         validators.put(ZIPCODE_VALIDATOR, new ZipcodeTypeValidator());
68         validators.put(EMAIL_VALIDATOR, new EmailTypeValidator());
69         validators.put(REQUIRED_VALIDATOR, new RequiredTypeValidator());
70     }
71
72     /**
73      * Constructor for TypeValidatorRegistry that prevents construction.
74      */

75     private TypeValidatorRegistry() {
76     }
77
78
79     /**
80      * Stores the given TypeValidator in the registry under the given name.
81      *
82      * @param name The name to store the validator under
83      * @param validator The validator to store
84      */

85     public static void storeTypeValidator(String JavaDoc name, TypeValidator validator) {
86         validators.put(name, validator);
87     }
88
89     /**
90      * Lookups the TypeValidator in the registry that was stored under the given
91      * name.
92      *
93      * @param name The name to store the validator under
94      * @return The validator stored under the given name, or null
95      */

96     public static TypeValidator lookupTypeValidator(String JavaDoc name) {
97         return (TypeValidator) validators.get(name);
98     }
99 }
Popular Tags