Coverage Report - org.kuali.student.contract.writer.service.PureJavaInfcInfcWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
PureJavaInfcInfcWriter
0%
0/59
0%
0/10
1.667
 
 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  
 
 34  
  private ServiceContractModel model;
 35  
  private ModelFinder finder;
 36  
  private String directory;
 37  
  private String rootPackage;
 38  
  private String service;
 39  
  private XmlType xmlType;
 40  
 
 41  
  public PureJavaInfcInfcWriter (ServiceContractModel model,
 42  
                                 String directory,
 43  
                                 String rootPackage,
 44  
                                 String service,
 45  
                                 XmlType xmlType)
 46  
  {
 47  0
   super (directory, calcPackage (service, rootPackage), calcClassName (
 48  
     xmlType.getName ()));
 49  0
   this.model = model;
 50  0
   this.finder = new ModelFinder (model);
 51  0
   this.directory = directory ;
 52  0
   this.rootPackage = rootPackage;
 53  0
   this.service = service;
 54  0
   this.xmlType = xmlType;
 55  0
  }
 56  
 
 57  
  public static String calcPackage (String service, String rootPackage)
 58  
  {
 59  0
   if (service.contains (","))
 60  
   {
 61  0
    service = "common";
 62  
   }
 63  0
   return PureJavaInfcServiceWriter.calcPackage (service, rootPackage);
 64  
  }
 65  
 
 66  
  public static String calcClassName (String name)
 67  
  {
 68  0
   if (name.endsWith ("Info"))
 69  
   {
 70  0
    name = name.substring (0, name.length () - "Info".length ());
 71  0
    name = name + "Infc";
 72  
   }
 73  0
   else if (name.endsWith ("InfoList"))
 74  
   {
 75  0
    name = name.substring (0, name.length () - "InfoList".length ());
 76  0
    name = name + "InfcList";
 77  
   }
 78  0
   return GetterSetterNameCalculator.calcInitUpper (name);
 79  
  }
 80  
 
 81  
  /**
 82  
   * Write out the entire file
 83  
   * @param out
 84  
   */
 85  
  public void write ()
 86  
  {
 87  0
   indentPrintln ("public interface " + calcClassName (xmlType.getName ()));
 88  0
   openBrace ();
 89  
 
 90  0
   List<MessageStructure> list = finder.findMessageStructures (xmlType.getName ());
 91  0
   if (list.size () == 0)
 92  
   {
 93  0
    throw new DictionaryExecutionException (
 94  
      "xmlType " + xmlType.getName ()
 95  
      + " has no fields defined in the message structure tab");
 96  
   }
 97  0
   for (MessageStructure ms : list)
 98  
   {
 99  0
    String realType = stripList (calcClassName (ms.getType ()));
 100  0
    String type = this.calcFieldTypeToUse (ms.getType (), realType);
 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 ("public void " + calcSetter (ms) + "(" + type + " " + initLower (
 110  
      ms.getShortName ()) + ");");
 111  
 
 112  
 
 113  0
    indentPrintln ("");
 114  0
    indentPrintln ("/**");
 115  0
    indentPrintWrappedComment ("Get " + ms.getName ());
 116  0
    indentPrintln ("*");
 117  0
    indentPrintln ("* Type: " + ms.getType ());
 118  0
    indentPrintln ("*");
 119  0
    indentPrintWrappedComment (ms.getDescription ());
 120  0
    indentPrintln ("*/");
 121  0
    indentPrintln ("public " + type + " " + calcGetter (ms) + "();");
 122  0
    indentPrintln ("");
 123  
 
 124  0
    indentPrintln ("");
 125  0
   }
 126  0
   indentPrintln ("");
 127  0
   closeBrace ();
 128  
 
 129  0
   this.writeJavaClassAndImportsOutToFile ();
 130  0
   this.getOut ().close ();
 131  0
  }
 132  
 
 133  
  private String stripList (String str)
 134  
  {
 135  0
   return GetterSetterNameCalculator.stripList (str);
 136  
  }
 137  
 
 138  
  private String initLower (String str)
 139  
  {
 140  0
   return GetterSetterNameCalculator.calcInitLower (str);
 141  
  }
 142  
 
 143  
  private String calcGetter (MessageStructure ms)
 144  
  {
 145  0
   return new GetterSetterNameCalculator (ms, this, model).calcGetter ();
 146  
  }
 147  
 
 148  
  private String calcSetter (MessageStructure ms)
 149  
  {
 150  0
   return new GetterSetterNameCalculator (ms, this, model).calcSetter ();
 151  
  }
 152  
 
 153  
  private String calcFieldTypeToUse (String type, String realType)
 154  
  {
 155  0
   XmlType t = finder.findXmlType (this.stripList (type));
 156  0
   String pckName = calcPackage (t.getService (), rootPackage);
 157  0
   return MessageStructureTypeCalculator.calculate (this, model, type, realType,
 158  
                                                    pckName);
 159  
  }
 160  
 }