KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > portlet > ValidatorException


1 /**
2   * Copyright 2003 IBM Corporation and Sun Microsystems, Inc.
3   * All rights reserved.
4   * Use is subject to license terms.
5   */

6
7 package javax.portlet;
8
9 import java.util.ArrayList JavaDoc;
10 import java.util.Collection JavaDoc;
11 import java.util.Collections JavaDoc;
12 import java.util.Enumeration JavaDoc;
13
14 /**
15  * The <CODE>ValidatorException</CODE> is thrown by the
16  * <CODE>validate</CODE> method of a PreferencesValidator when
17  * the validation of a preference failed.
18  */

19
20 public class ValidatorException extends PortletException
21 {
22
23   private transient ArrayList JavaDoc failedKeyVector = new ArrayList JavaDoc();
24
25   private ValidatorException ()
26   {
27   }
28
29   /**
30    * Constructs a new validator exception with the given text. The
31    * portlet container may use the text write it to a log.
32    * <p>
33    * The collection of failed keys may contain all failed keys, only the
34    * first key that failed validation, or may be <code>null</code>.
35    *
36    * @param text
37    * the exception text
38    * @param failedKeys
39    * keys that failed the validation; may be <code>null</code>
40    */

41
42   public ValidatorException (String JavaDoc text, Collection JavaDoc failedKeys)
43   {
44     super (text);
45     if ( failedKeys != null )
46         failedKeyVector.addAll(failedKeys);
47   }
48
49   /**
50    * Constructs a new portlet validator exception.
51    * Used, when the portlet needs to do one of the following:
52    * <ul>
53    * <il>throw an exception
54    * <li>include a message about the "root cause" that interfered
55    * with its normal operation
56    * <li>include a description message
57    * </ul>
58    * <p>
59    * The Collection of failed keys may contain all failed keys, only the
60    * first key that failed validation, or may be <code>null</code>.
61    *
62    * @param text
63    * the exception text
64    * @param cause
65    * the root cause
66    * @param failedKeys
67    * keys that failed the validation; may be <code>null</code>
68    */

69   
70   public ValidatorException (String JavaDoc text, Throwable JavaDoc cause, Collection JavaDoc failedKeys)
71   {
72     super(text, cause);
73     if ( failedKeys != null )
74         failedKeyVector.addAll(failedKeys);
75   }
76
77   /**
78    * Constructs a new portlet validator exception when the portlet needs to throw an
79    * exception. The exception message is based on the localized message
80    * of the underlying exception.
81    * <p>
82    * The Collection of failed keys may contain all failed keys, only the
83    * first key that failed validation, or may be <code>null</code>.
84    *
85    * @param cause
86    * the root cause
87    * @param failedKeys
88    * keys that failed the validation; may be <code>null</code>
89    */

90
91   public ValidatorException (Throwable JavaDoc cause, Collection JavaDoc failedKeys)
92   {
93     super(cause);
94     if ( failedKeys != null )
95         failedKeyVector.addAll(failedKeys);
96   }
97
98
99   /**
100    * Returns the keys that failed the validation.
101    * <p>
102    * The Enumeration of failed keys may contain all failed keys, only the
103    * first key that failed validation, or an empty
104    * <code>Enumeration</code> if no failed keys are available.
105    *
106    * @return the keys that failed validation, or an empty
107    * <code>Enumeration</code> if no failed keys are available.
108    */

109
110   public Enumeration JavaDoc getFailedKeys()
111   {
112     return Collections.enumeration(failedKeyVector);
113   }
114 }
115
Popular Tags