KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > security > cert > CertPathValidatorException


1 /*
2  * @(#)CertPathValidatorException.java 1.10 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.security.cert;
9
10 import java.security.GeneralSecurityException JavaDoc;
11
12 /**
13  * An exception indicating one of a variety of problems encountered when
14  * validating a certification path.
15  * <p>
16  * A <code>CertPathValidatorException</code> provides support for wrapping
17  * exceptions. The {@link #getCause getCause} method returns the throwable,
18  * if any, that caused this exception to be thrown.
19  * <p>
20  * A <code>CertPathValidatorException</code> may also include the
21  * certification path that was being validated when the exception was thrown
22  * and the index of the certificate in the certification path that caused the
23  * exception to be thrown. Use the {@link #getCertPath getCertPath} and
24  * {@link #getIndex getIndex} methods to retrieve this information.
25  *
26  * <p>
27  * <b>Concurrent Access</b>
28  * <p>
29  * Unless otherwise specified, the methods defined in this class are not
30  * thread-safe. Multiple threads that need to access a single
31  * object concurrently should synchronize amongst themselves and
32  * provide the necessary locking. Multiple threads each manipulating
33  * separate objects need not synchronize.
34  *
35  * @see CertPathValidator
36  *
37  * @version 1.10 12/19/03
38  * @since 1.4
39  * @author Yassir Elley
40  */

41 public class CertPathValidatorException extends GeneralSecurityException JavaDoc {
42
43     private static final long serialVersionUID = -3083180014971893139L;
44
45     /**
46      * @serial the index of the certificate in the certification path
47      * that caused the exception to be thrown
48      */

49     private int index = -1;
50
51     /**
52      * @serial the <code>CertPath</code> that was being validated when
53      * the exception was thrown
54      */

55     private CertPath JavaDoc certPath;
56
57     /**
58      * Creates a <code>CertPathValidatorException</code> with
59      * no detail message.
60      */

61     public CertPathValidatorException() {
62         super();
63     }
64
65     /**
66      * Creates a <code>CertPathValidatorException</code> with the given
67      * detail message. A detail message is a <code>String</code> that
68      * describes this particular exception.
69      *
70      * @param msg the detail message
71      */

72     public CertPathValidatorException(String JavaDoc msg) {
73         super(msg);
74     }
75
76     /**
77      * Creates a <code>CertPathValidatorException</code> that wraps the
78      * specified throwable. This allows any exception to be converted into a
79      * <code>CertPathValidatorException</code>, while retaining information
80      * about the wrapped exception, which may be useful for debugging. The
81      * detail message is set to (<code>cause==null ? null : cause.toString()
82      * </code>) (which typically contains the class and detail message of
83      * cause).
84      *
85      * @param cause the cause (which is saved for later retrieval by the
86      * {@link #getCause getCause()} method). (A <code>null</code> value is
87      * permitted, and indicates that the cause is nonexistent or unknown.)
88      */

89     public CertPathValidatorException(Throwable JavaDoc cause) {
90     super(cause);
91     }
92
93     /**
94      * Creates a <code>CertPathValidatorException</code> with the specified
95      * detail message and cause.
96      *
97      * @param msg the detail message
98      * @param cause the cause (which is saved for later retrieval by the
99      * {@link #getCause getCause()} method). (A <code>null</code> value is
100      * permitted, and indicates that the cause is nonexistent or unknown.)
101      */

102     public CertPathValidatorException(String JavaDoc msg, Throwable JavaDoc cause) {
103         super(msg, cause);
104     }
105
106     /**
107      * Creates a <code>CertPathValidatorException</code> with the specified
108      * detail message, cause, certification path, and index.
109      *
110      * @param msg the detail message (or <code>null</code> if none)
111      * @param cause the cause (or <code>null</code> if none)
112      * @param certPath the certification path that was in the process of
113      * being validated when the error was encountered
114      * @param index the index of the certificate in the certification path
115      * that caused the error (or -1 if not applicable). Note that
116      * the list of certificates in a <code>CertPath</code> is zero based.
117      * @throws IndexOutofBoundsException if the index is out of range
118      * <code>(index < -1 || (certPath != null && index >=
119      * certPath.getCertificates().size())</code>
120      * @throws IllegalArgumentException if <code>certPath</code> is
121      * <code>null</code> and <code>index</code> is not -1
122      */

123     public CertPathValidatorException(String JavaDoc msg, Throwable JavaDoc cause,
124         CertPath JavaDoc certPath, int index) {
125         super(msg, cause);
126     if (certPath == null && index != -1) {
127         throw new IllegalArgumentException JavaDoc();
128     }
129     if (index < -1 ||
130         (certPath != null && index >= certPath.getCertificates().size())) {
131         throw new IndexOutOfBoundsException JavaDoc();
132     }
133     this.certPath = certPath;
134     this.index = index;
135     }
136
137     /**
138      * Returns the certification path that was being validated when
139      * the exception was thrown.
140      *
141      * @return the <code>CertPath</code> that was being validated when
142      * the exception was thrown (or <code>null</code> if not specified)
143      */

144     public CertPath JavaDoc getCertPath() {
145         return this.certPath;
146     }
147
148     /**
149      * Returns the index of the certificate in the certification path
150      * that caused the exception to be thrown. Note that the list of
151      * certificates in a <code>CertPath</code> is zero based. If no
152      * index has been set, -1 is returned.
153      *
154      * @return the index that has been set, or -1 if none has been set
155      */

156     public int getIndex() {
157     return this.index;
158     }
159
160 }
161
Popular Tags