1 /**
2 * Copyright 2005-2013 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.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/ecl2.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.krad.datadictionary.validation.processor;
17
18 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
19 import org.kuali.rice.krad.datadictionary.validation.AttributeValueReader;
20 import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint;
21 import org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult;
22 import org.kuali.rice.krad.datadictionary.validation.result.ProcessorResult;
23
24 /**
25 * ConstraintProcessor must be implemented by constraint processors, which validate individual constraints in the
26 * data dictionary
27 *
28 * <p>The idea is that each constraint has its own processor, and that the validation service can be configured
29 * via dependency injection with a list of processors. This gives institutions the ability to easily modify how
30 * validation
31 * should be handled and to add arbitrary new constraints and constraint processors.</p>
32 *
33 * <p>An alternative might have been to put
34 * the process() method into the Constraint marker interface and have each Constraint define its own processing, but
35 * that would
36 * have forced business logic into what are naturally API classes (classes that implement Constraint). This strategy
37 * separates
38 * the two functions.</p>
39 *
40 * @author Kuali Rice Team (rice.collab@kuali.org)
41 */
42 public interface ConstraintProcessor<T, C extends Constraint> {
43
44 /**
45 * process the provided constraint
46 *
47 * @param result - holds dictionary validation results
48 * @param value - the value of the attribute
49 * @param constraint - the constraint to process
50 * @param attributeValueReader - - provides access to the attribute being validated
51 * @return the result of the constraint processing
52 * @throws AttributeValidationException
53 */
54 public ProcessorResult process(DictionaryValidationResult result, T value, C constraint,
55 AttributeValueReader attributeValueReader) throws AttributeValidationException;
56
57 /**
58 * gets a descriptive name of this constraint processor
59 *
60 * <p>e.g. @see CollectionSizeConstraintProcessor.CONSTRAINT_NAME</p>
61 *
62 * @return a descriptive name
63 */
64 public String getName();
65
66 /**
67 * gets the java class type of the constraint that this contraint processor handles
68 *
69 * @return an instance of {@code Constraint}
70 */
71 public Class<? extends Constraint> getConstraintType();
72
73 /**
74 * returns true if the processing of this constraint is something that can be opted out of by some pieces of code.
75 * The only example of this in the version under development (1.1) is the existence constraint.
76 *
77 * @return true if this processor can be turned off by some pieces of code, false otherwise
78 */
79 public boolean isOptional();
80
81 }