3 import java.io.OutputStream;
4 import java.io.PrintWriter;
5 import java.io.StringWriter;
7 import java.text.DateFormat;
14 * Created: Thu Feb 15 12:58:59 2001
16 * @author Paul Kinnucan
17 * @version $Revision: 1.8 $
20 public class JDE implements Protocol {
23 * The single instance of this class.
26 private static JDE s_jde = new JDE(System.out);
29 * Writes command responses, messages, and event notifications to
32 private PrintWriter m_out;
34 /** logical OR of the debug flags that should be used in this particular session */
35 private int m_debugFlags
45 private JDE(OutputStream out) {
46 m_out = new PrintWriter(out, true);
52 * Private methods ----------------------------------------------------
56 private synchronized void p_transmit(String type, String message) {
57 m_out.println("(" + JDE_BUG + type + " " + message + ")");
60 private void p_setDebugFlags(int flags) {
64 private void p_debug(int flag, String message) {
65 if ((m_debugFlags & flag) != 0) {
66 p_transmit(DEBUG, " \"" +
67 DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date()) + ": " +
73 * Public, static interface --------------------------------------------------
77 * To indicate which of the debugging flags should be set. If a
78 * flag is set, it means that calls to <code>JDE.debug()</code>
79 * with that flag will actually be printed.
81 * @param flags an <code>int</code> value with a bitwise OR of the
82 * types of information that are desired.
85 public static void setDebugFlags(int flags) {
86 s_jde.p_setDebugFlags(flags);
90 * Send a debugging message to Emacs, for display in the
91 * <code>*JDEbug*</code> buffer. The message will only be printed
92 * if the flag that is passed in the first argument is set. The
93 * current time is prepended to the message string.
95 * @param flag an <code>int</code> value
96 * @param message a <code>String</code> value
100 public static void debug(int flag, String message) {
101 s_jde.p_debug(flag, message);
105 * Sends the result of executing a debugger command to
106 * Emacs. Depending on wether the command was successful or not,
107 * different lisp code will be generated. If the
108 * <code>quote</code> argument is set ({@link Protocol#QUOTE}),
109 * double quotes will be added around the message string. The idea
110 * is that if the command result should be a Lisp string, you
111 * should set the <code>quote</code> argument to get the double
112 * quotes, and otherwise not.
114 * @param cmdID the ID of the command
115 * @param message a <code>String</code> value
116 * @param success indicates what to generate, {@link
117 * Protocol#COMMAND_RESULT} or {@link Protocol#COMMAND_ERROR}
118 * @param quote a <code>boolean</code> value
120 public static void commandResult(Integer cmdID, String message, boolean success, boolean quote) {
121 String type = success ? COMMAND_RESULT : COMMAND_ERROR;
123 StringBuffer messageBuffer = new StringBuffer(cmdID.toString());
125 if (message != null && message.length() > 0) {
126 messageBuffer.append(" ");
128 messageBuffer.append("\"");
130 messageBuffer.append(message);
132 messageBuffer.append("\"");
136 s_jde.p_transmit(type, messageBuffer.toString());
141 * Equivalent to calling {@link #commandResult(Integer,
142 * String, boolean, boolean)} with the <code>quote</code> argument
143 * set to {@link Protocol#NOQUOTE}.
145 * @param cmdID an <code>Integer</code> value
146 * @param message a <code>String</code> value
147 * @param success a <code>boolean</code> value
149 public static void commandResult(Integer cmdID, String message, boolean success) {
150 commandResult(cmdID, message, success, NOQUOTE);
154 * A method for sending more arbitrary information to Emacs. If
155 * the <code>quote</code> argument is set, double quotes will
156 * added around the message string.
158 * @param procID an <code>Integer</code> value
159 * @param type a <code>String</code> value indicating what Lisp
160 * command should be sent
161 * @param message a <code>String</code> value
162 * @param quote a <code>boolean</code> value
164 public static void signal(Integer procID, String type, String message, boolean quote) {
165 StringBuffer messageBuffer = new StringBuffer(procID.toString());
167 if (message != null && message.length() > 0) {
168 messageBuffer.append(" ");
170 messageBuffer.append("\"");
172 messageBuffer.append(message);
174 messageBuffer.append("\"");
178 s_jde.p_transmit(type, messageBuffer.toString());
181 /** A method for signaling JDEE that an exception occured. The
182 message displayed in Emacs will include the stack trace. */
183 public static void signalException(Throwable exc) {
184 s_jde.p_signalException(exc);
187 private void p_signalException(Throwable exc) {
188 if ((m_debugFlags & EXCEPTION) != 0) {
189 Writer writer = new StringWriter();
190 exc.printStackTrace(new PrintWriter(writer));
191 signal(new Integer(-1), ERROR,
192 "Exception during command execution: " +
200 * Equivalent to calling {@link #signal(Integer,
201 * String, String, boolean)} with the <code>quote</code> argument
204 * @param procID an <code>Integer</code> value
205 * @param type a <code>String</code> value
206 * @param message a <code>String</code> value
208 public static void signal(Integer procID, String type, String message) {
209 signal(procID, type, message, NOQUOTE);
215 * Revision 1.8 2004/12/24 16:05:13 troy
216 * Add window to display threads and stacks
218 * Revision 1.7 2003/09/21 05:23:11 paulk
219 * Fix bug in setDebugFlags (it was calling itself).
221 * Revision 1.6 2003/04/29 16:51:56 troy
222 * Initial version of GUI. Includes display of local variables.
224 * Revision 1.5 2003/01/15 05:50:51 paulk
227 * Revision 1.4 2003/01/08 06:53:38 paulk
228 * Integrate Petter Mahlen's updates.