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 super(directory, calcPackage(service, rootPackage), calcClassName(
46 xmlType.getName()));
47 this.model = model;
48 this.finder = new ModelFinder(model);
49 this.directory = directory;
50 this.rootPackage = rootPackage;
51 this.service = service;
52 this.xmlType = xmlType;
53 }
54
55 public static String calcPackage(String service, String rootPackage) {
56 if (service.contains(",")) {
57 service = "common";
58 }
59 return PureJavaInfcServiceWriter.calcPackage(service, rootPackage);
60 }
61
62 public static String calcClassName(String name) {
63 if (name.endsWith("Info")) {
64 name = name.substring(0, name.length() - "Info".length());
65 name = name + "Infc";
66 } else if (name.endsWith("InfoList")) {
67 name = name.substring(0, name.length() - "InfoList".length());
68 name = name + "InfcList";
69 }
70 return GetterSetterNameCalculator.calcInitUpper(name);
71 }
72
73
74
75
76
77 public void write() {
78 indentPrintln("public interface " + calcClassName(xmlType.getName()));
79 openBrace();
80
81 List<MessageStructure> list = finder.findMessageStructures(xmlType.getName());
82
83
84
85
86
87 for (MessageStructure ms : list) {
88 if (ms.getId().equals ("RegistrationGroupTemplateInfo.activityOfferingCombinations")) {
89 continue;
90 }
91 String realType = stripList(calcClassName(ms.getType()));
92 String type = this.calcFieldTypeToUse(ms.getType(), realType);
93 indentPrintln("");
94 indentPrintln("/**");
95 indentPrintWrappedComment("Set " + ms.getName());
96 indentPrintln("*");
97 indentPrintln("* Type: " + ms.getType());
98 indentPrintln("*");
99 indentPrintWrappedComment(ms.getDescription());
100 indentPrintln("*/");
101 indentPrintln("public void " + calcSetter(ms) + "(" + type + " " + initLower(
102 ms.getShortName()) + ");");
103
104
105 indentPrintln("");
106 indentPrintln("/**");
107 indentPrintWrappedComment("Get " + ms.getName());
108 indentPrintln("*");
109 indentPrintln("* Type: " + ms.getType());
110 indentPrintln("*");
111 indentPrintWrappedComment(ms.getDescription());
112 indentPrintln("*/");
113 indentPrintln("public " + type + " " + calcGetter(ms) + "();");
114 indentPrintln("");
115
116 indentPrintln("");
117 }
118 indentPrintln("");
119 closeBrace();
120
121 this.writeJavaClassAndImportsOutToFile();
122 this.getOut().close();
123 }
124
125 private String stripList(String str) {
126 return GetterSetterNameCalculator.stripList(str);
127 }
128
129 private String initLower(String str) {
130 return GetterSetterNameCalculator.calcInitLower(str);
131 }
132
133 private String calcGetter(MessageStructure ms) {
134 return new GetterSetterNameCalculator(ms, this, model).calcGetter();
135 }
136
137 private String calcSetter(MessageStructure ms) {
138 return new GetterSetterNameCalculator(ms, this, model).calcSetter();
139 }
140
141 private String calcFieldTypeToUse(String type, String realType) {
142 XmlType t = finder.findXmlType(this.stripList(type));
143 String pckName = calcPackage(t.getService(), rootPackage);
144 return MessageStructureTypeCalculator.calculate(this, model, type, realType,
145 pckName);
146 }
147 }