KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.bsf.debug.*;
59 import org.apache.bsf.debug.jsdi.*;
60
61 import org.mozilla.javascript.*;
62 import org.mozilla.javascript.debug.*;
63
64 import java.rmi.RemoteException JavaDoc;
65
66 /**
67  * Insert the type's description here.
68  * Creation date: (8/24/2001 9:54:48 AM)
69  * @author: Administrator
70  */

71 public class JsObjectStub
72 extends org.apache.bsf.debug.util.Skeleton
73     implements JsObject {
74
75     Scriptable m_object;
76
77     RhinoEngineDebugger m_rhinoDbg;
78
79     //////////////////////////////////////////////////////////////////
80
public JsObjectStub(RhinoEngineDebugger rhinoDbg, Scriptable object)
81         throws RemoteException JavaDoc {
82         super(org.apache.bsf.debug.util.DebugConstants.JS_OBJECT_TID);
83         m_rhinoDbg = rhinoDbg;
84         m_object = object;
85     }
86     //////////////////////////////////////////////////////////////////
87
public void define(String JavaDoc propertyName, JsObject value, int attributes) {
88         try {
89             Context.enter();
90         } finally {
91             Context.exit();
92         }
93     }
94     //////////////////////////////////////////////////////////////////
95
public void define(String JavaDoc propertyName, Object JavaDoc value, int attributes) {
96         try {
97             Context.enter();
98         } finally {
99             Context.exit();
100         }
101     }
102     //////////////////////////////////////////////////////////////////
103
public void delete(int index) {
104         try {
105             Context.enter();
106         } finally {
107             Context.exit();
108         }
109     }
110     //////////////////////////////////////////////////////////////////
111
public void delete(String JavaDoc name) {
112         try {
113             Context.enter();
114         } finally {
115             Context.exit();
116         }
117     }
118     //////////////////////////////////////////////////////////////////
119
public Object JavaDoc get(int index) throws RemoteException JavaDoc {
120         try {
121             Context.enter();
122             Object JavaDoc prop = m_object.get(index, m_object);
123             return m_rhinoDbg.marshallProperty(prop);
124         } finally {
125             Context.exit();
126         }
127     }
128     //////////////////////////////////////////////////////////////////
129
public Object JavaDoc get(String JavaDoc name) throws RemoteException JavaDoc {
130         try {
131             Context.enter();
132             Object JavaDoc prop = m_object.get(name, m_object);
133             return m_rhinoDbg.marshallProperty(prop);
134         } finally {
135             Context.exit();
136         }
137     }
138     //////////////////////////////////////////////////////////////////
139
public String JavaDoc getClassName() {
140         try {
141             Context.enter();
142             return null;
143         } finally {
144             Context.exit();
145         }
146     }
147     //////////////////////////////////////////////////////////////////
148
public Object JavaDoc getDefaultValue(Class JavaDoc hint) {
149         try {
150             Context.enter();
151             return null;
152         } finally {
153             Context.exit();
154         }
155     }
156     //////////////////////////////////////////////////////////////////
157
public Object JavaDoc[] getIds(boolean all) {
158         try {
159             Context.enter();
160             Object JavaDoc ids[] = null;
161             if (all) {
162                 if (m_object instanceof ScriptableObject) {
163                     ScriptableObject so = (ScriptableObject) m_object;
164                     ids = so.getAllIds();
165                 } else
166                     ids = m_object.getIds();
167             } else
168                 ids = m_object.getIds();
169
170             return ids;
171         } finally {
172             Context.exit();
173         }
174     }
175     //////////////////////////////////////////////////////////////////
176
public JsObject getPrototype() throws RemoteException JavaDoc {
177         try {
178             Context.enter();
179             Scriptable prot = m_object.getPrototype();
180             return m_rhinoDbg.marshallScriptable(prot);
181 /*
182             JsObject stub;
183
184             stub = m_rhinoDbg.getStub(prot);
185             if (stub == null) {
186                 stub = new JsObjectStub(m_rhinoDbg, prot);
187             }
188             return (JsPrototype) stub;
189 */

190         } finally {
191             Context.exit();
192         }
193     }
194     //////////////////////////////////////////////////////////////////
195
public JsObject getScope() throws RemoteException JavaDoc {
196         try {
197             Context.enter();
198             Scriptable obj = m_object.getParentScope();
199             return m_rhinoDbg.marshallScriptable(obj);
200         } finally {
201             Context.exit();
202         }
203     }
204     //////////////////////////////////////////////////////////////////
205
public boolean has(int index) {
206         try {
207             Context.enter();
208             return false;
209         } finally {
210             Context.exit();
211         }
212     }
213     //////////////////////////////////////////////////////////////////
214
public boolean has(String JavaDoc name) {
215         try {
216             Context.enter();
217             return false;
218         } finally {
219             Context.exit();
220         }
221     }
222     //////////////////////////////////////////////////////////////////
223
public boolean hasInstance(JsObject instance) {
224         try {
225             Context.enter();
226             return false;
227         } finally {
228             Context.exit();
229         }
230     }
231     //////////////////////////////////////////////////////////////////
232
public boolean isFunction() {
233         try {
234             Context.enter();
235             return (m_object instanceof NativeFunction)
236                 && !(m_object instanceof NativeScript);
237         } finally {
238             Context.exit();
239         }
240     }
241     //////////////////////////////////////////////////////////////////
242
public boolean isScript() {
243         try {
244             Context.enter();
245             return (m_object instanceof NativeScript);
246         } finally {
247             Context.exit();
248         }
249     }
250     //////////////////////////////////////////////////////////////////
251
public boolean isWrapper() {
252         try {
253             Context.enter();
254             return (m_object instanceof Wrapper);
255         } finally {
256             Context.exit();
257         }
258     }
259     //////////////////////////////////////////////////////////////////
260
public void put(int index, Object JavaDoc value) {
261
262         JsObjectStub stub;
263         try {
264             
265             Context.enter();
266             
267             if (value instanceof JsObject) {
268                 stub = (JsObjectStub)value;
269                 value = stub.m_object;
270             }
271             m_object.put(index,m_object,value);
272         } finally {
273             Context.exit();
274         }
275     }
276     //////////////////////////////////////////////////////////////////
277
public void put(String JavaDoc name, Object JavaDoc value) {
278         JsObjectStub stub;
279         try {
280             
281             Context.enter();
282             
283             if (value instanceof JsObject) {
284                 stub = (JsObjectStub)value;
285                 value = stub.m_object;
286             }
287             m_object.put(name,m_object,value);
288         } finally {
289             Context.exit();
290         }
291     }
292     //////////////////////////////////////////////////////////////////
293
public void setPrototype(JsObject prototype) {
294         JsObjectStub stub;
295         Scriptable prot;
296         try {
297             Context.enter();
298             stub = (JsObjectStub)prototype;
299             prot = stub.m_object;
300             m_object.setPrototype(prot);
301         } finally {
302             Context.exit();
303         }
304     }
305     //////////////////////////////////////////////////////////////////
306
public void setScope(JsObject jsobj) {
307         JsObjectStub stub;
308         Scriptable scope;
309         try {
310             Context.enter();
311             stub = (JsObjectStub)jsobj;
312             scope = stub.m_object;
313             m_object.setParentScope(scope);
314         } finally {
315             Context.exit();
316         }
317     }
318     //////////////////////////////////////////////////////////////////
319
public Object JavaDoc unwrap() {
320         try {
321             Context.enter();
322             if (m_object instanceof Wrapper)
323                 return ((Wrapper) m_object).unwrap();
324             else
325                 return null;
326         } finally {
327             Context.exit();
328         }
329     }
330     //////////////////////////////////////////////////////////////////
331
public boolean wrapsJavaObject() {
332         try {
333             Context.enter();
334             return false;
335         } finally {
336             Context.exit();
337         }
338     }
339     //////////////////////////////////////////////////////////////////
340
//////////////////////////////////////////////////////////////////
341
//////////////////////////////////////////////////////////////////
342
//////////////////////////////////////////////////////////////////
343
/*
344     public void deleteProperty(int index) {
345         try {
346             Context.enter();
347         } finally {
348             Context.exit();
349         }
350     }
351     public void deleteProperty(String name) {
352         try {
353             Context.enter();
354         } finally {
355             Context.exit();
356         }
357     }
358     public JsPrototype getBase(int index) throws RemoteException {
359         try {
360             Context.enter();
361             Scriptable m = m_object;
362             do {
363                 if (m.has(index, m)) {
364                     return (JsPrototype) m_rhinoDbg.marshallScriptable(m);
365                 }
366                 m = m.getPrototype();
367             } while (m != null);
368             / *
369             // CAN'T REMEMBER WHY I WAS LOOKUP THE PARENT SCOPES...
370             // FOR FINDING THE BASE IT DOES NOT SEEM APPROPRIATE.
371             //
372             Context.enter();
373             Scriptable obj = m_object;
374             Object prop;
375             while (obj != null) {
376                 Scriptable m = obj;
377                 do {
378                     // if (m.get(id, obj) != Scriptable.NOT_FOUND)
379                     if (m.has(index, obj)) {
380                         return (JsPrototype) m_rhinoDbg.marshallScriptable(m);
381                     }
382                     m = m.getPrototype();
383                 } while (m != null);
384                 obj = obj.getParentScope();
385             }
386             * /
387             return null;
388         } finally {
389             Context.exit();
390         }
391     }
392     public JsPrototype getBase(String id) throws RemoteException {
393         try {
394             Context.enter();
395             Scriptable m = m_object;
396             do {
397                 if (m.has(id, m)) {
398                     return (JsPrototype) m_rhinoDbg.marshallScriptable(m);
399                 }
400                 m = m.getPrototype();
401             } while (m != null);
402             
403             // CAN'T REMEMBER WHY I WAS LOOKUP THE PARENT SCOPES...
404             // FOR FINDING THE BASE IT DOES NOT SEEM APPROPRIATE.
405             //
406             / *
407             Context.enter();
408             Scriptable obj = m_object;
409             Object prop;
410             while (obj != null) {
411                 Scriptable m = obj;
412                 do {
413                     // if (m.get(id, obj) != Scriptable.NOT_FOUND)
414                     if (m.has(id, obj)) {
415                         return (JsPrototype) m_rhinoDbg.marshallScriptable(m);
416                     }
417                     m = m.getPrototype();
418                 } while (m != null);
419                 obj = obj.getParentScope();
420             }
421             * /
422             return null;
423         } finally {
424             Context.exit();
425         }
426     }
427     public Object getProperty(int index) throws RemoteException {
428         try {
429             Context.enter();
430             JsPrototype prot = getBase(index);
431             if (prot != null) {
432                 return prot.get(index);
433             }
434             return null;
435         } finally {
436             Context.exit();
437         }
438     }
439     public Object getProperty(String name) throws RemoteException {
440         try {
441             Context.enter();
442             JsPrototype prot = getBase(name);
443             if (prot != null) {
444                 return prot.get(name);
445             }
446             return null;
447         } finally {
448             Context.exit();
449         }
450     }
451     public Object[] getPropertyIds() {
452         try {
453             Context.enter();
454             return null;
455         } finally {
456             Context.exit();
457         }
458     }
459     public void putProperty(int index, Object value) {
460         try {
461             Context.enter();
462         } finally {
463             Context.exit();
464         }
465     }
466     public void putProperty(String name, Object value) {
467         try {
468             Context.enter();
469         } finally {
470             Context.exit();
471         }
472     }
473     */

474 }
475
Popular Tags