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 | |
|
31 | |
private ServiceContractModel model; |
32 | |
private String directory; |
33 | |
private String rootPackage; |
34 | |
private ServiceMethodError error; |
35 | |
|
36 | |
public ServiceExceptionWriter (ServiceContractModel model, |
37 | |
String directory, |
38 | |
String rootPackage, |
39 | |
ServiceMethodError error) |
40 | |
{ |
41 | 0 | super (directory, calcPackage (rootPackage), calcClassName (error.getType ())); |
42 | 0 | this.model = model; |
43 | 0 | this.directory = directory; |
44 | 0 | this.rootPackage = rootPackage; |
45 | 0 | this.error = error; |
46 | 0 | } |
47 | |
|
48 | |
public static String calcPackage (String rootPackage) |
49 | |
{ |
50 | 0 | return PureJavaInfcServiceWriter.calcPackage ("exception", rootPackage); |
51 | |
} |
52 | |
|
53 | |
public static String calcClassName (String type) |
54 | |
{ |
55 | 0 | return new JavaEnumConstantCalculator (type).reverse () + "Exception"; |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public void write () |
63 | |
{ |
64 | 0 | String className = calcClassName (error.getType ()); |
65 | 0 | indentPrintln ("public class " + className + " extends Exception"); |
66 | 0 | openBrace (); |
67 | 0 | indentPrintln (""); |
68 | 0 | indentPrintln ("private static final long serialVersionUID = 1L;"); |
69 | 0 | indentPrintln (""); |
70 | 0 | indentPrintln ("public " + className + "()"); |
71 | 0 | openBrace (); |
72 | 0 | indentPrintln ("super ();"); |
73 | 0 | closeBrace (); |
74 | |
|
75 | 0 | indentPrintln (""); |
76 | 0 | indentPrintln ("public " + className + "(String msg)"); |
77 | 0 | openBrace (); |
78 | 0 | indentPrintln ("super (msg);"); |
79 | 0 | closeBrace (); |
80 | |
|
81 | 0 | indentPrintln (""); |
82 | 0 | indentPrintln ("public " + className + "(Throwable cause)"); |
83 | 0 | openBrace (); |
84 | 0 | indentPrintln ("super (cause);"); |
85 | 0 | closeBrace (); |
86 | |
|
87 | 0 | indentPrintln (""); |
88 | 0 | indentPrintln ("public " + className + "(String msg, Throwable cause)"); |
89 | 0 | openBrace (); |
90 | 0 | indentPrintln ("super (msg, cause);"); |
91 | 0 | closeBrace (); |
92 | |
|
93 | 0 | indentPrintln (""); |
94 | 0 | closeBrace (); |
95 | |
|
96 | 0 | this.writeJavaClassAndImportsOutToFile (); |
97 | 0 | this.getOut ().close (); |
98 | 0 | } |
99 | |
|
100 | |
} |