Coverage Report - org.kuali.student.contract.writer.service.PureJavaInfcWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
PureJavaInfcWriter
0%
0/41
0%
0/20
3
 
 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.Collection;
 19  
 import java.util.HashMap;
 20  
 import java.util.HashSet;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 import java.util.Set;
 24  
 
 25  
 import org.kuali.student.contract.model.Service;
 26  
 import org.kuali.student.contract.model.ServiceContractModel;
 27  
 import org.kuali.student.contract.model.ServiceMethod;
 28  
 import org.kuali.student.contract.model.ServiceMethodError;
 29  
 import org.kuali.student.contract.model.XmlType;
 30  
 import org.kuali.student.contract.model.util.ServicesFilter;
 31  
 import org.kuali.student.contract.model.validation.DictionaryValidationException;
 32  
 import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
 33  
 
 34  
 /**
 35  
  *
 36  
  * @author nwright
 37  
  */
 38  
 public class PureJavaInfcWriter
 39  
 {
 40  
 
 41  
  private ServiceContractModel model;
 42  
  private String directory;
 43  
  private String rootPackage;
 44  
  public static final String DEFAULT_ROOT_PACKAGE = "org.kuali.student.service";
 45  
  private ServicesFilter filter;
 46  
 
 47  
  public PureJavaInfcWriter (ServiceContractModel model,
 48  
                         String directory,
 49  
                         String rootPackage,
 50  
                         ServicesFilter filter)
 51  0
  {
 52  0
   this.model = model;
 53  0
   this.directory = directory;
 54  0
   this.rootPackage = rootPackage;
 55  0
   this.filter = filter;
 56  0
  }
 57  
 
 58  
  /**
 59  
   * Write out the entire file
 60  
   * @param out
 61  
   */
 62  
  public void write ()
 63  
  {
 64  0
   this.validate ();
 65  
 
 66  0
   for (Service service : filterServices ())
 67  
   {
 68  0
    new PureJavaInfcWriterForOneService (model, directory, rootPackage, service.getKey ()).write ();
 69  
   }
 70  
 
 71  
   // the Info interfaces's
 72  0
   System.out.println ("Generating common Info interfaces");
 73  0
   for (XmlType xmlType : getXmlTypesUsedByMoreThanOneByService ())
 74  
   {
 75  0
    System.out.println ("Generating info interface for " + xmlType.getName ());
 76  0
    new PureJavaInfcInfcWriter (model, directory, rootPackage, xmlType.getService (), xmlType).write ();
 77  0
    new PureJavaInfcBeanWriter (model, directory, rootPackage, xmlType.getService (), xmlType).write ();
 78  
   }
 79  
 
 80  
 //  exceptions
 81  
   // Decided to just use the exisiting exceptions that are hand crafted
 82  
   // no need to generate
 83  
 //  for (ServiceMethodError error : getServiceMethodErrors ().values ())
 84  
 //  {
 85  
 //   System.out.println ("generating exception class: " + error.getType ());
 86  
 //   new ServiceExceptionWriter (model, directory, rootPackage, error).write ();
 87  
 //  }
 88  
 
 89  0
  }
 90  
 
 91  
  private Set<XmlType> getXmlTypesUsedByMoreThanOneByService ()
 92  
  {
 93  0
   Set<XmlType> set = new HashSet ();
 94  0
   for (XmlType type : model.getXmlTypes ())
 95  
   {
 96  0
    if (type.getService ().contains (","))
 97  
    {
 98  0
     if (type.getPrimitive ().equalsIgnoreCase (XmlType.COMPLEX))
 99  
     {
 100  0
      System.out.println (type.getName () + "==>" + type.getService ());
 101  0
      set.add (type);
 102  
     }
 103  
    }
 104  
   }
 105  0
   return set;
 106  
  }
 107  
 
 108  
  private Map<String, ServiceMethodError> getServiceMethodErrors ()
 109  
  {
 110  0
   Map<String, ServiceMethodError> errors = new HashMap ();
 111  0
   for (ServiceMethod method : model.getServiceMethods ())
 112  
   {
 113  0
    for (ServiceMethodError error : method.getErrors ())
 114  
    {
 115  0
     errors.put (error.getType (), error);
 116  
    }
 117  
   }
 118  0
   return errors;
 119  
  }
 120  
 
 121  
  private List<Service> filterServices ()
 122  
  {
 123  0
   if (filter == null)
 124  
   {
 125  0
    return model.getServices ();
 126  
   }
 127  0
   return filter.filter (model.getServices ());
 128  
  }
 129  
 
 130  
  private void validate ()
 131  
  {
 132  0
   Collection<String> errors =
 133  
                      new ServiceContractModelValidator (model).validate ();
 134  0
   if (errors.size () > 0)
 135  
   {
 136  0
    StringBuffer buf = new StringBuffer ();
 137  0
    buf.append (errors.size () + " errors found while validating the data.");
 138  0
    int cnt = 0;
 139  0
    for (String msg : errors)
 140  
    {
 141  0
     cnt ++;
 142  0
     buf.append ("\n");
 143  0
     buf.append ("*error*" + cnt + ":" + msg);
 144  
    }
 145  
 
 146  0
    throw new DictionaryValidationException (buf.toString ());
 147  
   }
 148  0
  }
 149  
 }