KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > CommandException


1 /*****************************************************************************
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is the CVS Client Library.
16  * The Initial Developer of the Original Software is Robert Greig.
17  * Portions created by Robert Greig are Copyright (C) 2000.
18  * All Rights Reserved.
19  *
20  * Contributor(s): Robert Greig.
21  *****************************************************************************/

22 package org.netbeans.lib.cvsclient.command;
23
24 import java.io.*;
25 import java.text.*;
26 import java.util.*;
27
28 import org.netbeans.lib.cvsclient.util.*;
29
30 /**
31  * This exception is thrown when an error occurs while executing a command.
32  * It is nearly always a container for another exception.
33  * @author Robert Greig
34  */

35 public class CommandException extends Exception JavaDoc {
36     private Exception JavaDoc underlyingException;
37     private String JavaDoc localizedMessage;
38     private String JavaDoc message;
39
40     public CommandException(Exception JavaDoc underlyingException, String JavaDoc localizedMessage) {
41         this.underlyingException = underlyingException;
42         this.localizedMessage = localizedMessage;
43     }
44
45     public CommandException(String JavaDoc message, String JavaDoc localizedMessage) {
46         super(message);
47         this.message = message;
48         this.localizedMessage = localizedMessage;
49     }
50
51     public Exception JavaDoc getUnderlyingException() {
52         return underlyingException;
53     }
54
55     public void printStackTrace() {
56         if (underlyingException != null) {
57             underlyingException.printStackTrace();
58         }
59         else {
60             super.printStackTrace();
61         }
62     }
63
64     public void printStackTrace(PrintStream stream) {
65         if (underlyingException != null) {
66             underlyingException.printStackTrace(stream);
67         }
68         else {
69             super.printStackTrace(stream);
70         }
71     }
72
73     public void printStackTrace(PrintWriter writer) {
74         if (underlyingException != null) {
75             underlyingException.printStackTrace(writer);
76         }
77         else {
78             super.printStackTrace(writer);
79         }
80     }
81
82     public String JavaDoc getLocalizedMessage() {
83         if (localizedMessage == null) {
84             return message;
85         }
86         return localizedMessage;
87     }
88
89     public String JavaDoc getMessage() {
90         if (message == null) {
91             return localizedMessage;
92         }
93         return message;
94     }
95
96     protected static String JavaDoc getBundleString(String JavaDoc key) {
97         String JavaDoc value = null;
98         try {
99             ResourceBundle bundle = BundleUtilities.getResourceBundle(CommandException.class, "Bundle"); // NOI18N
100
if (bundle != null) {
101                 value = bundle.getString(key);
102             }
103         }
104         catch (MissingResourceException exc) {
105         }
106         return value;
107     }
108
109     public static String JavaDoc getLocalMessage(String JavaDoc key) {
110         return getLocalMessage(key, null);
111     }
112
113     public static String JavaDoc getLocalMessage(String JavaDoc key, Object JavaDoc[] arguments) {
114         String JavaDoc locMessage = CommandException.getBundleString(key);
115         if (locMessage == null) {
116             return null;
117         }
118         if (arguments != null) {
119             locMessage = MessageFormat.format(locMessage, arguments);
120         }
121         return locMessage;
122     }
123 }
124
Popular Tags