001 
002 /*
003  *  JScripter Standard 1.0 - To Script In Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package js;
021 
022 import js.Var.Mid;
023 import js.core.JsObject;
024 
025 /**
026  * <p>An <b>opaque</b> interface resembling JavaScript objects.</p>
027  * <p>This interface must be implemented in JS Simulation Libraries.</p>
028  *
029  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
030  * @see Initializer#var()
031  * @see Js#object()
032  * @see Js#object(Object)
033  * @see js.core.JsObject#JsObject()
034  * @see js.core.JsGlobal.Object#create()
035  * 
036  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be 
037  * generated into the target codes. Re-compilers must exit with error on the operations of 
038  * accessing that kind of class objects.
039  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored 
040  * and <tt>instanceof</tt> to it always <tt>true</tt>.
041  */
042 
043 public interface ObjectLike
044 {
045     /**
046      * <p>Deletes a property of the current object instance by its ID.</p>
047      * @param id The ID of the property to delete.
048      * @return <tt>true</tt> if the deletion is successful, <tt>false</tt> otherwise.
049      * @see #delete(String)
050      * @see #delete(js.Var.Member)
051      * @see #delete(js.Var.Mid)
052      * @since 1.0
053      * @javascript Re-compilers must convert the interface invocation of this method into the 
054      * JavaScript expression: 
055      * <pre>delete o.id</pre>
056      * where <tt>o</tt> is the current object instance of the invocation and <tt>id</tt> 
057      * must be resolved to a property identifier at re-compile time.
058      */
059     public boolean delete(Id<?> id);
060     /**
061      * <p>Deletes a property of the current object instance by its member ID.</p>
062      * @param mid Member ID of the property to delete.
063      * @return <tt>true</tt> if the deletion is successful, <tt>false</tt> otherwise.
064      * @see #delete(Id)
065      * @see #delete(String)
066      * @see #delete(js.Var.Member)
067      * @since 1.0
068      * @javascript Re-compilers must convert the interface invocation of this method into the 
069      * JavaScript expression: 
070      * <pre>delete o.mid</pre>
071      * where <tt>o</tt> is the current object instance of the invocation and <tt>mid</tt> 
072      * must be resolved to the property identifier at re-compile time.
073      */
074     public boolean delete(Mid mid);
075     /**
076      * <p>Deletes a property of the current object instance by its opaque member.</p>
077      * @param m The opaque member of the property to delete.
078      * @return <tt>true</tt> if the deletion is successful, <tt>false</tt> otherwise.
079      * @see #delete(Id)
080      * @see #delete(js.Var.Mid)
081      * @see #delete(String)
082      * @since 1.0
083      * @javascript Re-compilers must convert the interface invocation of this method into the 
084      * JavaScript expression: 
085      * <pre>delete o.m</pre>
086      * where <tt>o</tt> is the current object instance of the invocation and <tt>m</tt> 
087      * must be resolved to the property identifier at re-compile time.
088      */
089     public boolean delete(Var.Member<?> m);
090     /**
091      * <p>Deletes a property of the current object instance by its name.</p>
092      * @param name The name of the property to delete.
093      * @return <tt>true</tt> if the deletion is successful, <tt>false</tt> otherwise.
094      * @see #delete(Id)
095      * @see #delete(js.Var.Mid)
096      * @see #delete(js.Var.Member)
097      * @since 1.0
098      * @javascript Re-compilers must convert the interface invocation of this method into the 
099      * JavaScript expression: 
100      * <pre>delete o[name]</pre>
101      * where <tt>o</tt> is the current object instance of the invocation.
102      */
103     public boolean delete(String name);
104     /**
105      * <p>Gets a property of the current object instance by its ID.</p>
106      * @param id The ID of the property to get.
107      * @return The property of the current object instance specified by its index.
108      * @see #var(js.Var.Mid)
109      * @see #var(js.Var.Member)
110      * @see #var(String)
111      * @since 1.0
112      * @javascript Re-compilers must convert the interface invocation of this method into the 
113      * JavaScript expression: 
114      * <pre>o.id</pre>
115      * where <tt>o</tt> is the current object instance of the invocation and <tt>id</tt> 
116      * must be resolved to a property identifier at re-compile time.
117      */
118     public <T> T var(Id<T> id);
119     /**
120      * <p>Gets a property of the current object instance by its opaque member.</p>
121      * @param m The opaque member of the property to get.
122      * @return The property of the current object instance specified by its opaque member.
123      * @see #var(Id)
124      * @see #var(js.Var.Mid)
125      * @see #var(String)
126      * @since 1.0
127      * @javascript Re-compilers must convert the interface invocation of this method into the 
128      * JavaScript expression: 
129      * <pre>o.m</pre>
130      * where <tt>o</tt> is the current object instance of the invocation and <tt>m</tt> 
131      * must be resolved to the property identifier at re-compile time.
132      */
133     public <T> T var(Var.Member<T> m);
134     /**
135      * <p>Gets a property of the current object instance by its name.</p>
136      * @param name The name of the property to get.
137      * @return The property of the current object instance specified by its name.
138      * @see #var(Id)
139      * @see #var(js.Var.Mid)
140      * @see #var(js.Var.Member)
141      * @since 1.0
142      * @javascript Re-compilers must convert the interface invocation of this method into the 
143      * JavaScript expression: 
144      * <pre>o[name]</pre>
145      * where <tt>o</tt> is the current object instance of the invocation.
146      */
147     public Object var(String name);
148     /**
149      * <p>Gets a property of the current object instance by its member ID.</p>
150      * @param mid The member ID of the property to get
151      * @return The property of the current object instance specified by its member ID.
152      * @see #var(Id)
153      * @see #var(js.Var.Member)
154      * @see #var(String)
155      * @since 1.0
156      * @javascript Re-compilers must convert the interface invocation of this method into the 
157      * JavaScript expression: 
158      * <pre>o.mid</pre>
159      * where <tt>o</tt> is the current object instance of the invocation and <tt>mid</tt> 
160      * must be resolved to the property identifier at re-compile time.
161      */
162     public Object var(Var.Mid mid);
163     /**
164      * <p>Sets a value to the property of the current object instance by its ID.</p>
165      * @param id The ID of the property to set the <tt>value</tt>.
166      * @return The property of the current object instance specified by its index.
167      * @param value The new value to be set.
168      * @see #var(js.Var.Mid, Object)
169      * @see #var(js.Var.Member, Object)
170      * @see #var(String, Object)
171      * @since 1.0
172      * @javascript Re-compilers must convert the interface invocation of this method into the 
173      * JavaScript expression: 
174      * <pre>o.id = value</pre>
175      * where <tt>o</tt> is the current object instance of the invocation and <tt>id</tt> 
176      * must be resolved to a property identifier at re-compile time.
177      */
178     public <T> T var(Id<T> id, T value);
179     /**
180      * <p>Sets a value to the property of the current object instance by its opaque member.</p>
181      * @param m The opaque member of the property to set the <tt>value</tt>.
182      * @param value The new value to be set.
183      * @return The property of the current object instance specified by its opaque member.
184      * @see #var(Id, Object)
185      * @see #var(js.Var.Mid, Object)
186      * @see #var(String, Object)
187      * @since 1.0
188      * @javascript Re-compilers must convert the interface invocation of this method into the 
189      * JavaScript expression: 
190      * <pre>o.m = value</pre>
191      * where <tt>o</tt> is the current object instance of the invocation and <tt>m</tt> 
192      * must be resolved to the property identifier at re-compile time.
193      */
194     public <T> T var(Var.Member<T> m, T value);
195     /**
196      * <p>Sets a value to the property of the current object instance by its name.</p>
197      * @param name The name of the property to set the <tt>value</tt>.
198      * @param value The new value to be set.
199      * @return The property of the current object instance specified by its name.
200      * @see #var(Id, Object)
201      * @see #var(js.Var.Mid, Object)
202      * @see #var(js.Var.Member, Object)
203      * @since 1.0
204      * @javascript Re-compilers must convert the interface invocation of this method into the 
205      * JavaScript expression: 
206      * <pre>o[name] = value</pre>
207      * where <tt>o</tt> is the current object instance of the invocation.
208      */
209     public <T> T var(String name, T value);
210     /**
211      * <p>Sets a value to the property of the current object instance by its member ID.</p>
212      * @param mid The member ID of the property to set the <tt>value</tt>.
213      * @param value The new value to be set.
214      * @return The property of the current object instance specified by its member ID.
215      * @see #var(Id, Object)
216      * @see #var(js.Var.Member, Object)
217      * @see #var(String, Object)
218      * @since 1.0
219      * @javascript Re-compilers must convert the interface invocation of this method into the 
220      * JavaScript expression: 
221      * <pre>o.mid = value</pre>
222      * where <tt>o</tt> is the current object instance of the invocation and <tt>mid</tt> 
223      * must be resolved to the property identifier at re-compile time.
224      */
225     public <T> T var(Var.Mid mid, T value);
226     /**
227      * <p>Checks whether the current object instance has a locally defined (non-inherited) 
228      * property with a specified name.</p>
229      * <p>JavaScript objects may have properties of their own, and they may also inherit 
230      * properties from their prototype object. This method provides a way to distinguish 
231      * between inherited properties and non-inherited local properties</p>
232      * @param propname A string that contains the name of a property of the current 
233      * object instance.
234      * @return <tt>true</tt> if the current object instance has a non-inherited 
235      * property with the name specified by <tt>propname</tt>; <tt>false</tt> if 
236      * the object does not have a property with the specified name or if it inherits that 
237      * property from its prototype object.
238      * @since 1.0
239      * @javascript Re-compilers must convert the interface invocation of this method directly 
240      * into a JavaScript invocation on its current array instance without changing the 
241      * method name, but expanding variable arguments, if any, into comma-separated values. 
242      */
243     public Boolean hasOwnProperty(Object propname);
244     /**
245      * <p>Checks whether the current object instance is the prototype object of a 
246      * specified object.</p>
247      * <p>This method provides a way to determine if one Object object is the prototype 
248      * of another</p>
249      * <p>In JavaScript, Object objects inherit properties from their prototype object. 
250      * The prototype of an Object object is referred to by the prototype property of the 
251      * constructor function that creates and initializes the object.</p>
252      * <p>Not that, in JS Embed Simulation mode, this method always returns <tt>false</tt> 
253      * on a simulated object instance of {@link ObjectLike}, unless the instance is 
254      * converted to a JavaScript object by {@link ObjectLike#var()}.</p>
255      * @param other Any object.
256      * @return <tt>true</tt> if the current object instance is the prototype of 
257      * <tt>other</tt>; <tt>false</tt> if <tt>other</tt> is not an Object 
258      * object or if the current object instance is not the prototype of <tt>other</tt>.
259      * @see js.core.JsObject.Members#constructor
260      * @see js.core.JsFunction.Members#prototype
261      * @since 1.0
262      * @javascript Re-compilers must convert the interface invocation of this method directly 
263      * into a JavaScript invocation on its current array instance without changing the 
264      * method name, but expanding variable arguments, if any, into comma-separated values. 
265      */
266     public Boolean isPrototypeOf(Object other);
267     /**
268      * <p>Checks whether a named property exists and would be enumerable in JavaScript.</p>
269      * @param propname A string that contains the name of a property of the current 
270      * object instance.
271      * @return <tt>true</tt> if the current object instance has a non-inherited 
272      * property with the name specified by <tt>propname</tt> and if that property is 
273      * enumerable, which means that it would be enumerated by a for/in loop on the current 
274      * object instance in JavaScript.
275      * @since 1.0
276      * @javascript Re-compilers must convert the interface invocation of this method directly 
277      * into a JavaScript invocation on its current array instance without changing the 
278      * method name, but expanding variable arguments, if any, into comma-separated values. 
279      */
280     public Boolean propertyIsEnumerable(Object propname);
281     /**
282      * <p>Converts the current object instance to a string.</p>
283      * @return A string representing the current object instance.
284      * @since 1.0
285      * @javascript Re-compilers must convert the interface invocation of this method directly 
286      * into a JavaScript invocation on its current array instance without changing the 
287      * method name, but expanding variable arguments, if any, into comma-separated values. 
288      */
289     public String toString();
290     /**
291      * <p>Converts the current object instance to a string, localized as appropriate 
292      * for the current locale.</p>
293      * @return A string representing the current object instance, localized as 
294      * appropriate for the current locale.
295      * @since 1.0
296      * @javascript Re-compilers must convert the interface invocation of this method directly 
297      * into a JavaScript invocation on its current array instance without changing the 
298      * method name, but expanding variable arguments, if any, into comma-separated values. 
299      */
300     public String toLocaleString();
301     /**
302      * <p>Simply returns the object of the current instance.</p>
303      * <p>This method is useful for JS Simulation to implement opaque types.</p>
304      * <p>If the current instance is a Java simulated object and the method runs in JS 
305      * Embed Simulation mode, the invocation creates and returns a JavaScript Object object 
306      * as a runtime copy of the current instance.</p>
307      * @return The object of the current instance.
308      * @since 1.0
309      * @javascript Re-compilers must ignore the interface invocation of this method, that is, 
310      * replacing it with its current instance.
311      */
312     public JsObject var();
313 }