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

Quick Search    Search Deep

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


1   package com.thermidor.util.exception;
2   /*@LEGAL@*/
3   import java.io.Serializable;
4   import java.util.LinkedList;
5   import java.util.Iterator;
6   import java.util.List;
7   /**
8    * The purpose of the ValidationDescriptor class is provide a container for 
9    * data validation errors that can be used in the DataValidationException and
10   * its subclasses
11   * @version 1.0
12   * @author Edward Turnock
13   */
14  public class ValidationDescriptor implements Serializable {
15      /**
16       * The list of error elements for this descriptor
17       */
18      private LinkedList elements = new LinkedList();
19      /**
20       * The subject of the validation
21       */
22      private String subject;
23  
24      /**
25       * The human meaningful description validation that took place
26       */
27      private String description;
28  
29      /**
30       * Construct a default instance of the ValidationDescriptor.
31       */
32      public ValidationDescriptor() {}
33  
34      /**
35       * Construct a new instance of an ValidationDescriptor with the specifed
36       * details.
37       * @param subject the subject of the exception
38       * @param description the human readable description of the causes of the
39       * exception.
40       */
41      public ValidationDescriptor(String subject,
42                                 String description) {
43          this.subject = subject;
44          this.description = description;
45      }
46  
47      /**
48       * Return a string representation of this descriptor.
49       * @return the string representation of this descriptor
50       <pre><code>
51      <tt>
52      VALIDATION-FAILURE {
53        subject:{
54          some GTS subsystem
55        }
56        description:{
57          A fatal database error occured
58        }
59        errors:{
60          error:{ClientSetupInput.accountRef == null or ''}
61          error:{ClientSetupInput.primaryClient.dob == null}
62        }
63      }
64      </tt>
65       </code><pre>
66       */
67      public String toString() {
68          String ls = System.getProperty("line.separator");
69          StringBuffer retval = new StringBuffer("VALIDATION-FAILURE { " + ls);
70          retval.append("  subject:{" + ls);
71          retval.append("    " + subject + ls);
72          retval.append("  }");
73          retval.append("  description:{" + ls);
74          retval.append("    " + description + ls);
75          retval.append("  }");
76          retval.append("  errors:{");
77          Iterator it = elements.iterator();
78          while (it.hasNext()) {
79              retval.append("    element:{" + it.next() + "}" + ls);
80          }
81          retval.append("  }");
82          retval.append("}");
83          return retval.toString();
84      }
85  
86      /**
87       * Retrieve the description of the exception
88       * @return the description;
89       */
90      public String getDescription() {
91          return subject;
92      }
93  
94      /**
95       * Retrieve the subject of the exception
96       * @return the subject
97       */
98      public String getSubject() {
99          return description;
100     }
101     /**
102      * Retrieve the list of error elements
103      * @return the list of error elements
104      */
105     public List getErrorElements() {
106         return elements;
107     }
108     /**
109      * Add an error element to this descriptor. In this case an error element
110      * may be a validation error that was encounterd when validing input, or
111      * similar
112      * @param toAdd the element to add
113      */
114     public void addErrorElement(String toAdd) {
115         elements.add(toAdd);
116     }
117     /**
118      * Does this instance have any error elements assigned to it.
119      * @return true is error elements have been assigned.
120      */
121     public boolean hasErrorElements(){
122         return !elements.isEmpty();
123     }
124 }