01: /**
02: * Copyright 2003 IBM Corporation and Sun Microsystems, Inc.
03: * All rights reserved.
04: * Use is subject to license terms.
05: */package javax.portlet;
06:
07: import java.util.ArrayList;
08: import java.util.Collection;
09: import java.util.Collections;
10: import java.util.Enumeration;
11:
12: /**
13: * The <CODE>ValidatorException</CODE> is thrown by the
14: * <CODE>validate</CODE> method of a PreferencesValidator when
15: * the validation of a preference failed.
16: */
17:
18: public class ValidatorException extends PortletException {
19:
20: private transient ArrayList failedKeyVector = new ArrayList();
21:
22: private ValidatorException() {
23: }
24:
25: /**
26: * Constructs a new validator exception with the given text. The
27: * portlet container may use the text write it to a log.
28: * <p/>
29: * The collection of failed keys may contain all failed keys, only the
30: * first key that failed validation, or may be <code>null</code>.
31: *
32: * @param text the exception text
33: * @param failedKeys keys that failed the validation; may be <code>null</code>
34: */
35:
36: public ValidatorException(String text, Collection failedKeys) {
37: super (text);
38: if (failedKeys != null)
39: failedKeyVector.addAll(failedKeys);
40: }
41:
42: /**
43: * Constructs a new portlet validator exception.
44: * Used, when the portlet needs to do one of the following:
45: * <ul>
46: * <il>throw an exception
47: * <li>include a message about the "root cause" that interfered
48: * with its normal operation
49: * <li>include a description message
50: * </ul>
51: * <p/>
52: * The Collection of failed keys may contain all failed keys, only the
53: * first key that failed validation, or may be <code>null</code>.
54: *
55: * @param text the exception text
56: * @param cause the root cause
57: * @param failedKeys keys that failed the validation; may be <code>null</code>
58: */
59:
60: public ValidatorException(String text, Throwable cause,
61: Collection failedKeys) {
62: super (text, cause);
63: if (failedKeys != null)
64: failedKeyVector.addAll(failedKeys);
65: }
66:
67: /**
68: * Constructs a new portlet validator exception when the portlet needs to throw an
69: * exception. The exception message is based on the localized message
70: * of the underlying exception.
71: * <p/>
72: * The Collection of failed keys may contain all failed keys, only the
73: * first key that failed validation, or may be <code>null</code>.
74: *
75: * @param cause the root cause
76: * @param failedKeys keys that failed the validation; may be <code>null</code>
77: */
78:
79: public ValidatorException(Throwable cause, Collection failedKeys) {
80: super (cause);
81: if (failedKeys != null)
82: failedKeyVector.addAll(failedKeys);
83: }
84:
85: /**
86: * Returns the keys that failed the validation.
87: * <p/>
88: * The Enumeration of failed keys may contain all failed keys, only the
89: * first key that failed validation, or an empty
90: * <code>Enumeration</code> if no failed keys are available.
91: *
92: * @return the keys that failed validation, or an empty
93: * <code>Enumeration</code> if no failed keys are available.
94: */
95:
96: public Enumeration getFailedKeys() {
97: return Collections.enumeration(failedKeyVector);
98: }
99: }
|