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 java.util.ArrayList; |
19 | |
import java.util.Collection; |
20 | |
|
21 | |
import org.kuali.student.contract.model.ServiceContractModel; |
22 | |
import org.kuali.student.contract.model.XmlType; |
23 | |
import org.kuali.student.contract.model.util.ModelFinder; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class XmlTypesValidator implements ModelValidator { |
30 | |
|
31 | |
private ServiceContractModel model; |
32 | |
private ModelFinder finder; |
33 | |
private XmlType xmlType; |
34 | |
|
35 | 0 | public XmlTypesValidator(XmlType xmlType, ServiceContractModel model) { |
36 | 0 | this.model = model; |
37 | 0 | this.finder = new ModelFinder(model); |
38 | 0 | this.xmlType = xmlType; |
39 | 0 | } |
40 | |
private Collection errors; |
41 | |
|
42 | |
@Override |
43 | |
public Collection<String> validate() { |
44 | |
|
45 | 0 | errors = new ArrayList(); |
46 | 0 | basicValidation(); |
47 | 0 | return errors; |
48 | |
} |
49 | |
|
50 | |
private void basicValidation() { |
51 | 0 | if (xmlType.getName().equals("")) { |
52 | 0 | addError("Name is required"); |
53 | |
} |
54 | 0 | if (xmlType.getName().equalsIgnoreCase("Object")) { |
55 | 0 | addError("Object is reserved and cannot be used as the name of an XmlType"); |
56 | |
} |
57 | 0 | if (xmlType.getName().equalsIgnoreCase("ObjectList")) { |
58 | 0 | addError("Object is reserved and cannot be used as the name of an XmlType"); |
59 | |
} |
60 | 0 | if (!xmlType.getService().equals("")) { |
61 | 0 | for (String srv : xmlType.getService().split(",")) { |
62 | 0 | if (finder.findService(srv.trim()) == null) { |
63 | 0 | addError("Service, [" + srv |
64 | |
+ "] could not be found in the list of services"); |
65 | |
} |
66 | |
} |
67 | |
} |
68 | 0 | } |
69 | |
|
70 | |
private void addError(String msg) { |
71 | 0 | String error = "Error in xmlType entry: " + xmlType.getName() + ": " + msg; |
72 | 0 | if (!errors.contains(error)) { |
73 | 0 | errors.add(error); |
74 | |
} |
75 | 0 | } |
76 | |
} |