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 | |
|
32 | |
private ServiceContractModel model; |
33 | |
private ModelFinder finder; |
34 | |
private XmlType xmlType; |
35 | |
|
36 | |
public XmlTypesValidator (XmlType xmlType, ServiceContractModel model) |
37 | 0 | { |
38 | 0 | this.model = model; |
39 | 0 | this.finder = new ModelFinder (model); |
40 | 0 | this.xmlType = xmlType; |
41 | 0 | } |
42 | |
private Collection errors; |
43 | |
|
44 | |
@Override |
45 | |
public Collection<String> validate () |
46 | |
{ |
47 | |
|
48 | 0 | errors = new ArrayList (); |
49 | 0 | basicValidation (); |
50 | 0 | return errors; |
51 | |
} |
52 | |
|
53 | |
private void basicValidation () |
54 | |
{ |
55 | 0 | if (xmlType.getName ().equals ("")) |
56 | |
{ |
57 | 0 | addError ("Name is required"); |
58 | |
} |
59 | 0 | if (xmlType.getName ().equalsIgnoreCase ("Object")) |
60 | |
{ |
61 | 0 | addError ("Object is reserved and cannot be used as the name of an XmlType"); |
62 | |
} |
63 | 0 | if (xmlType.getName ().equalsIgnoreCase ("ObjectList")) |
64 | |
{ |
65 | 0 | addError ("Object is reserved and cannot be used as the name of an XmlType"); |
66 | |
} |
67 | 0 | if ( ! xmlType.getService ().equals ("")) |
68 | |
{ |
69 | 0 | for (String srv : xmlType.getService ().split (",")) |
70 | |
{ |
71 | 0 | if (finder.findService (srv.trim ()) == null) |
72 | |
{ |
73 | 0 | addError ("Service, [" + srv |
74 | |
+ "] could not be found in the list of services"); |
75 | |
} |
76 | |
} |
77 | |
} |
78 | 0 | } |
79 | |
|
80 | |
private void addError (String msg) |
81 | |
{ |
82 | 0 | String error = "Error in xmlType entry: " + xmlType.getName () + ": " + msg; |
83 | 0 | if ( ! errors.contains (error)) |
84 | |
{ |
85 | 0 | errors.add (error); |
86 | |
} |
87 | 0 | } |
88 | |
} |