1 11 package org.eclipse.team.internal.ccvs.core.connection; 12 13 14 import java.io.InterruptedIOException ; 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 28 private CVSCommunicationException(IStatus status) { 29 super(status); 30 } 31 35 public CVSCommunicationException(String message) { 36 super(message); 37 } 38 39 47 public CVSCommunicationException(String message, ICVSRepositoryLocation cvsLocation, Exception e) { 48 this(new CVSStatus(IStatus.ERROR, CVSStatus.COMMUNICATION_FAILURE, message, e, cvsLocation)); 49 } 50 51 58 public CVSCommunicationException(ICVSRepositoryLocation cvsLocation,Exception e) { 59 this(getStatusFor(e,cvsLocation)); 60 } 61 62 private static IStatus getStatusFor(Exception e,ICVSRepositoryLocation cvsLocation) { 63 if (e instanceof InterruptedIOException ) { 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 getMessageFor(Throwable throwable) { 75 String message = Policy.getMessage(getMessageKey(throwable)); 76 if (message == null) { 77 message = NLS.bind(CVSMessages.CVSCommunicationException_io, (new Object [] {throwable.toString()})); 78 } else { 79 message = NLS.bind(message, (new Object [] {throwable.getMessage()})); 80 } 81 return message; 82 } 83 84 private static String getMessageKey(Throwable t) { 85 String name = t.getClass().getName(); 86 name = name.replace('.', '_'); 87 return name; 88 } 89 } 90 | Popular Tags |