View Javadoc

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 org.kuali.student.contract.model.ServiceContractModel;
19  import org.kuali.student.contract.model.ServiceMethodError;
20  import org.kuali.student.contract.writer.JavaClassWriter;
21  import org.kuali.student.contract.writer.JavaEnumConstantCalculator;
22  
23  /**
24   *
25   * @author nwright
26   * @deprecated 
27   */
28  public class ServiceExceptionWriter extends JavaClassWriter {
29  
30      private ServiceContractModel model;
31      private String directory;
32      private String rootPackage;
33      private ServiceMethodError error;
34  
35      public ServiceExceptionWriter(ServiceContractModel model,
36              String directory,
37              String rootPackage,
38              ServiceMethodError error) {
39          super(directory, calcPackage(rootPackage), calcClassName(error.getType()));
40          this.model = model;
41          this.directory = directory;
42          this.rootPackage = rootPackage;
43          this.error = error;
44      }
45  
46      public static String calcPackage(String rootPackage) {
47          return PureJavaInfcServiceWriter.calcPackage("exception", rootPackage);
48      }
49  
50      public static String calcClassName(String type) {
51          return new JavaEnumConstantCalculator(type).reverse() + "Exception";
52      }
53  
54      /**
55       * Write out the entire file
56       * @param out
57       */
58      public void write() {
59          String className = calcClassName(error.getType());
60          indentPrintln("public class " + className + " extends Exception");
61          openBrace();
62          indentPrintln("");
63          indentPrintln("private static final long serialVersionUID = 1L;");
64          indentPrintln("");
65          indentPrintln("public " + className + "()");
66          openBrace();
67          indentPrintln("super ();");
68          closeBrace();
69  
70          indentPrintln("");
71          indentPrintln("public " + className + "(String msg)");
72          openBrace();
73          indentPrintln("super (msg);");
74          closeBrace();
75  
76          indentPrintln("");
77          indentPrintln("public " + className + "(Throwable cause)");
78          openBrace();
79          indentPrintln("super (cause);");
80          closeBrace();
81  
82          indentPrintln("");
83          indentPrintln("public " + className + "(String msg, Throwable cause)");
84          openBrace();
85          indentPrintln("super (msg, cause);");
86          closeBrace();
87  
88          indentPrintln("");
89          closeBrace();
90  
91          this.writeJavaClassAndImportsOutToFile();
92          this.getOut().close();
93      }
94  }