001/** 002 * Copyright 2005-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.datadictionary.validation.constraint.provider; 017 018import org.kuali.rice.krad.datadictionary.validation.capability.Constrainable; 019import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint; 020import org.kuali.rice.krad.datadictionary.validation.constraint.resolver.ConstraintResolver; 021 022import java.util.HashMap; 023import java.util.List; 024import java.util.Map; 025 026/** 027 * A class that implements a simple in memory storage map of constraint resolvers. This provides a convenient base class 028 * from which other constraint providers can be derived. 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 * @since 1.1 032 */ 033public abstract class BaseConstraintProvider<T extends Constrainable> implements ConstraintProvider<T> { 034 035 036 protected Map<String, ConstraintResolver<T>> resolverMap; 037 038 public void init() { 039 if (resolverMap == null) 040 resolverMap = new HashMap<String, ConstraintResolver<T>>(); 041 042 } 043 044 /** 045 * @see org.kuali.rice.krad.datadictionary.validation.constraint.provider.ConstraintProvider#getConstraints(org.kuali.rice.krad.datadictionary.validation.capability.Constrainable, java.lang.Class) 046 */ 047 @Override 048 public List<Constraint> getConstraints(T definition, Class<? extends Constraint> constraintType) { 049 if (resolverMap == null) 050 init(); 051 052 ConstraintResolver<T> resolver = resolverMap.get(constraintType.getName()); 053 054 if (resolver == null) 055 return null; 056 057 return resolver.resolve(definition); 058 } 059 060 /** 061 * @return the resolverMap 062 */ 063 public Map<String, ConstraintResolver<T>> getResolverMap() { 064 return this.resolverMap; 065 } 066 067 /** 068 * @param resolverMap the resolverMap to set 069 */ 070 public void setResolverMap(Map<String, ConstraintResolver<T>> resolverMap) { 071 this.resolverMap = resolverMap; 072 } 073 074}