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