View Javadoc

1   /*
2    * Copyright 2003,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /*
17   * This source code implements specifications defined by the Java
18   * Community Process. In order to remain compliant with the specification
19   * DO NOT add / change / or delete method signatures!
20   */
21  package javax.portlet;
22  
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import java.util.Collections;
26  import java.util.Enumeration;
27  
28  /***
29   * The <CODE>ValidatorException</CODE> is thrown by the
30   * <CODE>validate</CODE> method of a PreferencesValidator when 
31   * the validation of a preference failed.
32   */
33  
34  public class ValidatorException extends PortletException
35  {
36  
37  
38    private transient ArrayList failedKeyVector = new ArrayList();
39  
40    private ValidatorException ()
41    {
42    }
43  
44    /***
45     * Constructs a new validator exception with the given text. The
46     * portlet container may use the text write it to a log.
47     * <p>
48     * The collection of failed keys may contain all failed keys, only the
49     * first key that failed validation, or may be <code>null</code>.
50     *
51     * @param   text
52     *          the exception text
53     * @param   failedKeys
54     *          keys that failed the validation; may be <code>null</code>
55     */
56  
57    public ValidatorException (String text, Collection failedKeys)
58    {
59      super (text);
60      if ( failedKeys != null )
61  	    failedKeyVector.addAll(failedKeys);
62    }
63  
64    /***
65     * Constructs a new portlet validator exception.
66     * Used, when the portlet needs to do one of the following:
67     * <ul>
68     * <il>throw an exception 
69     * <li>include a message about the "root cause" that interfered
70     *     with its normal operation
71     * <li>include a description message
72     * </ul>
73     * <p>
74     * The Collection of failed keys may contain all failed keys, only the
75     * first key that failed validation, or may be <code>null</code>.
76     *
77     * @param   text
78     *          the exception text
79     * @param   cause
80     *          the root cause
81     * @param   failedKeys
82     *          keys that failed the validation; may be <code>null</code>
83     */
84    
85    public ValidatorException (String text, Throwable cause, Collection failedKeys)
86    {
87      super(text, cause);
88      if ( failedKeys != null )
89  	    failedKeyVector.addAll(failedKeys);
90    }
91  
92    /***
93     * Constructs a new portlet validator exception when the portlet needs to throw an
94     * exception. The exception message is based on the localized message
95     * of the underlying exception.
96     * <p>
97     * The Collection of failed keys may contain all failed keys, only the
98     * first key that failed validation, or may be <code>null</code>.
99     *
100    * @param   cause
101    *          the root cause
102    * @param   failedKeys
103    *          keys that failed the validation; may be <code>null</code>
104    */
105 
106   public ValidatorException (Throwable cause, Collection failedKeys)
107   {
108     super(cause);
109     if ( failedKeys != null )
110 	    failedKeyVector.addAll(failedKeys);
111   }
112 
113 
114   /***
115    * Returns the keys that failed the validation.
116    * <p>
117    * The Enumeration of failed keys may contain all failed keys, only the
118    * first key that failed validation, or an empty 
119    * <code>Enumeration</code> if no failed keys are available.
120    *
121    * @return  the keys that failed validation, or an empty 
122    *          <code>Enumeration</code> if no failed keys are available.
123    */
124 
125   public Enumeration getFailedKeys()
126   {
127     return Collections.enumeration(failedKeyVector);
128   }
129 }