KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > bsf > engines > javascript > JsEngineStub


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.engines.javascript;
57
58 import java.rmi.RemoteException JavaDoc;
59 import org.apache.bsf.debug.util.DebugLog;
60
61 import org.apache.bsf.util.*;
62 import org.apache.bsf.debug.jsdi.*;
63 import org.mozilla.javascript.Context;
64 import org.mozilla.javascript.Script;
65 import org.mozilla.javascript.debug.DebuggableEngine;
66
67 /**
68  * Insert the type's description here.
69  * Creation date: (9/6/2001 1:21:46 PM)
70  * @author: Administrator
71  */

72 public class JsEngineStub
73     extends org.apache.bsf.debug.util.Skeleton
74     implements JsEngine {
75
76     RhinoEngineDebugger m_rhinoDbg;
77     boolean m_inCallback;
78     boolean m_resumeExecution;
79     Object JavaDoc m_lock;
80     
81     /**
82      * JsEngineStub constructor comment.
83      */

84     public JsEngineStub(RhinoEngineDebugger rhinoDbg)
85         throws RemoteException JavaDoc {
86         super(org.apache.bsf.debug.util.DebugConstants.JS_ENGINE_TID);
87         m_rhinoDbg = rhinoDbg;
88         m_lock = new Object JavaDoc();
89     }
90     
91     public boolean isSuspended() throws RemoteException JavaDoc {
92         return m_inCallback;
93     }
94     
95     public boolean poll() { return true; }
96     
97     public Object JavaDoc eval(String JavaDoc docname, String JavaDoc exp, int lineNo)
98         throws RemoteException JavaDoc {
99
100         Object JavaDoc retval = null;
101
102         Context.enter();
103         try {
104             retval = m_rhinoDbg.eval(docname, exp, lineNo);
105         } catch (Throwable JavaDoc ex) {
106             throw new RemoteException JavaDoc("Failed eval", ex);
107         } finally {
108             Context.exit();
109         }
110         return retval;
111     }
112
113     public JsContext getContext(int depth) throws RemoteException JavaDoc {
114         try {
115             Context.enter();
116             return m_rhinoDbg.getContext(depth);
117         } finally {
118             Context.exit();
119         }
120
121     }
122
123     public int getContextCount() throws RemoteException JavaDoc {
124         int count;
125         try {
126             Context.enter();
127             count = m_rhinoDbg.getContextCount();
128             DebugLog.stdoutPrintln(" count = "+count,
129                                    DebugLog.BSF_LOG_L3);
130             return count;
131         } finally {
132             Context.exit();
133         }
134
135     }
136   
137     public String JavaDoc getThread() throws RemoteException JavaDoc {
138         return m_rhinoDbg.getThread();
139     }
140
141     public String JavaDoc getThreadGroup() throws RemoteException JavaDoc {
142         return m_rhinoDbg.getThreadGroup();
143     }
144
145     /**
146      * Return the current debugger.
147      * @return the debugger, or null if none is attached.
148      */

149     public JsCallbacks getDebugger() throws RemoteException JavaDoc {
150         try {
151             Context.enter();
152             return m_rhinoDbg.getDebugger();
153         } finally {
154             Context.exit();
155         }
156     }
157
158     public JsObject getGlobalObject() throws RemoteException JavaDoc {
159         try {
160             Context.enter();
161             return m_rhinoDbg.getGlobalObject();
162         } finally {
163             Context.exit();
164         }
165     }
166
167     public JsObject getUndefinedValue() throws RemoteException JavaDoc {
168         try {
169             Context.enter();
170             return m_rhinoDbg.getUndefinedValue();
171         } finally {
172             Context.exit();
173         }
174     }
175
176     public void run() throws RemoteException JavaDoc {
177         try {
178             Context.enter();
179             m_rhinoDbg.run(this);
180         } catch (Exception JavaDoc ex) {
181             throw new RemoteException JavaDoc("Internal JSDI error",ex);
182         } finally {
183             Context.exit();
184         }
185     }
186
187     /**
188      * Set the associated debugger.
189      * @param debugger the debugger to be used on callbacks from
190      * the engine.
191      */

192     public void setDebugger(JsCallbacks debugger) throws RemoteException JavaDoc {
193         try {
194             Context.enter();
195             m_rhinoDbg.setDebugger(debugger);
196         } catch (Exception JavaDoc ex) {
197             throw new RemoteException JavaDoc("Internal JSDI error",ex);
198         } finally {
199             Context.exit();
200         }
201     }
202
203     public void stepIn() throws RemoteException JavaDoc {
204         try {
205             Context.enter();
206             DebugLog.stdoutPrintln("Step In command on "+this,
207                                    DebugLog.BSF_LOG_L3);
208             m_rhinoDbg.stepIn(this);
209         } catch (Exception JavaDoc ex) {
210             throw new RemoteException JavaDoc("Internal JSDI error",ex);
211         } finally {
212             Context.exit();
213         }
214     }
215
216     public void stepOut() throws RemoteException JavaDoc {
217         try {
218             Context.enter();
219             m_rhinoDbg.stepOut(this);
220         } catch (Exception JavaDoc ex) {
221             throw new RemoteException JavaDoc("Internal JSDI error",ex);
222         } finally {
223             Context.exit();
224         }
225     }
226
227     public void stepOver() throws RemoteException JavaDoc {
228         RhinoContextProxy rcp;
229         try {
230             Context.enter();
231             m_rhinoDbg.stepOver(this);
232         } catch (Exception JavaDoc ex) {
233             throw new RemoteException JavaDoc("Internal JSDI error",ex);
234         } finally {
235             Context.exit();
236         }
237     }
238 }
239
Popular Tags