Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BaseConstraintProvider |
|
| 2.0;2 |
1 | /* | |
2 | * Copyright 2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 1.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl1.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.kns.datadictionary.validation.constraint.provider; | |
17 | ||
18 | import java.util.HashMap; | |
19 | import java.util.List; | |
20 | import java.util.Map; | |
21 | ||
22 | import org.kuali.rice.kns.datadictionary.validation.capability.Constrainable; | |
23 | import org.kuali.rice.kns.datadictionary.validation.constraint.Constraint; | |
24 | import org.kuali.rice.kns.datadictionary.validation.constraint.resolver.ConstraintResolver; | |
25 | ||
26 | /** | |
27 | * A class that implements a simple in memory storage map of constraint resolvers. This provides a convenient base class | |
28 | * from which other constraint providers can be derived. | |
29 | * | |
30 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
31 | * @since 1.1 | |
32 | */ | |
33 | 0 | 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 | 0 | if (resolverMap == null) |
40 | 0 | resolverMap = new HashMap<String, ConstraintResolver<T>>(); |
41 | ||
42 | 0 | } |
43 | ||
44 | /** | |
45 | * @see org.kuali.rice.kns.datadictionary.validation.constraint.provider.ConstraintProvider#getConstraints(org.kuali.rice.kns.datadictionary.validation.capability.Constrainable, java.lang.Class) | |
46 | */ | |
47 | @Override | |
48 | public List<Constraint> getConstraints(T definition, Class<? extends Constraint> constraintType) { | |
49 | 0 | if (resolverMap == null) |
50 | 0 | init(); |
51 | ||
52 | 0 | ConstraintResolver<T> resolver = resolverMap.get(constraintType.getName()); |
53 | ||
54 | 0 | if (resolver == null) |
55 | 0 | return null; |
56 | ||
57 | 0 | return resolver.resolve(definition); |
58 | } | |
59 | ||
60 | /** | |
61 | * @return the resolverMap | |
62 | */ | |
63 | public Map<String, ConstraintResolver<T>> getResolverMap() { | |
64 | 0 | return this.resolverMap; |
65 | } | |
66 | ||
67 | /** | |
68 | * @param resolverMap the resolverMap to set | |
69 | */ | |
70 | public void setResolverMap(Map<String, ConstraintResolver<T>> resolverMap) { | |
71 | 0 | this.resolverMap = resolverMap; |
72 | 0 | } |
73 | ||
74 | } |