1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.contract.writer.service; |
17 |
|
|
18 |
|
import java.util.HashSet; |
19 |
|
import java.util.List; |
20 |
|
import java.util.Set; |
21 |
|
|
22 |
|
import org.kuali.student.contract.model.MessageStructure; |
23 |
|
import org.kuali.student.contract.model.ServiceContractModel; |
24 |
|
import org.kuali.student.contract.model.ServiceMethod; |
25 |
|
import org.kuali.student.contract.model.ServiceMethodParameter; |
26 |
|
import org.kuali.student.contract.model.ServiceMethodReturnValue; |
27 |
|
import org.kuali.student.contract.model.XmlType; |
28 |
|
import org.kuali.student.contract.model.util.ModelFinder; |
29 |
|
import org.kuali.student.contract.model.validation.DictionaryValidationException; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
@author |
34 |
|
|
|
|
| 0% |
Uncovered Elements: 78 (78) |
Complexity: 17 |
Complexity Density: 0.33 |
|
35 |
|
public class PureJavaInfcWriterForOneService { |
36 |
|
|
37 |
|
private ServiceContractModel model; |
38 |
|
private ModelFinder finder; |
39 |
|
private String directory; |
40 |
|
private String rootPackage; |
41 |
|
private String servKey; |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
43 |
0
|
public PureJavaInfcWriterForOneService(ServiceContractModel model,... |
44 |
|
String directory, |
45 |
|
String rootPackage, |
46 |
|
String servKey) { |
47 |
0
|
this.model = model; |
48 |
0
|
this.finder = new ModelFinder(model); |
49 |
0
|
this.directory = directory; |
50 |
0
|
this.rootPackage = rootPackage; |
51 |
0
|
this.servKey = servKey; |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@param |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
|
58 |
0
|
public void write() {... |
59 |
0
|
List<ServiceMethod> methods = finder.getServiceMethodsInService(servKey); |
60 |
0
|
if (methods.size() == 0) { |
61 |
0
|
System.out.println("No methods defined for servKey: " + servKey); |
62 |
0
|
return; |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
0
|
System.out.println("Generating servKeys API's for " + servKey); |
67 |
0
|
new PureJavaInfcServiceWriter(model, directory, rootPackage, servKey, methods).write(); |
68 |
|
|
69 |
|
|
70 |
0
|
System.out.println("Generating info interfaces"); |
71 |
0
|
for (XmlType xmlType : getXmlTypesUsedJustByService()) { |
72 |
0
|
System.out.println("Generating Beans for " + xmlType.getName()); |
73 |
0
|
new PureJavaInfcBeanWriter(model, directory, rootPackage, servKey, xmlType).write(); |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
0
|
System.out.println("Generating Info interfaces"); |
78 |
0
|
for (XmlType xmlType : getXmlTypesUsedJustByService()) { |
79 |
0
|
System.out.println("Generating info interface for " + xmlType.getName()); |
80 |
0
|
new PureJavaInfcInfcWriter(model, directory, rootPackage, servKey, xmlType).write(); |
81 |
|
} |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
84 |
0
|
private Set<XmlType> getXmlTypesUsedJustByService() {... |
85 |
0
|
Set<XmlType> set = new HashSet(); |
86 |
0
|
for (XmlType type : model.getXmlTypes()) { |
87 |
0
|
if (type.getService().equalsIgnoreCase(servKey)) { |
88 |
0
|
if (type.getPrimitive().equalsIgnoreCase(XmlType.COMPLEX)) { |
89 |
0
|
set.add(type); |
90 |
|
} |
91 |
|
} |
92 |
|
} |
93 |
0
|
return set; |
94 |
|
} |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
96 |
0
|
private Set<XmlType> getXmlTypesUsedByService(List<ServiceMethod> methods) {... |
97 |
0
|
Set<XmlType> set = new HashSet(); |
98 |
0
|
for (ServiceMethod method : methods) { |
99 |
0
|
if (method.getReturnValue() != null) { |
100 |
0
|
ServiceMethodReturnValue ret = method.getReturnValue(); |
101 |
0
|
XmlType xmlType = finder.findXmlType(stripListFromType(ret.getType())); |
102 |
0
|
if (xmlType == null) { |
103 |
0
|
throw new DictionaryValidationException("Method " + method.getService() |
104 |
|
+ "." + method.getName() |
105 |
|
+ "returns an unknown type, " |
106 |
|
+ ret.getType()); |
107 |
|
} |
108 |
0
|
addTypeAndAllSubTypes(set, xmlType); |
109 |
|
} |
110 |
0
|
for (ServiceMethodParameter param : method.getParameters()) { |
111 |
0
|
XmlType xmlType = finder.findXmlType(stripListFromType(param.getType())); |
112 |
0
|
if (xmlType == null) { |
113 |
0
|
throw new DictionaryValidationException("Parameter " |
114 |
|
+ method.getService() + "." |
115 |
|
+ method.getName() + "." |
116 |
|
+ param.getName() |
117 |
|
+ "has an unknown type, " |
118 |
|
+ param.getType()); |
119 |
|
} |
120 |
0
|
addTypeAndAllSubTypes(set, xmlType); |
121 |
|
} |
122 |
|
} |
123 |
0
|
return set; |
124 |
|
} |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 1 |
|
126 |
0
|
private void addTypeAndAllSubTypes(Set<XmlType> set, XmlType xmlType) {... |
127 |
0
|
if (xmlType.getPrimitive().equalsIgnoreCase(XmlType.COMPLEX)) { |
128 |
0
|
if (set.add(xmlType)) { |
129 |
0
|
addXmlTypesUsedByMessageStructure(set, xmlType); |
130 |
|
} |
131 |
|
} |
132 |
|
} |
133 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
134 |
0
|
private String stripListFromType(String type) {... |
135 |
0
|
if (type.endsWith("List")) { |
136 |
0
|
type = type.substring(0, type.length() - "List".length()); |
137 |
|
} |
138 |
0
|
return type; |
139 |
|
} |
140 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
141 |
0
|
private void addXmlTypesUsedByMessageStructure(Set<XmlType> set,... |
142 |
|
XmlType xmlType) { |
143 |
0
|
ModelFinder finder = new ModelFinder(model); |
144 |
0
|
for (MessageStructure ms : finder.findMessageStructures(xmlType.getName())) { |
145 |
0
|
XmlType subType = finder.findXmlType(stripListFromType(ms.getType())); |
146 |
0
|
if (subType == null) { |
147 |
0
|
throw new DictionaryValidationException("MessageStructure field " |
148 |
|
+ ms.getId() |
149 |
|
+ " has an unknown type, " |
150 |
|
+ ms.getType()); |
151 |
|
} |
152 |
0
|
addTypeAndAllSubTypes(set, subType); |
153 |
|
} |
154 |
|
} |
155 |
|
} |