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 public abstract class BaseConstraintProvider<T extends Constrainable> implements ConstraintProvider<T> {
34
35
36 protected Map<String, ConstraintResolver<T>> resolverMap;
37
38 public void init() {
39 if (resolverMap == null)
40 resolverMap = new HashMap<String, ConstraintResolver<T>>();
41
42 }
43
44
45
46
47 @Override
48 public List<Constraint> getConstraints(T definition, Class<? extends Constraint> constraintType) {
49 if (resolverMap == null)
50 init();
51
52 ConstraintResolver<T> resolver = resolverMap.get(constraintType.getName());
53
54 if (resolver == null)
55 return null;
56
57 return resolver.resolve(definition);
58 }
59
60
61
62
63 public Map<String, ConstraintResolver<T>> getResolverMap() {
64 return this.resolverMap;
65 }
66
67
68
69
70 public void setResolverMap(Map<String, ConstraintResolver<T>> resolverMap) {
71 this.resolverMap = resolverMap;
72 }
73
74 }