1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.contract.model.validation;
17
18 import org.kuali.student.contract.model.ServiceContractModel;
19 import org.kuali.student.contract.model.ServiceMethod;
20 import org.kuali.student.contract.model.XmlType;
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24
25
26
27
28
29 public class ServiceContractModelValidator implements ModelValidator {
30
31 private ServiceContractModel model;
32
33 public ServiceContractModelValidator(ServiceContractModel model) {
34 this.model = model;
35 }
36 private Collection<String> errors;
37
38 @Override
39 public Collection<String> validate() {
40 errors = new ArrayList<String>();
41 basicValidation();
42 this.validateServiceMethods();
43 validateXmlTypes();
44 return errors;
45 }
46
47 private void validateServiceMethods() {
48 for (ServiceMethod method : model.getServiceMethods()) {
49 errors.addAll(new ServiceMethodValidator(method, model).validate());
50 }
51 }
52
53 private void validateXmlTypes() {
54 if (model.getXmlTypes().size() == 0) {
55 addError("No xmlTypes found");
56 }
57 for (XmlType xmlType : model.getXmlTypes()) {
58 XmlTypesValidator validator = new XmlTypesValidator(xmlType, model);
59 errors.addAll(validator.validate());
60 }
61 }
62
63 private void basicValidation() {
64 if (model.getServiceMethods().size() == 0) {
65 addError("no service methods have been defined");
66 }
67 }
68
69 private void addError(String msg) {
70 String error = "Error in service methods: " + msg;
71 if (!errors.contains(error)) {
72 errors.add(error);
73 }
74 }
75 }