001: /**
002: * Copyright 2003 IBM Corporation and Sun Microsystems, Inc.
003: * All rights reserved.
004: * Use is subject to license terms.
005: */package javax.portlet;
006:
007: import java.util.ArrayList;
008: import java.util.Collection;
009: import java.util.Collections;
010: import java.util.Enumeration;
011:
012: /**
013: * The <CODE>ValidatorException</CODE> is thrown by the
014: * <CODE>validate</CODE> method of a PreferencesValidator when
015: * the validation of a preference failed.
016: */
017:
018: public class ValidatorException extends PortletException {
019:
020: private transient ArrayList failedKeyVector = new ArrayList();
021:
022: private ValidatorException() {
023: }
024:
025: /**
026: * Constructs a new validator exception with the given text. The
027: * portlet container may use the text write it to a log.
028: * <p>
029: * The collection of failed keys may contain all failed keys, only the
030: * first key that failed validation, or may be <code>null</code>.
031: *
032: * @param text
033: * the exception text
034: * @param failedKeys
035: * keys that failed the validation; may be <code>null</code>
036: */
037:
038: public ValidatorException(String text, Collection failedKeys) {
039: super (text);
040: if (failedKeys != null)
041: failedKeyVector.addAll(failedKeys);
042: }
043:
044: /**
045: * Constructs a new portlet validator exception.
046: * Used, when the portlet needs to do one of the following:
047: * <ul>
048: * <il>throw an exception
049: * <li>include a message about the "root cause" that interfered
050: * with its normal operation
051: * <li>include a description message
052: * </ul>
053: * <p>
054: * The Collection of failed keys may contain all failed keys, only the
055: * first key that failed validation, or may be <code>null</code>.
056: *
057: * @param text
058: * the exception text
059: * @param cause
060: * the root cause
061: * @param failedKeys
062: * keys that failed the validation; may be <code>null</code>
063: */
064:
065: public ValidatorException(String text, Throwable cause,
066: Collection failedKeys) {
067: super (text, cause);
068: if (failedKeys != null)
069: failedKeyVector.addAll(failedKeys);
070: }
071:
072: /**
073: * Constructs a new portlet validator exception when the portlet needs to throw an
074: * exception. The exception message is based on the localized message
075: * of the underlying exception.
076: * <p>
077: * The Collection of failed keys may contain all failed keys, only the
078: * first key that failed validation, or may be <code>null</code>.
079: *
080: * @param cause
081: * the root cause
082: * @param failedKeys
083: * keys that failed the validation; may be <code>null</code>
084: */
085:
086: public ValidatorException(Throwable cause, Collection failedKeys) {
087: super (cause);
088: if (failedKeys != null)
089: failedKeyVector.addAll(failedKeys);
090: }
091:
092: /**
093: * Returns the keys that failed the validation.
094: * <p>
095: * The Enumeration of failed keys may contain all failed keys, only the
096: * first key that failed validation, or an empty
097: * <code>Enumeration</code> if no failed keys are available.
098: *
099: * @return the keys that failed validation, or an empty
100: * <code>Enumeration</code> if no failed keys are available.
101: */
102:
103: public Enumeration getFailedKeys() {
104: return Collections.enumeration(failedKeyVector);
105: }
106: }
|