| 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.Date; |
| 19 | |
import java.util.List; |
| 20 | |
import java.util.Map; |
| 21 | |
|
| 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.model.validation.DictionaryValidationException; |
| 26 | |
import org.kuali.student.contract.writer.JavaClassWriter; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 0 | public class MessageStructureTypeCalculator { |
| 33 | |
|
| 34 | |
public static String calculate(ServiceContractModel model, |
| 35 | |
String type, String realType) { |
| 36 | 0 | return calculate(null, model, type, realType, ""); |
| 37 | |
} |
| 38 | |
|
| 39 | |
public static String calculate(JavaClassWriter writer, |
| 40 | |
ServiceContractModel model, |
| 41 | |
String type, |
| 42 | |
String realType, |
| 43 | |
String importPackage) { |
| 44 | 0 | if (type.equalsIgnoreCase("Map<String, String>")) { |
| 45 | 0 | importsAdd(writer, Map.class.getName()); |
| 46 | 0 | return "Map<String, String>"; |
| 47 | |
} |
| 48 | |
|
| 49 | 0 | if (type.endsWith("List")) { |
| 50 | 0 | importsAdd(writer, List.class.getName()); |
| 51 | 0 | type = type.substring(0, type.length() - "List".length()); |
| 52 | 0 | return "List<" + calculate(writer, model, type, realType, importPackage) + ">"; |
| 53 | |
} |
| 54 | 0 | XmlType xmlType = new ModelFinder(model).findXmlType(type); |
| 55 | 0 | if (xmlType == null) { |
| 56 | 0 | throw new DictionaryValidationException("No XmlType found for type " + type); |
| 57 | |
} |
| 58 | |
|
| 59 | 0 | if (xmlType.getPrimitive().equalsIgnoreCase("Primitive")) { |
| 60 | 0 | if (type.equalsIgnoreCase("string")) { |
| 61 | 0 | return "String"; |
| 62 | |
} |
| 63 | 0 | if (type.equalsIgnoreCase("date")) { |
| 64 | 0 | importsAdd(writer, Date.class.getName()); |
| 65 | 0 | return "Date"; |
| 66 | |
} |
| 67 | 0 | if (type.equalsIgnoreCase("datetime")) { |
| 68 | 0 | importsAdd(writer, Date.class.getName()); |
| 69 | 0 | return "Date"; |
| 70 | |
} |
| 71 | 0 | if (type.equalsIgnoreCase("boolean")) { |
| 72 | 0 | return "Boolean"; |
| 73 | |
} |
| 74 | 0 | if (type.equalsIgnoreCase("int")) { |
| 75 | 0 | return "int"; |
| 76 | |
} |
| 77 | 0 | if (type.equalsIgnoreCase("integer")) { |
| 78 | 0 | return "Integer"; |
| 79 | |
} |
| 80 | 0 | if (type.equalsIgnoreCase("long")) { |
| 81 | 0 | return "Long"; |
| 82 | |
} |
| 83 | |
} |
| 84 | |
|
| 85 | 0 | if (xmlType.getPrimitive().equalsIgnoreCase("Mapped String")) { |
| 86 | 0 | return "String"; |
| 87 | |
} |
| 88 | |
|
| 89 | 0 | if (xmlType.getPrimitive().equalsIgnoreCase(XmlType.COMPLEX)) { |
| 90 | 0 | String msType = GetterSetterNameCalculator.calcInitUpper(realType); |
| 91 | 0 | if (importPackage != null) { |
| 92 | 0 | importsAdd(writer, importPackage + "." + msType); |
| 93 | |
} |
| 94 | 0 | return msType; |
| 95 | |
} |
| 96 | |
|
| 97 | 0 | throw new DictionaryValidationException("Unknown/unhandled xmlType.primtive value, " |
| 98 | |
+ xmlType.getPrimitive() |
| 99 | |
+ ", for type " + type); |
| 100 | |
} |
| 101 | |
|
| 102 | |
private static void importsAdd(JavaClassWriter writer, String importStr) { |
| 103 | 0 | if (writer != null) { |
| 104 | 0 | writer.importsAdd(importStr); |
| 105 | |
} |
| 106 | 0 | } |
| 107 | |
} |