source: trunk/gcc/libjava/javax/naming/NamingException.java

Last change on this file was 1392, checked in by bird, 21 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 9.2 KB
Line 
1/* NamingException.java -- Superclass of all naming Exceptions
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package javax.naming;
39
40import java.io.PrintStream;
41import java.io.PrintWriter;
42
43/**
44 * Superclass of all naming Exceptions.
45 * Can contain extra information about the root cause of this exception
46 * (for example when the original exception was not a subclass of
47 * <code>NamingException</code>), the part of the <code>Name</code> that
48 * could be resolved (including the <code>Object</code> it resolved to)
49 * and the part of the <code>Name</code> that could not be resolved when
50 * the exception occured.
51 *
52 * @since 1.3
53 * @author Anthony Green (green@redhat.com)
54 * @author Mark Wielaard (mark@klomp.org)
55 */
56public class NamingException extends Exception
57{
58
59 /**
60 * The root cause of this exception. Might be null. Set by calling
61 * <code>setRootCause()</code>, can be accessed by calling
62 * <code>getRootCause()</code>.
63 */
64 protected Throwable rootException;
65
66 /**
67 * If the exception was caused while resolving a <code>Name</code> then
68 * this field contains that part of the name that could be resolved.
69 * Field might be null. Set by calling <code>setResolvedName()</code>.
70 * Can be accessed by calling <code>getResolvedName</code>.
71 */
72 protected Name resolvedName;
73
74 /**
75 * If the exception was caused while resolving a <code>Name</code> then
76 * this field contains the object that part of the name could be resolved to.
77 * Field might be null. Set by calling <code>setResolvedObj()</code>.
78 * Can be accessed by calling <code>getResolvedObj</code>.
79 */
80 protected Object resolvedObj;
81
82 /**
83 * If the exception was caused while resolving a <code>Name</code> then
84 * this field contains that part of the name that could not be resolved.
85 * Field might be null. Set by calling <code>setRemainingName()</code>.
86 * The field can be extended by calling <code>appendRemainingName()</code>
87 * or <code>appendRemainingComponent()</code>.
88 * Can be accessed by calling <code>getRemainingName</code>.
89 */
90 protected Name remainingName;
91
92 /**
93 * Creates a new NamingException without a message. Does not set any of the
94 * <code>rootException</code>, <code>resolvedName</code>,
95 * <code>resolvedObj</code> or <code>remainingObject,<code> fields.
96 * These fields can be set later.
97 */
98 public NamingException ()
99 {
100 super();
101 }
102
103 /**
104 * Creates a new NamingException with a detailed message. Does not set
105 * the <code>rootException</code>, <code>resolvedName</code>,
106 * <code>resolvedObj</code> or <code>remainingObject,<code> fields.
107 * These fields can be set later.
108 */
109 public NamingException (String msg)
110 {
111 super(msg);
112 }
113
114 /**
115 * Gets the root cause field <code>rootException</code> of this Exception.
116 */
117 public Throwable getRootCause ()
118 {
119 return rootException;
120 }
121
122 /**
123 * Sets the root cause field <code>rootException</code> of this Exception.
124 */
125 public void setRootCause (Throwable e)
126 {
127 rootException = e;
128 }
129
130 /**
131 * Gets the part of the name that could be resolved before this exception
132 * happend. Returns the <code>resolvedName</code> field of this Exception.
133 */
134 public Name getResolvedName ()
135 {
136 return resolvedName;
137 }
138
139 /**
140 * Sets the part of the name that could be resolved before this exception
141 * happend. Sets the <code>resolvedName</code> field of this Exception.
142 */
143 public void setResolvedName (Name name)
144 {
145 resolvedName = name;
146 }
147
148 /**
149 * Gets the Object to which (part of) the name could be resolved before this
150 * exception happend. Returns the <code>resolvedObj</code> field of this
151 * Exception.
152 */
153 public Object getResolvedObj ()
154 {
155 return resolvedObj;
156 }
157
158 /**
159 * Sets the Object to which (part of) the name could be resolved before this
160 * exception happend. Sets the <code>resolvedObj</code> field of this
161 * Exception.
162 */
163 public void setResolvedObj (Object o)
164 {
165 resolvedObj = o;
166 }
167
168 /**
169 * Gets the part of the name that could not be resolved before this exception
170 * happend. Returns the <code>remainingName</code> field of this Exception.
171 */
172 public Name getRemainingName ()
173 {
174 return remainingName;
175 }
176
177 /**
178 * Sets the part of the name that could be resolved before this exception
179 * happend. Sets the <code>resolvedName</code> field of this Exception.
180 * The field can be extended by calling <code>appendRemainingName()</code>
181 * or <code>appendRemainingComponent()</code>.
182 */
183 public void setRemainingName (Name name)
184 {
185 remainingName = name;
186 }
187
188 /**
189 * Adds the given <code>Name</code> to the <code>remainingName</code> field.
190 * Does nothing when <code>name</code> is null or when a
191 * <code>InvalidNameException</code> is thrown when adding the name.
192 *
193 * @see Name#addAll(Name)
194 */
195 public void appendRemainingName (Name name)
196 {
197 if (name != null)
198 try
199 {
200 remainingName.addAll(name);
201 }
202 catch(InvalidNameException ine) { /* ignored */ }
203 }
204
205 /**
206 * Adds the given <code>String</code> to the <code>remainingName</code> field.
207 * Does nothing when <code>name</code> is null or when a
208 * <code>InvalidNameException</code> is thrown when adding the component.
209 *
210 * @see Name#add(String)
211 */
212 public void appendRemainingComponent (String name)
213 {
214 if (name != null)
215 try
216 {
217 remainingName.add(name);
218 }
219 catch(InvalidNameException ine) { /* ignored */ }
220 }
221
222 /**
223 * Gets the message given to the constructor or null if no message was given.
224 *
225 * @see Throwable#getMessage();
226 */
227 public String getExplanation()
228 {
229 return getMessage();
230 }
231
232 /**
233 * Returns a String representation of this exception and possibly including
234 * the part object that could be resolved if the given flag is set to true.
235 * Always includes the root cause and the remaining name if not null.
236 */
237 public String toString(boolean objectInfo)
238 {
239 StringBuffer sb = new StringBuffer(super.toString());
240 Throwable cause = getRootCause();
241 if (cause != null)
242 {
243 sb.append(" caused by ");
244 sb.append(cause);
245 }
246 Name remaining = getRemainingName();
247 if (remaining != null)
248 {
249 sb.append(" [remainingName: ");
250 sb.append(remaining);
251 }
252 Object resolved = getResolvedObj();
253 if (objectInfo && resolved != null)
254 {
255 if (remainingName == null)
256 sb.append(" [");
257 else
258 sb.append(", ");
259 sb.append("resolvedObj: ");
260 sb.append(resolved);
261 }
262 if ((remaining != null) || (objectInfo && resolved != null))
263 sb.append(']');
264
265 return sb.toString();
266 }
267
268 /**
269 * Returns a string representation of this exception.
270 * Calls <code>toString(false)</code>.
271 */
272 public String toString()
273 {
274 return toString(false);
275 }
276 /**
277 * Prints the stacktrace of this exception or of the root cause if not null.
278 */
279 public void printStackTrace()
280 {
281 Throwable cause = getRootCause();
282 if (cause != null)
283 cause.printStackTrace();
284 else
285 super.printStackTrace();
286 }
287
288 /**
289 * Prints the stacktrace of this exception or of the root cause if not null
290 * to the given <code>PrintStream</code>.
291 */
292 public void printStackTrace(PrintStream ps)
293 {
294 Throwable cause = getRootCause();
295 if (cause != null)
296 cause.printStackTrace(ps);
297 else
298 super.printStackTrace(ps);
299 }
300
301 /**
302 * Prints the stacktrace of this exception or of the root cause if not null
303 * to the given <code>PrintWriter</code>.
304 */
305 public void printStackTrace(PrintWriter pw)
306 {
307 Throwable cause = getRootCause();
308 if (cause != null)
309 cause.printStackTrace(pw);
310 else
311 super.printStackTrace(pw);
312 }
313}
314
Note: See TracBrowser for help on using the repository browser.