1
2
3
4
5
6 package pt.digitalis.dif.exception.controller;
7
8 import pt.digitalis.dif.controller.objects.ControllerExecutionStep;
9 import pt.digitalis.dif.exception.DIFException;
10 import pt.digitalis.dif.utils.ObjectFormatter;
11
12
13
14
15
16
17
18 public class ControllerException extends DIFException {
19
20
21 private static final long serialVersionUID = 1120934514453714926L;
22
23
24 private boolean generatedFromException = false;
25
26
27 private ControllerExecutionStep step;
28
29
30
31
32
33
34
35
36
37 public ControllerException(ControllerExecutionStep step, Exception exception)
38 {
39 super(exception);
40 this.generatedFromException = true;
41 this.step = step;
42 }
43
44
45
46
47
48
49
50
51
52 public ControllerException(ControllerExecutionStep step, String reason)
53 {
54 super(reason);
55 this.step = step;
56 }
57
58
59
60
61
62
63
64
65
66
67
68 public ControllerException(ControllerExecutionStep step, String reason, Exception exception)
69 {
70 super(reason, exception);
71 this.generatedFromException = true;
72 this.step = step;
73 }
74
75
76
77
78 @Override
79 public String getRenderedExceptionContext()
80 {
81
82 ObjectFormatter formatter = new ObjectFormatter();
83 formatter.addItemIfNotNull("Step", step.toString());
84 formatter.addItemIfNotNull("Cause", getCause());
85 formatter.addItemIfNotNull("Message", getMessage());
86 formatter.addItemIfNotNull("Exception Context", getExceptionContext());
87
88 return "DIF Controller Exception:\n" + formatter.getFormatedObject() + "\n";
89 }
90
91
92
93
94 public ControllerExecutionStep getStep()
95 {
96 return step;
97 }
98
99
100
101
102 public boolean isGeneratedFromException()
103 {
104 return generatedFromException;
105 }
106 }