View Javadoc

1   /**
2    * - Digitalis Internal Framework v2.0 - (C) 2007, Digitalis Informatica. Distribuicao e Gestao de Informatica, Lda.
3    * Estrada de Paco de Arcos num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999
4    * http://www.digitalis.pt
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   * Represents an exception occurred in the controller tasks (AbstractChAL or Dispatcher)
14   * 
15   * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a>
16   * @created Dec 21, 2007
17   */
18  public class ControllerException extends DIFException {
19  
20      /** Serial Version ID. */
21      private static final long serialVersionUID = 1120934514453714926L;
22  
23      /** T if the controller exception was generated by another exception */
24      private boolean generatedFromException = false;
25  
26      /** The controller execution step */
27      private ControllerExecutionStep step;
28  
29      /**
30       * Constructs a new ControllerException from an Exception.
31       * 
32       * @param exception
33       *            the exception to encapsulate
34       * @param step
35       *            the execution step
36       */
37      public ControllerException(ControllerExecutionStep step, Exception exception)
38      {
39          super(exception);
40          this.generatedFromException = true;
41          this.step = step;
42      }
43  
44      /**
45       * Constructs a new ControllerException from a reason for the exception.
46       * 
47       * @param reason
48       *            the exception cause
49       * @param step
50       *            the execution step
51       */
52      public ControllerException(ControllerExecutionStep step, String reason)
53      {
54          super(reason);
55          this.step = step;
56      }
57  
58      /**
59       * Constructs a new ControllerException accepting a reason for the exception
60       * 
61       * @param reason
62       *            the exception cause
63       * @param exception
64       *            the exception to encapsulate
65       * @param step
66       *            the execution step
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       * @see pt.digitalis.dif.exception.IContextException#getRenderedExceptionContext()
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       * @return the step
93       */
94      public ControllerExecutionStep getStep()
95      {
96          return step;
97      }
98  
99      /**
100      * @return the generatedFromException
101      */
102     public boolean isGeneratedFromException()
103     {
104         return generatedFromException;
105     }
106 }