KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > CVSException


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.internal.ccvs.core;
12
13
14 import java.io.IOException JavaDoc;
15 import java.lang.reflect.InvocationTargetException JavaDoc;
16
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.team.core.TeamException;
20
21 /**
22  * A checked expection representing a failure in the CVS plugin.
23  * <p>
24  * CVS exceptions contain a status object describing the cause of
25  * the exception.
26  * </p>
27  *
28  * @see IStatus
29  */

30 public class CVSException extends TeamException {
31
32     private static final long serialVersionUID = 1L;
33
34     public CVSException(CoreException e) {
35         super(e);
36     }
37
38     public CVSException(String JavaDoc message) {
39         this(new CVSStatus(IStatus.ERROR, message));
40     }
41     
42     public CVSException(IStatus status) {
43         super(status);
44     }
45
46     /*
47      * Static helper methods for creating exceptions
48      */

49     public static CVSException wrapException(IResource resource, String JavaDoc message, IOException JavaDoc e) {
50         return new CVSException(new CVSStatus(IStatus.ERROR, IO_FAILED, message, e, resource));
51     }
52
53     /*
54      * Static helper methods for creating exceptions
55      */

56     public static CVSException wrapException(IResource resource, String JavaDoc message, CoreException e) {
57         return new CVSException(new CVSStatus(IStatus.ERROR, e.getStatus().getCode(), message, e, resource));
58     }
59
60     /*
61      * Static helper methods for creating exceptions
62      */

63     public static CVSException wrapException(Exception JavaDoc e) {
64         Throwable JavaDoc t = e;
65         if (e instanceof InvocationTargetException JavaDoc) {
66             Throwable JavaDoc target = ((InvocationTargetException JavaDoc) e).getTargetException();
67             if (target instanceof CVSException) {
68                 return (CVSException) target;
69             }
70             t = target;
71         }
72         //TODO: fix the caller to include a resource
73
//TODO: fix the caller to setup the error code
74
return new CVSException(new CVSStatus(IStatus.ERROR, UNABLE, t.getMessage() != null ? t.getMessage() : "", t, (IResource)null)); //$NON-NLS-1$
75
}
76     
77     public static CVSException wrapException(CoreException e) {
78         if (e instanceof CVSException) {
79             return (CVSException)e;
80         }
81         return new CVSException(e);
82     }
83 }
84
Popular Tags