1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.validation.impl;
17
18 import java.util.List;
19
20 import org.kuali.ole.sys.document.validation.Validation;
21 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
22
23
24
25
26
27 public class CompositeValidation implements Validation {
28 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CompositeValidation.class);
29
30 protected List<Validation> subValidations;
31 protected boolean shouldQuitOnFail = false;
32
33
34
35
36
37 public boolean validate(AttributedDocumentEvent event) {
38 if (subValidations == null) {
39 throw new IllegalStateException("A composite validation must have children validations");
40 }
41
42 boolean result = true;
43 boolean currResult;
44
45 for (Validation validation: subValidations) {
46 currResult = validation.stageValidation(event);
47 result &= currResult;
48
49 if(!currResult) {
50 if ( LOG.isDebugEnabled() ) {
51 LOG.debug(validation.getClass() + " failed");
52 }
53 }
54
55 if (!currResult && validation.shouldQuitOnFail()) {
56 break;
57 }
58 }
59
60 return result;
61 }
62
63
64
65
66
67 public boolean stageValidation(AttributedDocumentEvent event) {
68 return validate(event);
69 }
70
71
72
73
74
75 public List<Validation> getValidations() {
76 return this.subValidations;
77 }
78
79
80
81
82
83 public void setValidations(List<Validation> validations) {
84 this.subValidations = validations;
85 }
86
87
88
89
90
91 public boolean shouldQuitOnFail() {
92 return shouldQuitOnFail;
93 }
94
95
96
97
98
99 public void setQuitOnFail(boolean shouldQuitOnFail) {
100 this.shouldQuitOnFail = shouldQuitOnFail;
101 }
102 }