1 | |
package org.kuali.student.common.validator; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.HashMap; |
5 | |
import java.util.List; |
6 | |
import java.util.Map; |
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
public class ValidatorFactory { |
17 | |
|
18 | 8 | private Map<String,Validator> customValidators = null; |
19 | |
private DefaultValidatorImpl defaultValidator; |
20 | |
|
21 | 8 | private List<Validator> validatorList = new ArrayList<Validator>(); |
22 | |
|
23 | 8 | public ValidatorFactory(){ |
24 | 8 | } |
25 | |
|
26 | |
public synchronized void initializeMap(){ |
27 | |
|
28 | 0 | if(null == customValidators) { |
29 | 0 | customValidators = new HashMap<String, Validator>(); |
30 | 0 | for(Validator validator: validatorList){ |
31 | 0 | String validatorName = validator.getClass().getName(); |
32 | 0 | customValidators.put(validatorName, validator); |
33 | 0 | } |
34 | |
|
35 | |
} |
36 | 0 | } |
37 | |
|
38 | |
|
39 | |
public Validator getValidator(String customValidator) { |
40 | |
|
41 | 0 | System.out.println("Retrieving validatior:" + customValidator); |
42 | 0 | if(null == customValidators) { |
43 | 0 | initializeMap(); |
44 | |
} |
45 | |
|
46 | 0 | Validator v = customValidators.get(customValidator); |
47 | |
|
48 | 0 | if(v != null && v instanceof BaseAbstractValidator) { |
49 | 0 | BaseAbstractValidator bv = (BaseAbstractValidator)v; |
50 | 0 | bv.setValidatorFactory(this); |
51 | 0 | return bv; |
52 | |
} else { |
53 | 0 | return v; |
54 | |
} |
55 | |
} |
56 | |
|
57 | |
public Validator getValidator(){ |
58 | 0 | if(defaultValidator==null){ |
59 | 0 | defaultValidator = new DefaultValidatorImpl(); |
60 | |
} |
61 | |
|
62 | 0 | defaultValidator.setValidatorFactory(this); |
63 | 0 | return defaultValidator; |
64 | |
} |
65 | |
|
66 | |
public DefaultValidatorImpl getDefaultValidator() { |
67 | 0 | return defaultValidator; |
68 | |
} |
69 | |
|
70 | |
public void setDefaultValidator(DefaultValidatorImpl defaultValidator) { |
71 | 8 | this.defaultValidator = defaultValidator; |
72 | 8 | } |
73 | |
|
74 | |
public List<Validator> getValidatorList() { |
75 | 0 | return validatorList; |
76 | |
} |
77 | |
|
78 | |
public void setValidatorList(List<Validator> validatorList) { |
79 | 0 | this.validatorList = validatorList; |
80 | 0 | } |
81 | |
} |