Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/thermidor/util/exception/DataValidationException.java


1   package com.thermidor.util.exception;
2   /*@LEGAL@*/
3   import java.io.PrintWriter;
4   import java.io.PrintStream;
5   /**
6    * The purpose of the DataValidationException is to provide
7    * a base class for data validation exception. The implementation of the
8    * class is closely tied to the
9    * @{link ValidationDescriptor ValidationDescriptor} class that will be used 
10   * to gather information about the validation errors that have occured
11   * @author Edward Turnock
12   * @version 1.0
13   */
14  public abstract class DataValidationException extends Exception {
15      /**
16       * THe validation descriptor that will detail the validation errors
17       * that have lead to this exception being raised.
18       */
19      private ValidationDescriptor vd;
20      /**
21       * Construct a default instance of the DatValidationException.
22       */
23      public DataValidationException() {
24          super();
25      }
26  
27      /**
28       * Construct a new instance of the DataValidationException with the 
29       * specified valdiation descriptor
30       * @param vd the validation descriptor that will detail the causal
31       * validation failures.
32       */
33      public DataValidationException(ValidationDescriptor vd) {
34          this.vd = vd;
35      }
36  
37      /**
38         The printstackTrace operation prints the stacktrace of the exception 
39         to stderr together with the validation descriptor that describes the
40         validation errors.
41      <code><pre>
42      </tt>[validation-exception&gt;&gt;
43      <tt>VALIDATION-FAILURE {
44      <tt>  subject:{
45      <tt>    some GTS subsystem
46      <tt>  }
47      <tt>  description:{
48      <tt>    A fatal database error occured
49      <tt>  }
50      <tt>  errors:{
51      <tt>    error:{ClientSetupInput.accountRef == null or ''}
52      <tt>    error:{ClientSetupInput.primaryClient.dob == null}
53      <tt>  }
54      <tt>}
55      <tt>com.thermidor.gts.uk.services,client.InvalidClientDataException:
56      <tt>        at test.que(test.java:36)
57      <tt>        at test.bar(test.java:29)
58      <tt>        at test.foo(test.java:21)
59      <tt>        at test.main(test.java:17)
60      <tt>&lt;&lt;validation-exception]
61      </pre></code>
62       */
63      public void printStackTrace() {
64          System.err.println("[validation-exception>>");
65  
66          if (vd != null) {
67              System.err.println(vd.toString());
68          }
69  
70          super.printStackTrace();
71          System.err.println("<<validation-exception]");
72      }
73  
74      /**
75       * Print the stack trace of this exception an any specified validation
76       * descriptor to the specified print writer.
77       * see @{link #printStackTrace()} for the format of the stacktrace
78       * @param pw the print writer that will be used
79       */
80      public void printStackTrace(PrintWriter pw) {
81          pw.println("[validation-exception>>");
82  
83          if (vd != null) {
84              pw.println(vd.toString());
85          }
86  
87          super.printStackTrace(pw);
88          pw.println("<<validation-exception]");
89      }
90  
91      /**
92       * Print the stack trace of this exception an any specified validation
93       * descriptor to the specified print strem.
94       * see @{link #printStackTrace()} for the format of the stacktrace
95       * @param pw the print stream that will be used
96       */
97      public void printStackTrace(PrintStream pw) {
98          pw.println("[validation-exception>>");
99  
100         if (vd != null) {
101             pw.println(vd.toString());
102         }
103 
104         super.printStackTrace(pw);
105         pw.println("<<validation-exception]");
106     }
107 }
108