| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 /* -*- Mode: Java; tab-width: 8; c-basic-offset: 4 -*- 2 3 This program is free software; you can redistribute it and/or 4 modify it under the terms of the GNU General Public License 5 as published by the Free Software Foundation; either version 2 6 of the License, or (at your option) any later version. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 16 17 /* more doc todo: 18 * threads 19 * gc 20 * 21 * 22 */ 23 24 package netscape.javascript; 25 26 import java.applet.Applet; 27 28 /** 29 * JSObject allows Java to manipulate objects that are 30 * defined in JavaScript. 31 * Values passed from Java to JavaScript are converted as 32 * follows:<ul> 33 * <li>JSObject is converted to the original JavaScript object 34 * <li>Any other Java object is converted to a JavaScript wrapper, 35 * which can be used to access methods and fields of the java object. 36 * Converting this wrapper to a string will call the toString method 37 * on the original object, converting to a number will call the 38 * doubleValue method if possible and fail otherwise. Converting 39 * to a boolean will try to call the booleanValue method in the 40 * same way. 41 * <li>Java arrays are wrapped with a JavaScript object that understands 42 * array.length and array[index] 43 * <li>A Java boolean is converted to a JavaScript boolean 44 * <li>Java byte, char, short, int, long, float, and double are converted 45 * to JavaScript numbers 46 * </ul> 47 * Values passed from JavaScript to Java are converted as follows:<ul> 48 * <li>objects which are wrappers around java objects are unwrapped 49 * <li>other objects are wrapped with a JSObject 50 * <li>strings, numbers and booleans are converted to String, Double, 51 * and Boolean objects respectively 52 * </ul> 53 * This means that all JavaScript values show up as some kind 54 * of java.lang.Object in Java. In order to make much use of them, 55 * you will have to cast them to the appropriate subclass of Object, 56 * e.g. <code>(String) window.getMember("name");</code> or 57 * <code>(JSObject) window.getMember("document");</code>. 58 */ 59 public final class JSObject { 60 /* the internal object data */ 61 private int internal; 62 private long long_internal; 63 64 /** 65 * initialize 66 */ 67 private static native void initClass(); 68 static { 69 // On MRJ, this property won't exist, because the library is preloaded. 70 String liveConnectLibrary = System.getProperty("netscape.jsj.dll", null); 71 if (liveConnectLibrary != null) { 72 System.loadLibrary(liveConnectLibrary); 73 initClass(); 74 } 75 } 76 77 /** 78 * it is illegal to construct a JSObject manually 79 */ 80 private JSObject(int jsobj_addr) { 81 internal = jsobj_addr; 82 } 83 84 private JSObject(long jsobj_addr) { 85 long_internal = jsobj_addr; 86 } 87 88 /** 89 * Retrieves a named member of a JavaScript object. 90 * Equivalent to "this.<i>name</i>" in JavaScript. 91 */ 92 public native Object getMember(String name); 93 94 /** 95 * Retrieves an indexed member of a JavaScript object. 96 * Equivalent to "this[<i>index</i>]" in JavaScript. 97 */ 98 // public Object getMember(int index) { return getSlot(index); } 99 public native Object getSlot(int index); 100 101 /** 102 * Sets a named member of a JavaScript object. 103 * Equivalent to "this.<i>name</i> = <i>value</i>" in JavaScript. 104 */ 105 public native void setMember(String name, Object value); 106 107 /** 108 * Sets an indexed member of a JavaScript object. 109 * Equivalent to "this[<i>index</i>] = <i>value</i>" in JavaScript. 110 */ 111 // public void setMember(int index, Object value) { 112 // setSlot(index, value); 113 // } 114 public native void setSlot(int index, Object value); 115 116 /** 117 * Removes a named member of a JavaScript object. 118 */ 119 public native void removeMember(String name); 120 121 /** 122 * Calls a JavaScript method. 123 * Equivalent to "this.<i>methodName</i>(<i>args</i>[0], <i>args</i>[1], ...)" in JavaScript. 124 */ 125 public native Object call(String methodName, Object args[]); 126 127 /** 128 * Evaluates a JavaScript expression. The expression is a string 129 * of JavaScript source code which will be evaluated in the context 130 * given by "this". 131 */ 132 public native Object eval(String s); 133 134 /** 135 * Converts a JSObject to a String. 136 */ 137 public native String toString(); 138 139 // should use some sort of identifier rather than String 140 // is "property" the right word? 141 // native String[] listProperties(); 142 143 144 /** 145 * get a JSObject for the window containing the given applet 146 */ 147 public static native JSObject getWindow(Applet applet); 148 149 /** 150 * Finalization decrements the reference count on the corresponding 151 * JavaScript object. 152 */ 153 protected native void finalize(); 154 155 /** 156 * Override java.lang.Object.equals() because identity is not preserved 157 * with instances of JSObject. 158 */ 159 public native boolean equals(Object obj); 160 } 161 162
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |