001/** 002 * Copyright 2004-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.student.contract.writer.service; 017 018import org.kuali.student.contract.model.ServiceContractModel; 019import org.kuali.student.contract.model.ServiceMethodError; 020import org.kuali.student.contract.writer.JavaClassWriter; 021import org.kuali.student.contract.writer.JavaEnumConstantCalculator; 022 023/** 024 * 025 * @author nwright 026 * @deprecated 027 */ 028public class ServiceExceptionWriter extends JavaClassWriter { 029 030 private ServiceContractModel model; 031 private String directory; 032 private String rootPackage; 033 private ServiceMethodError error; 034 035 public ServiceExceptionWriter(ServiceContractModel model, 036 String directory, 037 String rootPackage, 038 ServiceMethodError error) { 039 super(directory, calcPackage(rootPackage), calcClassName(error.getType())); 040 this.model = model; 041 this.directory = directory; 042 this.rootPackage = rootPackage; 043 this.error = error; 044 } 045 046 public static String calcPackage(String rootPackage) { 047 return PureJavaInfcServiceWriter.calcPackage("exception", rootPackage); 048 } 049 050 public static String calcClassName(String type) { 051 return new JavaEnumConstantCalculator(type).reverse() + "Exception"; 052 } 053 054 /** 055 * Write out the entire file 056 * @param out 057 */ 058 public void write() { 059 String className = calcClassName(error.getType()); 060 indentPrintln("public class " + className + " extends Exception"); 061 openBrace(); 062 indentPrintln(""); 063 indentPrintln("private static final long serialVersionUID = 1L;"); 064 indentPrintln(""); 065 indentPrintln("public " + className + "()"); 066 openBrace(); 067 indentPrintln("super ();"); 068 closeBrace(); 069 070 indentPrintln(""); 071 indentPrintln("public " + className + "(String msg)"); 072 openBrace(); 073 indentPrintln("super (msg);"); 074 closeBrace(); 075 076 indentPrintln(""); 077 indentPrintln("public " + className + "(Throwable cause)"); 078 openBrace(); 079 indentPrintln("super (cause);"); 080 closeBrace(); 081 082 indentPrintln(""); 083 indentPrintln("public " + className + "(String msg, Throwable cause)"); 084 openBrace(); 085 indentPrintln("super (msg, cause);"); 086 closeBrace(); 087 088 indentPrintln(""); 089 closeBrace(); 090 091 this.writeJavaClassAndImportsOutToFile(); 092 this.getOut().close(); 093 } 094}