KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > bsf > debug > meta > DebugManagerStub


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2002 The Apache Software Foundation. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if
20  * any, must include the following acknowlegement:
21  * "This product includes software developed by the
22  * Apache Software Foundation (http://www.apache.org/)."
23  * Alternately, this acknowlegement may appear in the software itself,
24  * if and wherever such third-party acknowlegements normally appear.
25  *
26  * 4. The names "Apache BSF", "Apache", and "Apache Software Foundation"
27  * must not be used to endorse or promote products derived from
28  * this software without prior written permission. For written
29  * permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache"
32  * nor may "Apache" appear in their names without prior written
33  * permission of the Apache Group.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many individuals
50  * on behalf of the Apache Software Foundation and was originally created by
51  * Sanjiva Weerawarana and others at International Business Machines
52  * Corporation. For more information on the Apache Software Foundation,
53  * please see <http://www.apache.org/>.
54  */

55
56 package org.apache.bsf.debug.meta;
57 import org.apache.bsf.debug.*;
58 import java.net.*;
59 import java.io.*;
60 import java.util.*;
61 import java.rmi.RemoteException JavaDoc;
62
63 import org.apache.bsf.*;
64 import org.apache.bsf.debug.util.*;
65
66 public class DebugManagerStub extends Stub implements BSFDebugManager {
67     protected Vector fEngines;
68     
69     public DebugManagerStub(SocketConnection con) throws IOException {
70         super(con, DebugConstants.BSF_DEBUG_MANAGER_TID,
71               DebugConstants.BSF_DEBUG_MANAGER_UID);
72         fEngines = new Vector();
73     }
74
75     /**
76      * A communication error occured, simply disconnect
77      * and therefore clean everything up.
78      */

79     public void disconnectNotify(Exception JavaDoc ex) {
80         fEngines = new Vector();
81     }
82
83     public void sendQuitNotice() throws RemoteException JavaDoc {
84         ResultCell cell = null;
85         try {
86             cell = m_con.prepareOutgoingInvoke(this,DebugConstants.BSF_DEBUG_MANAGER_TID,DebugConstants.DM_QUIT_NOTIFY);
87             cell.writeInt(0);
88             cell.waitForCompletion();
89         }
90         catch (Exception JavaDoc ex) {
91             throw new RemoteException JavaDoc("Error sending quit notice.", ex);
92         }
93         
94     }
95
96     void engineCreateNotify(JsEngineStub eng) {
97         fEngines.addElement(eng);
98     }
99
100     /**
101      * Determine the language of a script file by looking at the file
102      * extension.
103      *
104      * @param filename the name of the file
105      *
106      * @return the scripting language the file is in if the file extension
107      * is known to me (must have been registered via
108      * registerScriptingEngine).
109      *
110      * @exception RemoteException if file's extension is unknown.
111      */

112     public String JavaDoc getLangFromFilename(String JavaDoc fileName)
113         throws RemoteException JavaDoc {
114         ResultCell cell;
115         try {
116             cell = m_con.prepareOutgoingInvoke(this, DebugConstants.BSF_DEBUG_MANAGER_TID, DebugConstants.DM_GET_LANG_FROM_FILENAME);
117             cell.writeObject(fileName);
118             return (String JavaDoc) cell.waitForValueObject();
119         }
120         catch (IOException ex) {
121             throw new RemoteException JavaDoc("Marshalling error", ex);
122         }
123         catch (Exception JavaDoc ex) {
124             throw new RemoteException JavaDoc("Error at server", ex);
125         }
126     }
127
128     /**
129      * Determine whether a language is registered.
130      *
131      * @param lang string identifying a language
132      *
133      * @return true iff it is
134      */

135     public boolean isLanguageRegistered(String JavaDoc lang)
136         throws RemoteException JavaDoc {
137         ResultCell cell=null;
138         try {
139             cell = m_con.prepareOutgoingInvoke(this,DebugConstants.BSF_DEBUG_MANAGER_TID,DebugConstants.DM_IS_LANGUAGE_REGISTERED);
140             cell.writeObject(lang);
141
142             return cell.waitForBooleanValue();
143         }
144         catch (IOException ex) {
145             throw new RemoteException JavaDoc("Marshalling error", ex);
146         }
147         catch (Exception JavaDoc ex) {
148             throw new RemoteException JavaDoc("Error at server", ex);
149         }
150     }
151
152     /**
153      * Breakpoints are placed within documents either at a specific line
154      * or offset. While breakpoints can be set at lines and offsets in
155      * the same document, there is no conversions between lines and offsets.
156      * Some engines may support only offsets or only lines and therefore
157      * some breakpoints may be ignored.
158      *
159      * Placing a breakpoint is local to a debugger connection.
160      * In other words, breakpoints set by other debuggers are not visible
161      * to a given debugger.
162      *
163      * Breakpoints are given identifiers so to make easier for debuggers
164      * to manipulate breakpoints. Identifiers are allocated by the debugger;
165      * they must be unique for the entire session between that debugger
166      * and the debug manager.
167      *
168      */

169     public void placeBreakpointAtLine(int bpid, String JavaDoc docname, int lineno)
170         throws RemoteException JavaDoc {
171
172         ResultCell cell=null;
173         try {
174             cell = m_con.prepareOutgoingInvoke(this,DebugConstants.BSF_DEBUG_MANAGER_TID,DebugConstants.DM_PLACE_BREAKPOINT_AT_LINE);
175             cell.writeInt(bpid);
176             cell.writeObject(docname);
177             cell.writeInt(lineno);
178             cell.waitForCompletion();
179         }
180         catch (IOException ex) {
181             throw new RemoteException JavaDoc("Marshalling error", ex);
182         }
183         catch (Exception JavaDoc ex) {
184             throw new RemoteException JavaDoc("Error at server", ex);
185         }
186
187     }
188
189     public void placeBreakpointAtOffset(int bpid, String JavaDoc docname, int offset)
190         throws RemoteException JavaDoc {
191         throw new Error JavaDoc("FYI");
192     }
193
194     /**
195      * Allows to remove a breakpoint.
196      */

197     public void removeBreakpoint(String JavaDoc docname, int bpid)
198         throws RemoteException JavaDoc {
199         ResultCell cell;
200         try {
201             cell = m_con.prepareOutgoingInvoke(this,DebugConstants.BSF_DEBUG_MANAGER_TID, DebugConstants.DM_REMOVE_BREAKPOINT);
202             cell.writeObject(docname);
203             cell.writeInt(bpid);
204             cell.waitForCompletion();
205         }
206         catch (IOException ex) {
207             throw new RemoteException JavaDoc("Marshalling error", ex);
208         }
209         catch (Exception JavaDoc ex) {
210             throw new RemoteException JavaDoc("Error at server", ex);
211         }
212     }
213
214     /**
215      * Allows setting entry/exit mode
216      */

217     public void setEntryExit(String JavaDoc docname, boolean on)
218         throws RemoteException JavaDoc {
219         ResultCell cell;
220         int int_on = (on) ? 1 : 0;
221
222         try {
223             cell = m_con.prepareOutgoingInvoke(this,DebugConstants.BSF_DEBUG_MANAGER_TID, DebugConstants.DM_SET_ENTRY_EXIT);
224             cell.writeObject(docname);
225             cell.writeInt(int_on);
226             cell.waitForCompletion();
227         }
228         catch (IOException ex) {
229             throw new RemoteException JavaDoc("Marshalling error", ex);
230         }
231         catch (Exception JavaDoc ex) {
232             throw new RemoteException JavaDoc("Error at server", ex);
233         }
234     }
235
236     /**
237      * Allows a debugger to ask if the engine for a given language
238      * will support either line or offset breakpoints.
239      * Note: this will most likely provoke the loading of the engine.
240      */

241     public boolean supportBreakpointAtOffset(String JavaDoc lang)
242         throws RemoteException JavaDoc {
243         return false;
244     }
245
246     public boolean supportBreakpointAtLine(String JavaDoc lang)
247         throws RemoteException JavaDoc {
248         return true;
249     }
250
251     /**
252      * Register a debugger for a scripting engine.
253      *
254      * @param lang string identifying language
255      * @exception RemoteException if the language is unknown (i.e., if it
256      * has not been registered) with a reason of
257      * REASON_UNKNOWN_LANGUAGE. If the language is known but
258      * if the interface can't be created for some reason, then
259      * the reason is set to REASON_OTHER_ERROR and the actual
260      * exception is passed on as well.
261      */

262     public void registerDebugger(String JavaDoc lang, BSFDebugger debugger)
263         throws RemoteException JavaDoc {
264         ResultCell cell;
265         try {
266             cell = m_con.prepareOutgoingInvoke(this,DebugConstants.BSF_DEBUG_MANAGER_TID,DebugConstants.DM_REGISTER_DEBUGGER_FOR_LANG);
267             cell.writeObject(lang);
268             cell.writeObject(debugger);
269             cell.waitForCompletion();
270         }
271         catch (IOException ex) {
272             throw new RemoteException JavaDoc("Marshalling error", ex);
273         }
274         catch (Exception JavaDoc ex) {
275             throw new RemoteException JavaDoc("Error at server", ex);
276         }
277     }
278
279     public void unregisterDebugger(String JavaDoc lang) throws RemoteException JavaDoc {
280         ResultCell cell;
281         try {
282             cell = m_con.prepareOutgoingInvoke(this, DebugConstants.BSF_DEBUG_MANAGER_TID,DebugConstants.DM_UNREGISTER_DEBUGGER_FOR_LANG);
283             cell.writeObject(lang);
284             cell.waitForCompletion();
285         }
286         catch (IOException ex) {
287             throw new RemoteException JavaDoc("Marshalling error", ex);
288         }
289         catch (Exception JavaDoc ex) {
290             throw new RemoteException JavaDoc("Error at server", ex);
291         }
292     }
293 }
294
Popular Tags