Coverage Report - org.kuali.student.contract.writer.service.MessageStructureTypeCalculator
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageStructureTypeCalculator
0%
0/40
0%
0/30
10.333
 
 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.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  
  * @author nwright
 31  
  */
 32  0
 public class MessageStructureTypeCalculator
 33  
 {
 34  
 
 35  
  public static String calculate (ServiceContractModel model,
 36  
                                  String type, String realType)
 37  
  {
 38  0
   return calculate (null, model, type, realType, "");
 39  
  }
 40  
 
 41  
  public static String calculate (JavaClassWriter writer,
 42  
                                  ServiceContractModel model,
 43  
                                  String type,
 44  
                                  String realType,
 45  
                                  String importPackage)
 46  
  {
 47  0
   if (type.equalsIgnoreCase ("Map<String, String>"))
 48  
   {
 49  0
    importsAdd (writer, Map.class.getName ());
 50  0
    return "Map<String, String>";
 51  
   }
 52  
 
 53  0
   if (type.endsWith ("List"))
 54  
   {
 55  0
    importsAdd (writer, List.class.getName ());
 56  0
    type = type.substring (0, type.length () - "List".length ());
 57  0
    return "List<" + calculate (writer, model, type, realType, importPackage) + ">";
 58  
   }
 59  0
   XmlType xmlType = new ModelFinder (model).findXmlType (type);
 60  0
   if (xmlType == null)
 61  
   {
 62  0
    throw new DictionaryValidationException ("No XmlType found for type " + type);
 63  
   }
 64  
 
 65  0
   if (xmlType.getPrimitive ().equalsIgnoreCase ("Primitive"))
 66  
   {
 67  0
    if (type.equalsIgnoreCase ("string"))
 68  
    {
 69  0
     return "String";
 70  
    }
 71  0
    if (type.equalsIgnoreCase ("date"))
 72  
    {
 73  0
     importsAdd (writer, Date.class.getName ());
 74  0
     return "Date";
 75  
    }
 76  0
    if (type.equalsIgnoreCase ("datetime"))
 77  
    {
 78  0
     importsAdd (writer, Date.class.getName ());
 79  0
     return "Date";
 80  
    }
 81  0
    if (type.equalsIgnoreCase ("boolean"))
 82  
    {
 83  0
     return "Boolean";
 84  
    }
 85  0
    if (type.equalsIgnoreCase ("int"))
 86  
    {
 87  0
     return "int";
 88  
    }
 89  0
    if (type.equalsIgnoreCase ("integer"))
 90  
    {
 91  0
     return "Integer";
 92  
    }
 93  0
    if (type.equalsIgnoreCase ("long"))
 94  
    {
 95  0
     return "Long";
 96  
    }
 97  
   }
 98  
 
 99  0
   if (xmlType.getPrimitive ().equalsIgnoreCase ("Mapped String"))
 100  
   {
 101  0
    return "String";
 102  
   }
 103  
 
 104  0
   if (xmlType.getPrimitive ().equalsIgnoreCase (XmlType.COMPLEX))
 105  
   {
 106  0
    String msType = GetterSetterNameCalculator.calcInitUpper (realType);
 107  0
    if (importPackage != null)
 108  
    {
 109  0
     importsAdd (writer, importPackage + "." + msType);
 110  
    }
 111  0
    return msType;
 112  
   }
 113  
 
 114  0
   throw new DictionaryValidationException ("Unknown/unhandled xmlType.primtive value, "
 115  
                                            + xmlType.getPrimitive ()
 116  
                                            + ", for type " + type);
 117  
  }
 118  
 
 119  
  private static void importsAdd (JavaClassWriter writer, String importStr)
 120  
  {
 121  0
   if (writer != null)
 122  
   {
 123  0
    writer.importsAdd (importStr);
 124  
   }
 125  0
  }
 126  
 }