source: trunk/gcc/libjava/java/security/cert/CertPathValidatorException.java@ 2446

Last change on this file since 2446 was 1389, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.0 KB
Line 
1/* CertPathValidatorException.java -- wraps an exception during validation
2 of a CertPath
3 Copyright (C) 2002 Free Software Foundation, Inc.
4
5This file is part of GNU Classpath.
6
7GNU Classpath is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU Classpath is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Classpath; see the file COPYING. If not, write to the
19Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2002111-1307 USA.
21
22Linking this library statically or dynamically with other modules is
23making a combined work based on this library. Thus, the terms and
24conditions of the GNU General Public License cover the whole
25combination.
26
27As a special exception, the copyright holders of this library give you
28permission to link this library with independent modules to produce an
29executable, regardless of the license terms of these independent
30modules, and to copy and distribute the resulting executable under
31terms of your choice, provided that you also meet, for each linked
32independent module, the terms and conditions of the license of that
33module. An independent module is a module which is not derived from
34or based on this library. If you modify this library, you may extend
35this exception to your version of the library, but you are not
36obligated to do so. If you do not wish to do so, delete this
37exception statement from your version. */
38
39
40package java.security.cert;
41
42import java.io.PrintStream;
43import java.io.PrintWriter;
44import java.security.GeneralSecurityException;
45
46/**
47 * Indicates a problem while validating a certification path. In addition,
48 * it can store the path an index in that path that caused the problem. This
49 * class is not thread-safe.
50 *
51 * @author Eric Blake <[email protected]>
52 * @see CertPathValidator
53 * @since 1.4
54 * @status updated to 1.4
55*/
56public class CertPathValidatorException extends GeneralSecurityException
57{
58 /**
59 * Compatible with JDK 1.4+.
60 */
61 private static final long serialVersionUID = -3083180014971893139L;
62
63 /**
64 * The index of the certificate path that failed, or -1.
65 *
66 * @serial the failed index
67 */
68 private final int index;
69
70 /**
71 * The <code>CertPath</code> that failed.
72 *
73 * @serial the object being validated at time of failure
74 */
75 private final CertPath certPath;
76
77 /**
78 * Create an exception without a message. The cause may be initialized. The
79 * index is set to -1 and the failed CertPath object to null.
80 */
81 public CertPathValidatorException()
82 {
83 this((String) null);
84 }
85
86 /**
87 * Create an exception with a message. The cause may be initialized. The
88 * index is set to -1 and the failed CertPath object to null.
89 *
90 * @param msg a message to display with exception
91 */
92 public CertPathValidatorException(String msg)
93 {
94 super(msg);
95 index = -1;
96 certPath = null;
97 }
98
99 /**
100 * Create an exception with a cause. The message will be
101 * <code>cause == null ? null : cause.toString()</code>. The index is set
102 * to -1 and the failed CertPath object to null.
103 *
104 * @param cause the cause
105 */
106 public CertPathValidatorException(Throwable cause)
107 {
108 this(cause == null ? null : cause.toString(), cause, null, -1);
109 }
110
111 /**
112 * Create an exception with a cause and a message. The index is set to -1
113 * and the failed CertPath object to null.
114 *
115 * @param msg the message
116 * @param cause the cause
117 */
118 public CertPathValidatorException(String msg, Throwable cause)
119 {
120 this(msg, cause, null, -1);
121 }
122
123 /**
124 * Create an exception with a cause, message, failed object, and index of
125 * failure in that CertPath.
126 *
127 * @param msg the message
128 * @param cause the cause
129 * @param certPath the path that was being validated, or null
130 * @param index the index of the path, or -1
131 * @throws IndexOutOfBoundsException if index is &lt; -1 or
132 * &gt; certPath.getCertificates().size()
133 * @throws IllegalArgumentException if certPath is null but index != -1
134 */
135 public CertPathValidatorException(String msg, Throwable cause,
136 CertPath certPath, int index)
137 {
138 super(msg);
139 initCause(cause);
140 if (index < -1 || (certPath != null
141 && index >= certPath.getCertificates().size()))
142 throw new IndexOutOfBoundsException();
143 if ((certPath == null) != (index == -1))
144 throw new IllegalArgumentException();
145 this.certPath = certPath;
146 this.index = index;
147 }
148
149 /**
150 * Get the detail message.
151 *
152 * @return the detail message
153 */
154 public String getMessage()
155 {
156 return super.getMessage();
157 }
158
159 /**
160 * Get the certificate path that had the failure, or null.
161 *
162 * @return the culprit path
163 */
164 public CertPath getCertPath()
165 {
166 return certPath;
167 }
168
169 /**
170 * Get the index that failed, or -1.
171 *
172 * @return the colprit index
173 */
174 public int getIndex()
175 {
176 return index;
177 }
178
179 /**
180 * Get the cause, null if unknown.
181 *
182 * @return the cause
183 */
184 public Throwable getCause()
185 {
186 return super.getCause();
187 }
188
189 /**
190 * Convert this to a string, including its cause.
191 *
192 * @return the string conversion
193 */
194 public String toString()
195 {
196 return super.toString();
197 }
198
199 /**
200 * Print the stack trace to <code>System.err</code>.
201 */
202 public void printStackTrace()
203 {
204 super.printStackTrace();
205 }
206
207 /**
208 * Print the stack trace to a stream.
209 *
210 * @param stream the stream
211 */
212 public void printStackTrace(PrintStream stream)
213 {
214 super.printStackTrace(stream);
215 }
216
217 /**
218 * Print the stack trace to a stream.
219 *
220 * @param stream the stream
221 */
222 public void printStackTrace(PrintWriter stream)
223 {
224 super.printStackTrace(stream);
225 }
226}
Note: See TracBrowser for help on using the repository browser.