1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary.validation.constraint.provider;
17
18 import org.kuali.rice.krad.datadictionary.validation.capability.Constrainable;
19 import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint;
20 import org.kuali.rice.krad.datadictionary.validation.constraint.resolver.ConstraintResolver;
21
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26
27
28
29
30
31
32
33
34
35 public abstract class BaseConstraintProvider<T extends Constrainable> implements ConstraintProvider<T> {
36
37 protected Map<String, ConstraintResolver<T>> resolverMap;
38
39
40
41
42
43
44
45 public void init() {
46 if (resolverMap == null) {
47 resolverMap = new HashMap<String, ConstraintResolver<T>>();
48 }
49
50 }
51
52
53
54
55
56 @Override
57 public List<Constraint> getConstraints(T definition, Class<? extends Constraint> constraintType) {
58 if (resolverMap == null) {
59 init();
60 }
61
62 ConstraintResolver<T> resolver = resolverMap.get(constraintType.getName());
63
64 if (resolver == null) {
65 return null;
66 }
67
68 return resolver.resolve(definition);
69 }
70
71
72
73
74 public Map<String, ConstraintResolver<T>> getResolverMap() {
75 return this.resolverMap;
76 }
77
78
79
80
81 public void setResolverMap(Map<String, ConstraintResolver<T>> resolverMap) {
82 this.resolverMap = resolverMap;
83 }
84
85 }