|  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.io.Serializable;  | 
  |  19 |     | 
   import java.util.List;  | 
  |  20 |     | 
     | 
  |  21 |     | 
   import org.kuali.student.contract.exception.DictionaryExecutionException;  | 
  |  22 |     | 
   import org.kuali.student.contract.model.MessageStructure;  | 
  |  23 |     | 
   import org.kuali.student.contract.model.ServiceContractModel;  | 
  |  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 |     | 
     | 
  |  31 |     | 
     | 
  |  32 |     | 
   public class PureJavaInfcBeanWriter extends JavaClassWriter { | 
  |  33 |     | 
     | 
  |  34 |     | 
       private ServiceContractModel model;  | 
  |  35 |     | 
       private String directory;  | 
  |  36 |     | 
       private String rootPackage;  | 
  |  37 |     | 
       private String service;  | 
  |  38 |     | 
       private XmlType type;  | 
  |  39 |     | 
       private ModelFinder finder;  | 
  |  40 |     | 
     | 
  |  41 |     | 
       public PureJavaInfcBeanWriter(ServiceContractModel model,  | 
  |  42 |     | 
               String directory,  | 
  |  43 |     | 
               String rootPackage,  | 
  |  44 |     | 
               String service,  | 
  |  45 |     | 
               XmlType type) { | 
  |  46 |    0 |            super(directory, calcPackage(service, rootPackage), calcClassName(type.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.type = type;  | 
  |  53 |    0 |        }  | 
  |  54 |     | 
     | 
  |  55 |     | 
       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 |     | 
       public static String calcClassName(String name) { | 
  |  63 |    0 |            if (name.endsWith("Info")) { | 
  |  64 |    0 |                name = name.substring(0, name.length() - "Info".length());  | 
  |  65 |     | 
           }  | 
  |  66 |    0 |            name = name + "Bean";  | 
  |  67 |    0 |            return GetterSetterNameCalculator.calcInitUpper(name);  | 
  |  68 |     | 
     | 
  |  69 |     | 
       }  | 
  |  70 |     | 
     | 
  |  71 |     | 
         | 
  |  72 |     | 
     | 
  |  73 |     | 
     | 
  |  74 |     | 
     | 
  |  75 |     | 
       public void write() { | 
  |  76 |    0 |            indentPrintln("public class " + calcClassName(type.getName())); | 
  |  77 |    0 |            incrementIndent();  | 
  |  78 |    0 |            indentPrint(" implements " | 
  |  79 |     | 
                   + PureJavaInfcInfcWriter.calcClassName(type.getName()));  | 
  |  80 |    0 |            importsAdd(PureJavaInfcInfcWriter.calcPackage(service, rootPackage)  | 
  |  81 |     | 
                   + "." + PureJavaInfcInfcWriter.calcClassName(type.getName()));  | 
  |  82 |    0 |            this.importsAdd(Serializable.class.getName());  | 
  |  83 |    0 |            indentPrintln(", Serializable"); | 
  |  84 |    0 |            openBrace();  | 
  |  85 |     | 
     | 
  |  86 |    0 |            indentPrintln(""); | 
  |  87 |    0 |            indentPrintln("private static final long serialVersionUID = 1L;"); | 
  |  88 |     | 
     | 
  |  89 |    0 |            List<MessageStructure> list =  | 
  |  90 |     | 
                   finder.findMessageStructures(type.getName());  | 
  |  91 |    0 |            if (list.size() == 0) { | 
  |  92 |    0 |                throw new DictionaryExecutionException("xmlType " + type.getName() | 
  |  93 |     | 
                       + " has no fields defined in the message structure tab");  | 
  |  94 |     | 
           }  | 
  |  95 |    0 |            for (MessageStructure ms : list) { | 
  |  96 |    0 |                String realType = stripList(PureJavaInfcInfcWriter.calcClassName(ms.getType()));  | 
  |  97 |    0 |                String fieldType = this.calcFieldTypeToUse(ms.getType(), realType);  | 
  |  98 |    0 |                String name = initLower(ms.getShortName());  | 
  |  99 |    0 |                indentPrintln(""); | 
  |  100 |    0 |                indentPrintln("private " + fieldType + " " + name + ";"); | 
  |  101 |    0 |                indentPrintln(""); | 
  |  102 |    0 |                indentPrintln("/**"); | 
  |  103 |    0 |                indentPrintWrappedComment("Set " + ms.getName()); | 
  |  104 |    0 |                indentPrintln("*"); | 
  |  105 |    0 |                indentPrintln("* Type: " + ms.getType()); | 
  |  106 |    0 |                indentPrintln("*"); | 
  |  107 |    0 |                indentPrintWrappedComment(ms.getDescription());  | 
  |  108 |    0 |                indentPrintln("*/"); | 
  |  109 |    0 |                indentPrintln("@Override"); | 
  |  110 |    0 |                indentPrintln("public void " + calcSetter(ms) + "(" + fieldType + " " | 
  |  111 |     | 
                       + name + ")");  | 
  |  112 |    0 |                openBrace();  | 
  |  113 |    0 |                indentPrintln("this." + name + " = " + name + ";"); | 
  |  114 |    0 |                closeBrace();  | 
  |  115 |     | 
     | 
  |  116 |    0 |                indentPrintln(""); | 
  |  117 |    0 |                indentPrintln("/**"); | 
  |  118 |    0 |                indentPrintWrappedComment("Get " + ms.getName()); | 
  |  119 |    0 |                indentPrintln("*"); | 
  |  120 |    0 |                indentPrintln("* Type: " + ms.getType()); | 
  |  121 |    0 |                indentPrintln("*"); | 
  |  122 |    0 |                indentPrintWrappedComment(ms.getDescription());  | 
  |  123 |    0 |                indentPrintln("*/"); | 
  |  124 |    0 |                indentPrintln("@Override"); | 
  |  125 |    0 |                indentPrintln("public " + fieldType + " " + calcGetter(ms) + "()"); | 
  |  126 |    0 |                openBrace();  | 
  |  127 |    0 |                indentPrintln("return this." + name + ";"); | 
  |  128 |    0 |                closeBrace();  | 
  |  129 |    0 |                indentPrint(""); | 
  |  130 |     | 
     | 
  |  131 |    0 |                indentPrint(""); | 
  |  132 |    0 |            }  | 
  |  133 |    0 |            indentPrintln(""); | 
  |  134 |    0 |            closeBrace();  | 
  |  135 |     | 
     | 
  |  136 |    0 |            this.writeJavaClassAndImportsOutToFile();  | 
  |  137 |    0 |            this.getOut().close();  | 
  |  138 |    0 |        }  | 
  |  139 |     | 
     | 
  |  140 |     | 
       private String stripList(String str) { | 
  |  141 |    0 |            return GetterSetterNameCalculator.stripList(str);  | 
  |  142 |     | 
       }  | 
  |  143 |     | 
     | 
  |  144 |     | 
       private String initLower(String str) { | 
  |  145 |    0 |            if (str == null) { | 
  |  146 |    0 |                return null;  | 
  |  147 |     | 
           }  | 
  |  148 |    0 |            if (str.isEmpty()) { | 
  |  149 |    0 |                return str;  | 
  |  150 |     | 
           }  | 
  |  151 |    0 |            if (str.length() == 1) { | 
  |  152 |    0 |                return str.toLowerCase();  | 
  |  153 |     | 
           }  | 
  |  154 |    0 |            return str.substring(0, 1).toLowerCase() + str.substring(1);  | 
  |  155 |     | 
       }  | 
  |  156 |     | 
     | 
  |  157 |     | 
       private String calcGetter(MessageStructure ms) { | 
  |  158 |    0 |            return new GetterSetterNameCalculator(ms, this, model).calcGetter();  | 
  |  159 |     | 
       }  | 
  |  160 |     | 
     | 
  |  161 |     | 
       private String calcSetter(MessageStructure ms) { | 
  |  162 |    0 |            return new GetterSetterNameCalculator(ms, this, model).calcSetter();  | 
  |  163 |     | 
       }  | 
  |  164 |     | 
     | 
  |  165 |     | 
       private String calcFieldTypeToUse(String type, String realType) { | 
  |  166 |    0 |            XmlType t = finder.findXmlType(this.stripList(type));  | 
  |  167 |    0 |            String pckName = calcPackage(t.getService(), rootPackage);  | 
  |  168 |    0 |            return MessageStructureTypeCalculator.calculate(this, model, type, realType,  | 
  |  169 |     | 
                   pckName);  | 
  |  170 |     | 
       }  | 
  |  171 |     | 
   }  |