1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
26
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
56
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 }