1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.vc.cvsimpl;
20
21 import nl.toolforge.karma.core.ErrorCode;
22
23 /***
24 * <p>This exception is thrown by the {@link CVSResponseAdapter} when an error message was received from CVS. The listener
25 * mechanism that is used by the Netbeans API sends events to a listener. Succesfull commands to CVS are passed to a
26 * {@link nl.toolforge.karma.core.cmd.CommandResponseHandler}, handled by Karma, but we want to be able to throw
27 * exceptions when errors have occurred. With a <code>RuntimeException</code>, we have the means to do so.
28 *
29 * <p>There is a little trick required to get to fetch this exception. The Netbeans API fetches all
30 * <code>RuntimeException</code>s and re-throws it as a <code>org.netbeans.lib.cvsclient.command.CommandException</code>.
31 * The original (runtime-)exception is kept in its <code>getUnderlyingException()</code>-method, which is thus used
32 * to determine if we threw a <code>CVSRuntimeException</code>. Works fine ...
33 *
34 * @author D.A. Smedes
35 * @version $Id: CVSRuntimeException.java,v 1.4 2004/11/02 22:26:44 asmedes Exp $
36 */
37 final class CVSRuntimeException extends RuntimeException {
38
39 private ErrorCode errorCode = null;
40 private Object[] messageArguments = null;
41
42 /***
43 * Constructs a <code>CVSRuntimeException</code>, with a non-<code>null</code> <code>ErrorCode</code>.
44 *
45 * @param errorCode An <code>ErrorCode</code> instance. Should not be <code>null</code> (or an
46 * <code>IllegalArgumentException</code> will be thrown.
47 */
48 public CVSRuntimeException(ErrorCode errorCode) {
49 this(errorCode, null);
50 }
51
52 public CVSRuntimeException(Throwable t, ErrorCode errorCode) {
53 super(t);
54 this.errorCode = errorCode;
55 }
56
57 public CVSRuntimeException(ErrorCode errorCode, Object[] messageArguments) {
58 this.errorCode = errorCode;
59 this.messageArguments = messageArguments;
60 }
61
62 public CVSRuntimeException(Throwable t, ErrorCode errorCode, Object[] messageArguments) {
63 super(t);
64 this.errorCode = errorCode;
65 this.messageArguments = messageArguments;
66 }
67
68
69 public String getMessage() {
70 if (messageArguments != null && messageArguments.length > 0) {
71 errorCode.setMessageArguments(messageArguments);
72 }
73 return errorCode.getErrorMessage();
74 }
75
76 /***
77 * Gets the exceptions' {@link nl.toolforge.karma.core.ErrorCode}.
78 * @return
79 */
80 public final ErrorCode getErrorCode() {
81 return errorCode;
82 }
83
84 public final Object[] getMessageArguments() {
85 return messageArguments;
86 }
87
88 }