KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > core > TeamException


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.team.core;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.team.internal.core.TeamPlugin;
19
20 /**
21  * This exception is thrown by the team provider API. It represents a failure in an API call.
22  * Since some API calls take multiple arguments, the exception is capable of returning multiple
23  * statuses. The API definition determines if the exception represents a single or multiple status
24  * response; this can also be tested on the exception instance itself.
25  * <p>
26  * To determine the exact cause of the failure the caller should look at each status in detail.
27  * </p>
28  * @since 2.0
29  */

30 public class TeamException extends CoreException {
31     
32     // Field required to avoid compiler warning
33
private static final long serialVersionUID = 1L;
34
35     // The operation completed successfully.
36
public static final int OK = 0;
37
38     // The operation failed because the resource is not checked-in.
39
public static final int NOT_CHECKED_IN = -1;
40
41     // The operation failed because the resource is not checked-out.
42
public static final int NOT_CHECKED_OUT = -2;
43
44     // The corresponding remote resource no longer exists or was never created.
45
public static final int NO_REMOTE_RESOURCE = -3;
46
47     // The provider suffered an IO failure, the operation may be retried.
48
public static final int IO_FAILED = -4;
49
50     // The user is not authorized to execute the attempted operation.
51
public static final int NOT_AUTHORIZED = -5;
52
53     // The provider was unable to complete the operation for an unspecified reason.
54
public static final int UNABLE = -6;
55     
56     // The operation cannot be performed due to a conflict with other work.
57
public static final int CONFLICT = -7;
58
59     /**
60      * Create a <code>TeamException</code> which contains the given status object.
61      * @param status the status for this exception
62      */

63     public TeamException(IStatus status) {
64         super(status);
65     }
66
67     /**
68      * Create a <code>TeamException</code> with an
69      * error status that contains the given message and
70      * throwable.
71      * @param message the message for the exception
72      * @param e an associated exception
73      * @since 3.0
74      */

75     public TeamException(String JavaDoc message, Throwable JavaDoc e) {
76         super(new Status(IStatus.ERROR, TeamPlugin.ID, 0, message, e));
77     }
78     
79     /**
80      * Create a <code>TeamException</code> with an
81      * error status that contains the given message.
82      * @param message the message for the exception
83      */

84     public TeamException(String JavaDoc message) {
85         this(message, null);
86     }
87     
88     /**
89      * Create a <code>TeamException</code> that wraps the given <code>CoreException</code>
90      * @param e a <code>CoreException</code>
91      * @since 3.0
92      */

93     protected TeamException(CoreException e) {
94         super(asStatus(e));
95     }
96
97     private static Status asStatus(CoreException e) {
98         IStatus status = e.getStatus();
99         return new Status(status.getSeverity(), status.getPlugin(), status.getCode(), status.getMessage(), e);
100     }
101
102     /**
103      * Return a <code>TeamException</code> for the given exception.
104      * @param e an exception
105      * @return a <code>TeamException</code> for the given exception
106      * @since 3.0
107      */

108     public static TeamException asTeamException(CoreException e) {
109         if (e instanceof TeamException) {
110             return (TeamException)e;
111         }
112         return new TeamException(e);
113     }
114     
115     /**
116      * Return a <code>TeamException</code> for the given exception.
117      * @param e an exception
118      * @return a <code>TeamException</code> for the given exception
119      * @since 3.0
120      */

121     public static TeamException asTeamException(InvocationTargetException JavaDoc e) {
122         Throwable JavaDoc target = e.getTargetException();
123         if (target instanceof TeamException) {
124             return (TeamException) target;
125         }
126         return new TeamException(new Status(IStatus.ERROR, TeamPlugin.ID, UNABLE, target.getMessage() != null ? target.getMessage() : "", target)); //$NON-NLS-1$
127
}
128 }
129
Popular Tags