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
51   155   17   7.29
20   115   0.33   7
7     2.43  
1    
 
  PureJavaInfcWriterForOneService       Line # 35 51 0% 17 78 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2010 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.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 nwright
34    */
 
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   
 
43  0 toggle 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    * Write out the entire file
56    * @param out
57    */
 
58  0 toggle 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    // the main servKey
66  0 System.out.println("Generating servKeys API's for " + servKey);
67  0 new PureJavaInfcServiceWriter(model, directory, rootPackage, servKey, methods).write();
68   
69    // the beans's
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    // the Info interfaces's
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   
 
84  0 toggle 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   
 
96  0 toggle 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   
 
126  0 toggle 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   
 
134  0 toggle 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   
 
141  0 toggle 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    }