mobile/android/base/util/NativeJSObject.java

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:57fa3f56dda8
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 package org.mozilla.gecko.util;
7
8 import org.mozilla.gecko.mozglue.JNITarget;
9
10 /**
11 * NativeJSObject is a wrapper around the SpiderMonkey JSAPI to make it possible to
12 * access Javascript objects in Java.
13 */
14 @JNITarget
15 public class NativeJSObject
16 {
17 private final NativeJSContainer mContainer;
18 private final int mObjectIndex;
19
20 protected NativeJSObject() {
21 mContainer = (NativeJSContainer)this;
22 mObjectIndex = -1;
23 }
24
25 private NativeJSObject(NativeJSContainer container, int index) {
26 mContainer = container;
27 mObjectIndex = index;
28 }
29
30 /**
31 * Returns the value of a boolean property.
32 *
33 * @param name
34 * Property name
35 * @throws IllegalArgumentException
36 * If the property does not exist or if its type does not match the return type
37 * @throws NullPointerException
38 * If name is null or if this JS object has been disposed
39 * @throws IllegalThreadStateException
40 * If not called on the thread this object is attached to
41 * @throws UnsupportedOperationException
42 * If an internal JSAPI call failed
43 */
44 public native boolean getBoolean(String name);
45
46 /**
47 * Returns the value of a boolean property.
48 *
49 * @param name
50 * Property name
51 * @param fallback
52 * Value to return if property does not exist
53 * @throws IllegalArgumentException
54 * If the property exists and its type does not match the return type
55 * @throws NullPointerException
56 * If name is null or if this JS object has been disposed
57 * @throws IllegalThreadStateException
58 * If not called on the thread this object is attached to
59 * @throws UnsupportedOperationException
60 * If an internal JSAPI call failed
61 */
62 public native boolean optBoolean(String name, boolean fallback);
63
64 /**
65 * Returns the value of a double property.
66 *
67 * @param name
68 * Property name
69 * @throws IllegalArgumentException
70 * If the property does not exist or if its type does not match the return type
71 * @throws NullPointerException
72 * If name is null or if this JS object has been disposed
73 * @throws IllegalThreadStateException
74 * If not called on the thread this object is attached to
75 * @throws UnsupportedOperationException
76 * If an internal JSAPI call failed
77 */
78 public native double getDouble(String name);
79
80 /**
81 * Returns the value of a double property.
82 *
83 * @param name
84 * Property name
85 * @param fallback
86 * Value to return if property does not exist
87 * @throws IllegalArgumentException
88 * If the property exists and its type does not match the return type
89 * @throws NullPointerException
90 * If name is null or if this JS object has been disposed
91 * @throws IllegalThreadStateException
92 * If not called on the thread this object is attached to
93 * @throws UnsupportedOperationException
94 * If an internal JSAPI call failed
95 */
96 public native double optDouble(String name, double fallback);
97
98 /**
99 * Returns the value of an int property.
100 *
101 * @param name
102 * Property name
103 * @throws IllegalArgumentException
104 * If the property does not exist or if its type does not match the return type
105 * @throws NullPointerException
106 * If name is null or if this JS object has been disposed
107 * @throws IllegalThreadStateException
108 * If not called on the thread this object is attached to
109 * @throws UnsupportedOperationException
110 * If an internal JSAPI call failed
111 */
112 public native int getInt(String name);
113
114 /**
115 * Returns the value of an int property.
116 *
117 * @param name
118 * Property name
119 * @param fallback
120 * Value to return if property does not exist
121 * @throws IllegalArgumentException
122 * If the property exists and its type does not match the return type
123 * @throws NullPointerException
124 * If name is null or if this JS object has been disposed
125 * @throws IllegalThreadStateException
126 * If not called on the thread this object is attached to
127 * @throws UnsupportedOperationException
128 * If an internal JSAPI call failed
129 */
130 public native int optInt(String name, int fallback);
131
132 /**
133 * Returns the value of an object property.
134 *
135 * @param name
136 * Property name
137 * @throws IllegalArgumentException
138 * If the property does not exist or if its type does not match the return type
139 * @throws NullPointerException
140 * If name is null or if this JS object has been disposed
141 * @throws IllegalThreadStateException
142 * If not called on the thread this object is attached to
143 * @throws UnsupportedOperationException
144 * If an internal JSAPI call failed
145 */
146 public native NativeJSObject getObject(String name);
147
148 /**
149 * Returns the value of an object property.
150 *
151 * @param name
152 * Property name
153 * @param fallback
154 * Value to return if property does not exist
155 * @throws IllegalArgumentException
156 * If the property exists and its type does not match the return type
157 * @throws NullPointerException
158 * If name is null or if this JS object has been disposed
159 * @throws IllegalThreadStateException
160 * If not called on the thread this object is attached to
161 * @throws UnsupportedOperationException
162 * If an internal JSAPI call failed
163 */
164 public native NativeJSObject optObject(String name, NativeJSObject fallback);
165
166 /**
167 * Returns the value of a string property.
168 *
169 * @param name
170 * Property name
171 * @throws IllegalArgumentException
172 * If the property does not exist or if its type does not match the return type
173 * @throws NullPointerException
174 * If name is null or if this JS object has been disposed
175 * @throws IllegalThreadStateException
176 * If not called on the thread this object is attached to
177 * @throws UnsupportedOperationException
178 * If an internal JSAPI call failed
179 */
180 public native String getString(String name);
181
182 /**
183 * Returns the value of a string property.
184 *
185 * @param name
186 * Property name
187 * @param fallback
188 * Value to return if property does not exist
189 * @throws IllegalArgumentException
190 * If the property exists and its type does not match the return type
191 * @throws NullPointerException
192 * If name is null or if this JS object has been disposed
193 * @throws IllegalThreadStateException
194 * If not called on the thread this object is attached to
195 * @throws UnsupportedOperationException
196 * If an internal JSAPI call failed
197 */
198 public native String optString(String name, String fallback);
199
200 /**
201 * Returns whether a property exists in this object
202 *
203 * @param name
204 * Property name
205 * @throws NullPointerException
206 * If name is null or if this JS object has been disposed
207 * @throws IllegalThreadStateException
208 * If not called on the thread this object is attached to
209 * @throws UnsupportedOperationException
210 * If an internal JSAPI call failed
211 */
212 public native boolean has(String name);
213
214 /**
215 * Returns the JSON representation of this object.
216 *
217 * @throws NullPointerException
218 * If this JS object has been disposed
219 * @throws IllegalThreadStateException
220 * If not called on the thread this object is attached to
221 * @throws UnsupportedOperationException
222 * If an internal JSAPI call failed
223 */
224 @Override
225 public native String toString();
226 }

mercurial