Clover Coverage Report - KS Contract Documentation Generator 0.0.1-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
56   144   13   6.22
8   103   0.23   9
9     1.44  
1    
 
  PureJavaInfcInfcWriter       Line # 31 56 0% 13 73 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.osedu.org/licenses/ECL-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
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    * @author nwright
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  0 toggle 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    }
54   
 
55  0 toggle 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  0 toggle 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    * Write out the entire file
75    * @param out
76    */
 
77  0 toggle 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    }
115  0 indentPrintln("");
116  0 closeBrace();
117   
118  0 this.writeJavaClassAndImportsOutToFile();
119  0 this.getOut().close();
120    }
121   
 
122  0 toggle private String stripList(String str) {
123  0 return GetterSetterNameCalculator.stripList(str);
124    }
125   
 
126  0 toggle private String initLower(String str) {
127  0 return GetterSetterNameCalculator.calcInitLower(str);
128    }
129   
 
130  0 toggle private String calcGetter(MessageStructure ms) {
131  0 return new GetterSetterNameCalculator(ms, this, model).calcGetter();
132    }
133   
 
134  0 toggle private String calcSetter(MessageStructure ms) {
135  0 return new GetterSetterNameCalculator(ms, this, model).calcSetter();
136    }
137   
 
138  0 toggle 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    }