001/** 002 * Copyright 2005-2016 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.resolver; 017 018import org.kuali.rice.krad.datadictionary.validation.capability.Constrainable; 019import org.kuali.rice.krad.datadictionary.validation.capability.SimpleConstrainable; 020import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint; 021import org.kuali.rice.krad.uif.field.InputField; 022 023import java.util.ArrayList; 024import java.util.Collections; 025import java.util.List; 026 027public class SimpleConstraintResolver<T extends Constrainable> implements ConstraintResolver<T> { 028 029 /** 030 * Return SimpleConstraint if SimpleConstrainable, otherwise return an empty list. 031 * @param definition Definition to extract a SimpleConstraint from 032 * @param <C> SimpleConstraint 033 * @return SimpleConstraint if SimpleConstrainable, otherwise return an empty list. 034 */ 035 public <C extends Constraint> List<C> resolve(T definition) { 036 if(definition instanceof SimpleConstrainable){ 037 C simpleConstraint = (C)(((SimpleConstrainable)definition).getSimpleConstraint()); 038 return Collections.singletonList(simpleConstraint); 039 } 040 else{ 041 return new ArrayList<C>(); 042 } 043 } 044}