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.List; |
19 | |
|
20 | |
import org.kuali.student.contract.exception.DictionaryExecutionException; |
21 | |
import org.kuali.student.contract.model.MessageStructure; |
22 | |
import org.kuali.student.contract.model.ServiceContractModel; |
23 | |
import org.kuali.student.contract.model.XmlType; |
24 | |
import org.kuali.student.contract.model.util.ModelFinder; |
25 | |
import org.kuali.student.contract.writer.JavaClassWriter; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class PureJavaInfcInfcWriter extends JavaClassWriter { |
32 | |
|
33 | |
private ServiceContractModel model; |
34 | |
private ModelFinder finder; |
35 | |
private String directory; |
36 | |
private String rootPackage; |
37 | |
private String service; |
38 | |
private XmlType xmlType; |
39 | |
|
40 | |
public PureJavaInfcInfcWriter(ServiceContractModel model, |
41 | |
String directory, |
42 | |
String rootPackage, |
43 | |
String service, |
44 | |
XmlType xmlType) { |
45 | 0 | super(directory, calcPackage(service, rootPackage), calcClassName( |
46 | |
xmlType.getName())); |
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.service = service; |
52 | 0 | this.xmlType = xmlType; |
53 | 0 | } |
54 | |
|
55 | |
public static String calcPackage(String service, String rootPackage) { |
56 | 0 | if (service.contains(",")) { |
57 | 0 | service = "common"; |
58 | |
} |
59 | 0 | return PureJavaInfcServiceWriter.calcPackage(service, rootPackage); |
60 | |
} |
61 | |
|
62 | |
public static String calcClassName(String name) { |
63 | 0 | if (name.endsWith("Info")) { |
64 | 0 | name = name.substring(0, name.length() - "Info".length()); |
65 | 0 | name = name + "Infc"; |
66 | 0 | } else if (name.endsWith("InfoList")) { |
67 | 0 | name = name.substring(0, name.length() - "InfoList".length()); |
68 | 0 | name = name + "InfcList"; |
69 | |
} |
70 | 0 | return GetterSetterNameCalculator.calcInitUpper(name); |
71 | |
} |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
public void write() { |
78 | 0 | indentPrintln("public interface " + calcClassName(xmlType.getName())); |
79 | 0 | openBrace(); |
80 | |
|
81 | 0 | List<MessageStructure> list = finder.findMessageStructures(xmlType.getName()); |
82 | 0 | if (list.size() == 0) { |
83 | 0 | throw new DictionaryExecutionException( |
84 | |
"xmlType " + xmlType.getName() |
85 | |
+ " has no fields defined in the message structure tab"); |
86 | |
} |
87 | 0 | for (MessageStructure ms : list) { |
88 | 0 | String realType = stripList(calcClassName(ms.getType())); |
89 | 0 | String type = this.calcFieldTypeToUse(ms.getType(), realType); |
90 | 0 | indentPrintln(""); |
91 | 0 | indentPrintln("/**"); |
92 | 0 | indentPrintWrappedComment("Set " + ms.getName()); |
93 | 0 | indentPrintln("*"); |
94 | 0 | indentPrintln("* Type: " + ms.getType()); |
95 | 0 | indentPrintln("*"); |
96 | 0 | indentPrintWrappedComment(ms.getDescription()); |
97 | 0 | indentPrintln("*/"); |
98 | 0 | indentPrintln("public void " + calcSetter(ms) + "(" + type + " " + initLower( |
99 | |
ms.getShortName()) + ");"); |
100 | |
|
101 | |
|
102 | 0 | indentPrintln(""); |
103 | 0 | indentPrintln("/**"); |
104 | 0 | indentPrintWrappedComment("Get " + ms.getName()); |
105 | 0 | indentPrintln("*"); |
106 | 0 | indentPrintln("* Type: " + ms.getType()); |
107 | 0 | indentPrintln("*"); |
108 | 0 | indentPrintWrappedComment(ms.getDescription()); |
109 | 0 | indentPrintln("*/"); |
110 | 0 | indentPrintln("public " + type + " " + calcGetter(ms) + "();"); |
111 | 0 | indentPrintln(""); |
112 | |
|
113 | 0 | indentPrintln(""); |
114 | 0 | } |
115 | 0 | indentPrintln(""); |
116 | 0 | closeBrace(); |
117 | |
|
118 | 0 | this.writeJavaClassAndImportsOutToFile(); |
119 | 0 | this.getOut().close(); |
120 | 0 | } |
121 | |
|
122 | |
private String stripList(String str) { |
123 | 0 | return GetterSetterNameCalculator.stripList(str); |
124 | |
} |
125 | |
|
126 | |
private String initLower(String str) { |
127 | 0 | return GetterSetterNameCalculator.calcInitLower(str); |
128 | |
} |
129 | |
|
130 | |
private String calcGetter(MessageStructure ms) { |
131 | 0 | return new GetterSetterNameCalculator(ms, this, model).calcGetter(); |
132 | |
} |
133 | |
|
134 | |
private String calcSetter(MessageStructure ms) { |
135 | 0 | return new GetterSetterNameCalculator(ms, this, model).calcSetter(); |
136 | |
} |
137 | |
|
138 | |
private String calcFieldTypeToUse(String type, String realType) { |
139 | 0 | XmlType t = finder.findXmlType(this.stripList(type)); |
140 | 0 | String pckName = calcPackage(t.getService(), rootPackage); |
141 | 0 | return MessageStructureTypeCalculator.calculate(this, model, type, realType, |
142 | |
pckName); |
143 | |
} |
144 | |
} |