1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.remote.impl.mojo;
17
18 import java.util.Collection;
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Set;
24
25 import org.kuali.student.contract.model.Service;
26 import org.kuali.student.contract.model.ServiceContractModel;
27 import org.kuali.student.contract.model.ServiceMethod;
28 import org.kuali.student.contract.model.ServiceMethodError;
29 import org.kuali.student.contract.model.XmlType;
30 import org.kuali.student.contract.model.impl.ServiceContractModelPescXsdLoader;
31 import org.kuali.student.contract.model.util.ServicesFilter;
32 import org.kuali.student.contract.model.validation.DictionaryValidationException;
33 import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37
38
39
40
41 public class RemoteImplWriter {
42
43 private static Logger log = LoggerFactory.getLogger(RemoteImplWriter.class);
44
45 private ServiceContractModel model;
46 private String directory;
47 private String rootPackage;
48 public static final String DEFAULT_ROOT_PACKAGE = "org.kuali.student.service.remote.impl";
49 private ServicesFilter filter;
50
51 public RemoteImplWriter(ServiceContractModel model,
52 String directory,
53 String rootPackage,
54 ServicesFilter filter) {
55 this.model = model;
56 this.directory = directory;
57 this.rootPackage = rootPackage;
58 this.filter = filter;
59 }
60
61
62
63
64
65
66 public void write() {
67 this.validate();
68
69 for (Service service : filterServices()) {
70 new RemoteImplWriterForOneService(model, directory, rootPackage, service.getKey()).write();
71 new RemoteImplServiceSpringBeanWriter(model, directory, rootPackage, service.getKey()).write();
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 }
89
90 private Set<XmlType> getXmlTypesUsedByMoreThanOneByService() {
91 Set<XmlType> set = new HashSet();
92 for (XmlType type : model.getXmlTypes()) {
93 if (type.getService().contains(",")) {
94 if (type.getPrimitive().equalsIgnoreCase(XmlType.COMPLEX)) {
95 log.info(type.getName() + "==>" + type.getService());
96 set.add(type);
97 }
98 }
99 }
100 return set;
101 }
102
103 private Map<String, ServiceMethodError> getServiceMethodErrors() {
104 Map<String, ServiceMethodError> errors = new HashMap();
105 for (ServiceMethod method : model.getServiceMethods()) {
106 for (ServiceMethodError error : method.getErrors()) {
107 errors.put(error.getType(), error);
108 }
109 }
110 return errors;
111 }
112
113 private List<Service> filterServices() {
114 if (filter == null) {
115 return model.getServices();
116 }
117 return filter.filter(model.getServices());
118 }
119
120 private void validate() {
121 Collection<String> errors
122 = new ServiceContractModelValidator(model).validate();
123 if (errors.size() > 0) {
124 StringBuffer buf = new StringBuffer();
125 buf.append(errors.size() + " errors found while validating the data.");
126 int cnt = 0;
127 for (String msg : errors) {
128 cnt++;
129 buf.append("\n");
130 buf.append("*error*" + cnt + ":" + msg);
131 }
132
133 throw new DictionaryValidationException(buf.toString());
134 }
135 }
136 }