View Javadoc

1   /*
2    * Copyright 2009 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.osedu.org/licenses/ECL-2.0
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.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   * This validates a single serviceMethodinoary entry
27   * @author nwright
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 errors;
37  
38      @Override
39      public Collection<String> validate() {
40          errors = new ArrayList();
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  }