KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > connection > CVSCommunicationException


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.connection;
12
13  
14 import java.io.InterruptedIOException JavaDoc;
15
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.team.internal.ccvs.core.*;
19
20 public class CVSCommunicationException extends CVSException {
21
22     private static final long serialVersionUID = 1L;
23
24     /**
25      * Create a new <code>CVSCommunicationException</code> with the
26      * given status.
27      */

28     private CVSCommunicationException(IStatus status) {
29         super(status);
30     }
31     /**
32      * Create a new <code>CVSCommunicationException</code> with the
33      * given message.
34      */

35     public CVSCommunicationException(String JavaDoc message) {
36         super(message);
37     }
38     
39     /**
40      * Create a new <code>CVSCommunicationException</code>.
41      *
42      * @param message a message describing the exception in detail.
43      * @param the CVS server
44      * @param the caught exception that has caused the communication
45      * exception.
46      */

47     public CVSCommunicationException(String JavaDoc message, ICVSRepositoryLocation cvsLocation, Exception JavaDoc e) {
48         this(new CVSStatus(IStatus.ERROR, CVSStatus.COMMUNICATION_FAILURE, message, e, cvsLocation));
49     }
50     
51     /**
52      * Create a new <code>CVSCommunicationException </code>.
53      *
54      * @param the caught exception that has caused the communication
55      * exception.
56      * @param the location of the CVS server.
57      */

58     public CVSCommunicationException(ICVSRepositoryLocation cvsLocation,Exception JavaDoc e) {
59         this(getStatusFor(e,cvsLocation));
60     }
61     
62     private static IStatus getStatusFor(Exception JavaDoc e,ICVSRepositoryLocation cvsLocation) {
63         if (e instanceof InterruptedIOException JavaDoc) {
64             MultiStatus status = new MultiStatus(CVSProviderPlugin.ID, 0, getMessageFor(e), e);
65             status.add(new CVSStatus(IStatus.ERROR, CVSStatus.COMMUNICATION_FAILURE, CVSMessages.CVSCommunicationException_interruptCause, cvsLocation));
66             status.add(new CVSStatus(IStatus.ERROR, CVSStatus.COMMUNICATION_FAILURE, CVSMessages.CVSCommunicationException_interruptSolution, cvsLocation));
67             status.add(new CVSStatus(IStatus.ERROR, CVSStatus.COMMUNICATION_FAILURE, CVSMessages.CVSCommunicationException_alternateInterruptCause, cvsLocation));
68             status.add(new CVSStatus(IStatus.ERROR, CVSStatus.COMMUNICATION_FAILURE, CVSMessages.CVSCommunicationException_alternateInterruptSolution, cvsLocation));
69             return status;
70         }
71         return new CVSStatus(IStatus.ERROR,CVSStatus.COMMUNICATION_FAILURE, getMessageFor(e), e, cvsLocation);
72     }
73     
74     public static String JavaDoc getMessageFor(Throwable JavaDoc throwable) {
75         String JavaDoc message = Policy.getMessage(getMessageKey(throwable));
76         if (message == null) {
77             message = NLS.bind(CVSMessages.CVSCommunicationException_io, (new Object JavaDoc[] {throwable.toString()}));
78         } else {
79             message = NLS.bind(message, (new Object JavaDoc[] {throwable.getMessage()}));
80         }
81         return message;
82     }
83     
84     private static String JavaDoc getMessageKey(Throwable JavaDoc t) {
85         String JavaDoc name = t.getClass().getName();
86         name = name.replace('.', '_');
87         return name;
88     }
89 }
90
Popular Tags