1/*
2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25/*
26 * $Id: NoSuchMechanismException.java,v 1.4 2005/05/10 15:47:42 mullan Exp $
27 */
28package javax.xml.crypto;
29
30import java.io.PrintStream;
31import java.io.PrintWriter;
32import javax.xml.crypto.dsig.Manifest;
33import javax.xml.crypto.dsig.XMLSignature;
34import javax.xml.crypto.dsig.XMLSignatureFactory;
35import javax.xml.crypto.dsig.keyinfo.KeyInfo;
36import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
37
38/**
39 * This exception is thrown when a particular XML mechanism is requested but
40 * is not available in the environment.
41 *
42 * <p>A {@code NoSuchMechanismException} can contain a cause: another
43 * throwable that caused this {@code NoSuchMechanismException} to get
44 * thrown.
45 *
46 * @author Sean Mullan
47 * @author JSR 105 Expert Group
48 * @since 1.6
49 * @see XMLSignatureFactory#getInstance XMLSignatureFactory.getInstance
50 * @see KeyInfoFactory#getInstance KeyInfoFactory.getInstance
51 */
52public class NoSuchMechanismException extends RuntimeException {
53
54    private static final long serialVersionUID = 4189669069570660166L;
55
56    /**
57     * The throwable that caused this exception to get thrown, or null if this
58     * exception was not caused by another throwable or if the causative
59     * throwable is unknown.
60     *
61     * @serial
62     */
63    private Throwable cause;
64
65    /**
66     * Constructs a new {@code NoSuchMechanismException} with
67     * {@code null} as its detail message.
68     */
69    public NoSuchMechanismException() {
70        super();
71    }
72
73    /**
74     * Constructs a new {@code NoSuchMechanismException} with the
75     * specified detail message.
76     *
77     * @param message the detail message
78     */
79    public NoSuchMechanismException(String message) {
80        super(message);
81    }
82
83    /**
84     * Constructs a new {@code NoSuchMechanismException} with the
85     * specified detail message and cause.
86     * <p>Note that the detail message associated with
87     * {@code cause} is <i>not</i> automatically incorporated in
88     * this exception's detail message.
89     *
90     * @param message the detail message
91     * @param cause the cause (A {@code null} value is permitted, and
92     *        indicates that the cause is nonexistent or unknown.)
93     */
94    public NoSuchMechanismException(String message, Throwable cause) {
95        super(message);
96        this.cause = cause;
97    }
98
99    /**
100     * Constructs a new {@code NoSuchMechanismException} with the
101     * specified cause and a detail message of
102     * {@code (cause==null ? null : cause.toString())} (which typically
103     * contains the class and detail message of {@code cause}).
104     *
105     * @param cause the cause (A {@code null} value is permitted, and
106     *        indicates that the cause is nonexistent or unknown.)
107     */
108    public NoSuchMechanismException(Throwable cause) {
109        super(cause==null ? null : cause.toString());
110        this.cause = cause;
111    }
112
113    /**
114     * Returns the cause of this {@code NoSuchMechanismException} or
115     * {@code null} if the cause is nonexistent or unknown.  (The
116     * cause is the throwable that caused this
117     * {@code NoSuchMechanismException} to get thrown.)
118     *
119     * @return the cause of this {@code NoSuchMechanismException} or
120     *         {@code null} if the cause is nonexistent or unknown.
121     */
122    public Throwable getCause() {
123        return cause;
124    }
125
126    /**
127     * Prints this {@code NoSuchMechanismException}, its backtrace and
128     * the cause's backtrace to the standard error stream.
129     */
130    public void printStackTrace() {
131        super.printStackTrace();
132        //XXX print backtrace of cause
133    }
134
135    /**
136     * Prints this {@code NoSuchMechanismException}, its backtrace and
137     * the cause's backtrace to the specified print stream.
138     *
139     * @param s {@code PrintStream} to use for output
140     */
141    public void printStackTrace(PrintStream s) {
142        super.printStackTrace(s);
143        //XXX print backtrace of cause
144    }
145
146    /**
147     * Prints this {@code NoSuchMechanismException}, its backtrace and
148     * the cause's backtrace to the specified print writer.
149     *
150     * @param s {@code PrintWriter} to use for output
151     */
152    public void printStackTrace(PrintWriter s) {
153        super.printStackTrace(s);
154        //XXX print backtrace of cause
155    }
156}
157