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.LengthConstrainable; 020import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint; 021 022import java.util.Collections; 023import java.util.List; 024 025/** 026 * An object that returns the constrainable definition itself as a list for a definition implementing the capability {@link Constrainable}. 027 * This definition must also implement the interface {@link Constraint}, or a ClassCastException will be thrown. 028 * 029 * An example is {@link LengthConstrainable}, where members of the definition itself need to be made available to the ConstraintProcessor. 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033public class DefinitionConstraintResolver<T extends Constrainable> implements ConstraintResolver<T> { 034 035 @Override 036 public <C extends Constraint> List<C> resolve(T definition) throws ClassCastException { 037 if (definition instanceof Constraint) { 038 @SuppressWarnings("unchecked") 039 C constraint = (C)definition; 040 return Collections.singletonList(constraint); 041 } 042/* else if(definiton instanceof InputField){ 043 C constraint = (C)definition.get 044 }*/ 045 throw new ClassCastException("DefinitionConstraintResolver can only be used for a definition that implements both Constraint and Constrainable, or derives from a class that does."); 046 } 047 048}