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