KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > ResourceException


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.resources;
12
13 import java.io.PrintStream JavaDoc;
14 import java.io.PrintWriter JavaDoc;
15 import org.eclipse.core.resources.IResourceStatus;
16 import org.eclipse.core.runtime.*;
17
18 /**
19  * A checked exception representing a failure.
20  * <p>
21  * Resource exceptions contain a status object describing the cause of the
22  * exception, and optionally the path of the resource where the failure
23  * occurred.
24  * </p>
25  *
26  * @see IStatus
27  */

28 public class ResourceException extends CoreException {
29     /**
30      * All serializable objects should have a stable serialVersionUID
31      */

32     private static final long serialVersionUID = 1L;
33
34     public ResourceException(int code, IPath path, String JavaDoc message, Throwable JavaDoc exception) {
35         super(new ResourceStatus(code, path, message, exception));
36     }
37
38     /**
39      * Constructs a new exception with the given status object.
40      *
41      * @param status the status object to be associated with this exception
42      * @see IStatus
43      */

44     public ResourceException(IStatus status) {
45         super(status);
46     }
47
48     /**
49      * Prints a stack trace out for the exception, and
50      * any nested exception that it may have embedded in
51      * its Status object.
52      */

53     public void printStackTrace() {
54         printStackTrace(System.err);
55     }
56
57     /**
58      * Prints a stack trace out for the exception, and
59      * any nested exception that it may have embedded in
60      * its Status object.
61      */

62     public void printStackTrace(PrintStream JavaDoc output) {
63         synchronized (output) {
64             IStatus status = getStatus();
65             if (status.getException() != null) {
66                 String JavaDoc path = "()"; //$NON-NLS-1$
67
if (status instanceof IResourceStatus)
68                     path = "(" + ((IResourceStatus) status).getPath() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
69
output.print(getClass().getName() + path + "[" + status.getCode() + "]: "); //$NON-NLS-1$ //$NON-NLS-2$
70
status.getException().printStackTrace(output);
71             } else
72                 super.printStackTrace(output);
73         }
74     }
75
76     /**
77      * Prints a stack trace out for the exception, and
78      * any nested exception that it may have embedded in
79      * its Status object.
80      */

81     public void printStackTrace(PrintWriter JavaDoc output) {
82         synchronized (output) {
83             IStatus status = getStatus();
84             if (status.getException() != null) {
85                 String JavaDoc path = "()"; //$NON-NLS-1$
86
if (status instanceof IResourceStatus)
87                     path = "(" + ((IResourceStatus) status).getPath() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
88
output.print(getClass().getName() + path + "[" + status.getCode() + "]: "); //$NON-NLS-1$ //$NON-NLS-2$
89
status.getException().printStackTrace(output);
90             } else
91                 super.printStackTrace(output);
92         }
93     }
94
95 }
96
Popular Tags