author | stefank |
Mon, 18 Aug 2014 12:25:36 +0000 | |
changeset 26153 | 8bdb58c0a883 |
parent 22139 | f4b2aa462b46 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
22139
f4b2aa462b46
8029236: Update copyright year to match last edit in jdk8 jaxp repository for 2013
joehw
parents:
18351
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
12005 | 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 |
package javax.xml.xpath; |
|
27 |
||
28 |
import java.io.PrintWriter; |
|
18351
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
29 |
import java.io.IOException; |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
30 |
import java.io.ObjectInputStream; |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
31 |
import java.io.ObjectOutputStream; |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
32 |
import java.io.ObjectStreamField; |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
33 |
import java.io.InvalidClassException; |
12005 | 34 |
|
35 |
/** |
|
36 |
* <code>XPathException</code> represents a generic XPath exception.</p> |
|
37 |
* |
|
38 |
* @author <a href="Norman.Walsh@Sun.com">Norman Walsh</a> |
|
39 |
* @author <a href="mailto:Jeff.Suttor@Sun.COM">Jeff Suttor</a> |
|
40 |
* @since 1.5 |
|
41 |
*/ |
|
42 |
public class XPathException extends Exception { |
|
43 |
||
18351
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
44 |
private static final ObjectStreamField[] serialPersistentFields = { |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
45 |
new ObjectStreamField( "cause", Throwable.class ) |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
46 |
}; |
12005 | 47 |
|
48 |
/** |
|
49 |
* <p>Stream Unique Identifier.</p> |
|
50 |
*/ |
|
51 |
private static final long serialVersionUID = -1837080260374986980L; |
|
52 |
||
53 |
/** |
|
54 |
* <p>Constructs a new <code>XPathException</code> |
|
55 |
* with the specified detail <code>message</code>.</p> |
|
56 |
* |
|
57 |
* <p>The <code>cause</code> is not initialized.</p> |
|
58 |
* |
|
59 |
* <p>If <code>message</code> is <code>null</code>, |
|
60 |
* then a <code>NullPointerException</code> is thrown.</p> |
|
61 |
* |
|
62 |
* @param message The detail message. |
|
63 |
* |
|
64 |
* @throws NullPointerException When <code>message</code> is |
|
65 |
* <code>null</code>. |
|
66 |
*/ |
|
67 |
public XPathException(String message) { |
|
68 |
super(message); |
|
69 |
if ( message == null ) { |
|
70 |
throw new NullPointerException ( "message can't be null"); |
|
71 |
} |
|
72 |
} |
|
73 |
||
74 |
/** |
|
75 |
* <p>Constructs a new <code>XPathException</code> |
|
76 |
* with the specified <code>cause</code>.</p> |
|
77 |
* |
|
78 |
* <p>If <code>cause</code> is <code>null</code>, |
|
79 |
* then a <code>NullPointerException</code> is thrown.</p> |
|
80 |
* |
|
81 |
* @param cause The cause. |
|
82 |
* |
|
83 |
* @throws NullPointerException if <code>cause</code> is <code>null</code>. |
|
84 |
*/ |
|
85 |
public XPathException(Throwable cause) { |
|
18351
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
86 |
super(cause); |
12005 | 87 |
if ( cause == null ) { |
88 |
throw new NullPointerException ( "cause can't be null"); |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
/** |
|
93 |
* <p>Get the cause of this XPathException.</p> |
|
94 |
* |
|
95 |
* @return Cause of this XPathException. |
|
96 |
*/ |
|
97 |
public Throwable getCause() { |
|
18351
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
98 |
return super.getCause(); |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
99 |
} |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
100 |
|
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
101 |
/** |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
102 |
* Writes "cause" field to the stream. |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
103 |
* The cause is got from the parent class. |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
104 |
* |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
105 |
* @param out stream used for serialization. |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
106 |
* @throws IOException thrown by <code>ObjectOutputStream</code> |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
107 |
* |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
108 |
*/ |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
109 |
private void writeObject(ObjectOutputStream out) |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
110 |
throws IOException |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
111 |
{ |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
112 |
ObjectOutputStream.PutField fields = out.putFields(); |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
113 |
fields.put("cause", (Throwable) super.getCause()); |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
114 |
out.writeFields(); |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
115 |
} |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
116 |
|
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
117 |
/** |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
118 |
* Reads the "cause" field from the stream. |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
119 |
* And initializes the "cause" if it wasn't |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
120 |
* done before. |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
121 |
* |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
122 |
* @param in stream used for deserialization |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
123 |
* @throws IOException thrown by <code>ObjectInputStream</code> |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
124 |
* @throws ClassNotFoundException thrown by <code>ObjectInputStream</code> |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
125 |
*/ |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
126 |
private void readObject(ObjectInputStream in) |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
127 |
throws IOException, ClassNotFoundException |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
128 |
{ |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
129 |
ObjectInputStream.GetField fields = in.readFields(); |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
130 |
Throwable scause = (Throwable) fields.get("cause", null); |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
131 |
|
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
132 |
if (super.getCause() == null && scause != null) { |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
133 |
try { |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
134 |
super.initCause(scause); |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
135 |
} catch(IllegalStateException e) { |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
136 |
throw new InvalidClassException("Inconsistent state: two causes"); |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
137 |
} |
e827e84fc265
8009579: Xpathexception does not honor initcause()
dmeetry
parents:
12457
diff
changeset
|
138 |
} |
12005 | 139 |
} |
140 |
||
141 |
/** |
|
142 |
* <p>Print stack trace to specified <code>PrintStream</code>.</p> |
|
143 |
* |
|
144 |
* @param s Print stack trace to this <code>PrintStream</code>. |
|
145 |
*/ |
|
146 |
public void printStackTrace(java.io.PrintStream s) { |
|
147 |
if (getCause() != null) { |
|
148 |
getCause().printStackTrace(s); |
|
149 |
s.println("--------------- linked to ------------------"); |
|
150 |
} |
|
151 |
||
152 |
super.printStackTrace(s); |
|
153 |
} |
|
154 |
||
155 |
/** |
|
156 |
* <p>Print stack trace to <code>System.err</code>.</p> |
|
157 |
*/ |
|
158 |
public void printStackTrace() { |
|
159 |
printStackTrace(System.err); |
|
160 |
} |
|
161 |
||
162 |
/** |
|
163 |
* <p>Print stack trace to specified <code>PrintWriter</code>.</p> |
|
164 |
* |
|
165 |
* @param s Print stack trace to this <code>PrintWriter</code>. |
|
166 |
*/ |
|
167 |
public void printStackTrace(PrintWriter s) { |
|
168 |
||
169 |
if (getCause() != null) { |
|
170 |
getCause().printStackTrace(s); |
|
171 |
s.println("--------------- linked to ------------------"); |
|
172 |
} |
|
173 |
||
174 |
super.printStackTrace(s); |
|
175 |
} |
|
176 |
} |