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
59   164   10   7.38
4   107   0.17   8
8     1.25  
1    
 
  PureJavaInfcServiceWriter       Line # 32 59 0% 10 71 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.model.ServiceContractModel;
21    import org.kuali.student.contract.model.ServiceMethod;
22    import org.kuali.student.contract.model.ServiceMethodError;
23    import org.kuali.student.contract.model.ServiceMethodParameter;
24    import org.kuali.student.contract.model.XmlType;
25    import org.kuali.student.contract.model.util.ModelFinder;
26    import org.kuali.student.contract.writer.JavaClassWriter;
27   
28    /**
29    *
30    * @author nwright
31    */
 
32    public class PureJavaInfcServiceWriter extends JavaClassWriter {
33   
34    private ServiceContractModel model;
35    private ModelFinder finder;
36    private String directory;
37    private String rootPackage;
38    private String servKey;
39    private List<ServiceMethod> methods;
40   
 
41  0 toggle public PureJavaInfcServiceWriter(ServiceContractModel model,
42    String directory,
43    String rootPackage,
44    String servKey,
45    List<ServiceMethod> methods) {
46  0 super(directory, calcPackage(servKey, rootPackage), calcClassName(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  0 this.methods = methods;
53    }
54   
 
55  0 toggle public static String calcPackage(String servKey, String rootPackage) {
56  0 String pack = rootPackage + "." + servKey.toLowerCase() + ".";
57    // StringBuffer buf = new StringBuffer (service.getVersion ().length ());
58    // for (int i = 0; i < service.getVersion ().length (); i ++)
59    // {
60    // char c = service.getVersion ().charAt (i);
61    // c = Character.toLowerCase (c);
62    // if (Character.isLetter (c))
63    // {
64    // buf.append (c);
65    // continue;
66    // }
67    // if (Character.isDigit (c))
68    // {
69    // buf.append (c);
70    // }
71    // }
72    // pack = pack + buf.toString ();
73  0 pack = pack + "api";
74  0 return pack;
75    }
76   
 
77  0 toggle public static String calcClassName(String servKey) {
78  0 return GetterSetterNameCalculator.calcInitUpper(servKey + "ServiceInfc");
79    }
80   
81    /**
82    * Write out the entire file
83    * @param out
84    */
 
85  0 toggle public void write() {
86  0 indentPrintln("public interface " + calcClassName(servKey));
87  0 openBrace();
88   
89  0 for (ServiceMethod method : methods) {
90  0 indentPrintln("");
91  0 indentPrintln("/**");
92  0 indentPrintWrappedComment(method.getDescription());
93  0 indentPrintln("* ");
94  0 for (ServiceMethodParameter param : method.getParameters()) {
95  0 indentPrintWrappedComment("@param " + param.getName() + " - "
96    + param.getType() + " - "
97    + param.getDescription());
98    }
99  0 indentPrintWrappedComment("@return " + method.getReturnValue().
100    getDescription());
101  0 indentPrintln("*/");
102  0 String type = method.getReturnValue().getType();
103  0 String realType = stripList(PureJavaInfcInfcWriter.calcClassName(type));
104  0 indentPrint("public " + calcType(type, realType) + " " + method.getName()
105    + "(");
106    // now do parameters
107  0 String comma = "";
108  0 for (ServiceMethodParameter param : method.getParameters()) {
109  0 type = param.getType();
110  0 realType = stripList(PureJavaInfcInfcWriter.calcClassName(type));
111  0 print(comma);
112  0 print(calcType(type, realType));
113  0 print(" ");
114  0 print(param.getName());
115  0 comma = ", ";
116    }
117  0 println(")");
118    // now do exceptions
119  0 comma = "throws ";
120  0 incrementIndent();
121  0 for (ServiceMethodError error : method.getErrors()) {
122  0 indentPrint(comma);
123  0 String exceptionClassName = calcExceptionClassName(error);
124  0 String exceptionPackageName = this.calcExceptionPackageName(error);
125  0 println(exceptionClassName);
126  0 this.importsAdd(exceptionPackageName + "." + exceptionClassName);
127  0 comma = " ,";
128    }
129  0 decrementIndent();
130  0 indentPrintln(";");
131   
132    }
133   
134  0 closeBrace();
135   
136  0 this.writeJavaClassAndImportsOutToFile();
137  0 this.getOut().close();
138    }
139   
 
140  0 toggle private String stripList(String str) {
141  0 return GetterSetterNameCalculator.stripList(str);
142    }
143   
 
144  0 toggle private String calcExceptionClassName(ServiceMethodError error) {
145  0 if (error.getClassName() == null) {
146  0 return ServiceExceptionWriter.calcClassName(error.getType());
147    }
148  0 return error.getClassName();
149    }
150   
 
151  0 toggle private String calcExceptionPackageName(ServiceMethodError error) {
152  0 if (error.getClassName() == null) {
153  0 return ServiceExceptionWriter.calcPackage(rootPackage);
154    }
155  0 return error.getPackageName();
156    }
157   
 
158  0 toggle private String calcType(String type, String realType) {
159  0 XmlType t = finder.findXmlType(this.stripList(type));
160  0 String pckName = PureJavaInfcInfcWriter.calcPackage(t.getService(), rootPackage);
161  0 return MessageStructureTypeCalculator.calculate(this, model, type, realType,
162    pckName);
163    }
164    }