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.user;
021 
022 import js.*;
023 import js.core.*;
024 
025 /**
026  * <p>An <b>opaque</b> class representing JavaScript client-side objects of the global 
027  * {@link JsClient#Plugin} class.</p>
028  * <p>A plug-in is a software module that can be invoked by a browser to display 
029  * specialized types of embedded data within the browser window. Plug-ins are 
030  * represented by {@link JsPlugin} objects, and the {@link JsNavigator#plugins} property of 
031  * {@link JsWindow#navigator} is an array of 
032  * {@link JsPlugin} objects representing the installed plug-ins for the browser. IE does 
033  * not support {@link JsPlugin}, and the array is always empty on that browser.</p>
034  * <p>The {@link JsNavigator#plugins} array may be indexed numerically when you want to 
035  * loop through the complete list of installed plug-ins, looking for one that meets your 
036  * needs (for example, one that supports the MIME type of the data you want to embed in 
037  * your web page). This array can also be indexed by plug-in name, however. That is, if 
038  * you want to check whether a specific plug-in is installed in the user's browser. The 
039  * name used as an array index with this technique is the same name that appears as the 
040  * value of the {@link #name} property of the {@link JsPlugin} object.</p>
041  * <p>A {@link JsPlugin} object is somewhat unusual in that it has both regular object 
042  * properties and array elements. The properties of a {@link JsPlugin} object provide 
043  * various pieces of information about the plug-in, and its array elements are {@link JsMimeType} 
044  * objects that specify the embedded data formats that the plug-in supports. Don't 
045  * confuse the fact that {@link JsPlugin} objects are stored in an array of the {@link JsNavigator} 
046  * object with the fact that each {@link JsPlugin} object is itself an array of {@link JsMimeType} 
047  * objects.</p>
048  * <p>Finally, note that while the array elements of a {@link JsPlugin} object specify 
049  * the MIME types supported by that plug-in, you can also determine which plug-in 
050  * supports a given MIME type with the {@link JsMimeType#enabledPlugin} property of the 
051  * {@link JsMimeType} object.</p>
052  *
053  * @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>
054  * @see JsMimeType
055  * @see JsNavigator
056  *
057  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be
058  * generated into the target codes. Re-compilers must exit with error on the operations of
059  * accessing that kind of class objects.
060  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
061  * and <tt>instanceof</tt> to it always <tt>true</tt>.
062  */
063 public class JsPlugin extends JsClient.Plugin.Prototype implements ArrayObject<JsMimeType>
064 {
065     /**
066      * <p>An <b>internal</b> class containing membership data for its enclosing
067      * opaque class.</p>
068      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or
069      * class members.</p>
070      *
071      * @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>
072      * 
073      * @javascript Re-compilers must report error on resolving an <b>internal</b> class.
074      */
075     protected static abstract class Members extends JsClient.Plugin.Prototype.Members
076     {
077         /**
078          * <p>An <b>internal</b> static field defining a member ID of the field name and
079          * used internally to define a member of the same name.</p>
080          * @since 1.0
081          * @see JsPlugin#description
082          * @see JsPlugin.Member#description
083          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
084          */
085         public final static Mid description = id("description");
086         /**
087          * <p>An <b>internal</b> static field defining a member ID of the field name and
088          * used internally to define a member of the same name.</p>
089          * @since 1.0
090          * @see JsPlugin#filename
091          * @see JsPlugin.Member#filename
092          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
093          */
094         public final static Mid filename    = id("filename"   );
095         /**
096          * <p>An <b>internal</b> static field defining a member ID of the field name and
097          * used internally to define a member of the same name.</p>
098          * @since 1.0
099          * @see JsPlugin#length
100          * @see JsPlugin.Member#length
101          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
102          */
103         public final static Mid length      = id("length"     );
104         /**
105          * <p>An <b>internal</b> static field defining a member ID of the field name and
106          * used internally to define a member of the same name.</p>
107          * @since 1.0
108          * @see JsPlugin#name
109          * @see JsPlugin.Member#name
110          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
111          */
112         public final static Mid name        = id("name"       );
113     }
114     /**
115      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
116      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
117      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
118      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
119      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
120      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
121      * either circumstance, the field names must be exactly same as the member names, as 
122      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
123      * based on the field names.</p>
124      *
125      * @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>
126      * 
127      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
128      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
129      * of class objects.
130      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
131      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
132      * <pre>q.m</pre>
133      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
134      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
135      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
136      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
137      * <pre>m</pre>
138      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
139      * error on the access to <b>opaque</b> fields declared by this class under any other 
140      * circumstances.
141      */
142     public static class Member extends JsClient.Plugin.Prototype.Member
143     {
144         /**
145          * <p>Internally constructs a member based on a qualifying member.</p>
146          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
147          * or <b>internal</b> classes or class members.</p>
148          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
149          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
150          * declared in the declaring class of this constructor itself or its subclasses. 
151          * Under this circumstance, the field names must be exactly same as the member 
152          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
153          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
154          * to their names appending to the name resolved from the specified qualifying 
155          * member with a dot in between.</p>
156          * @param q A qualifying member
157          * @param mid The ID of the member to construct
158          * @since 1.0
159          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
160          */
161         public Member(JsObject.Member q, Mid mid) {
162             super(q, mid);
163         }
164         /**
165          * <p>Internally constructs a member without a qualifying member.</p>
166          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
167          * or <b>internal</b> classes or class members.</p>
168          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
169          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
170          * declared in <b>opaque</b> types other than the declaring class of this constructor 
171          * itself and its subclasses. Under this circumstance, the field names must be
172          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
173          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
174          * @param mid The ID of the member to construct
175          * @since 1.0
176          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
177          */
178         public Member(Mid mid) {
179             super(mid);
180         }
181         @Override
182         /**
183          * <p>Evaluates the property, represented by the current member instance, of the
184          * argument object.</p>
185          * @param o The argument object
186          * @return The value of the current member based on the object argument.
187          * @since 1.0
188          * @javascript Re-compilers must convert the instance invocation of this method into
189          * the JavaScript expression: 
190          * <pre>o.m</pre>
191          * where <tt>m</tt> is the identifier name resolved from the current member
192          * instance of the invocation.
193          */
194         public JsPlugin with(ObjectLike o) {
195             return new JsPlugin(super.with(o));
196         }
197 
198         /**
199          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
200          * name of this field, qualified by the current member instance of the field, and 
201          * to access the property of the name on an object.</p>
202          * <p>The property, identified by this member, of a {@link JsPlugin} object 
203          * refers to a read-only string that contains a human-readable description of 
204          * the specified plug-in. The text of this description is provided by the 
205          * creators of the plug-in and may contain vendor and version information as 
206          * well as a brief description of the plug-in's function.</p> 
207          * @since 1.0
208          * @javascript Re-compilers must resolve the member of this instance field to the
209          * identifier of the field name appending to the identifier resolved from its 
210          * qualifying member with a dot in between.
211          */
212         public final Value.String.Member description = new Value.String.Member(this, Members.description);
213         /**
214          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
215          * name of this field, qualified by the current member instance of the field, and 
216          * to access the property of the name on an object.</p>
217          * <p>The property, identified by this member, of a {@link JsPlugin} object 
218          * refers to a read-only string that specifies the name of the file on disk that 
219          * contains the plug-in program itself. This name may vary from platform to 
220          * platform. The {@link #name} property is more useful than this property 
221          * for identifying a plug-in.</p> 
222          * @since 1.0
223          * @javascript Re-compilers must resolve the member of this instance field to the
224          * identifier of the field name appending to the identifier resolved from its 
225          * qualifying member with a dot in between.
226          */
227         public final Value.String.Member filename    = new Value.String.Member(this, Members.filename   );
228         /**
229          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
230          * name of this field, qualified by the current member instance of the field, and 
231          * to access the property of the name on an object.</p>
232          * <p>The property, identified by this member, of a {@link JsPlugin} object
233          * specifies the number of elements in the array as with all arrays, because 
234          * a {@link JsPlugin} object is also an array of {@link JsMimeType} objects 
235          * that specify the data formats supported by the plug-in.</p> 
236          * @since 1.0
237          * @javascript Re-compilers must resolve the member of this instance field to the
238          * identifier of the field name appending to the identifier resolved from its 
239          * qualifying member with a dot in between.
240          */
241         public final Value.Number.Member length      = new Value.Number.Member(this, Members.length     );
242         /**
243          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
244          * name of this field, qualified by the current member instance of the field, and 
245          * to access the property of the name on an object.</p>
246          * <p>The property, identified by this member, of a {@link JsPlugin} object 
247          * refers to a read-only string that specifies the plug-in. Each plug-in should 
248          * have a name that uniquely identifies it. The name of a plug-in can be used 
249          * as an index into the {@link JsNavigator#plugins} array. You can use this fact 
250          * to determine easily whether a particular named plug-in is installed in the 
251          * current browser.</p> 
252          * @since 1.0
253          * @javascript Re-compilers must resolve the member of this instance field to the
254          * identifier of the field name appending to the identifier resolved from its 
255          * qualifying member with a dot in between.
256          */
257         public final Value.String.Member name        = new Value.String.Member(this, Members.name       );
258     }
259 
260     /**
261      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
262      * with the wrapping constructor.</p>
263      * @param var The argument of an <b>opaque</b> object.
264      * @since 1.0
265      * @javascript Re-compilers must ignore the construction operation of this constructor,
266      * that is, replacing it with its only argument.
267      */
268     public JsPlugin(JsObject var) {
269         super(var);
270     }
271 
272     /**
273      * <p>An <b>opaque</b> static field defining a member that is named by the field name
274      * without a qualifying member and to access the property of the name on an object.</p>
275      * <p>The property, identified by this member, of a {@link JsPlugin} object 
276      * refers to a read-only string that contains a human-readable description of 
277      * the specified plug-in. The text of this description is provided by the 
278      * creators of the plug-in and may contain vendor and version information as 
279      * well as a brief description of the plug-in's function.</p> 
280      * @since 1.0
281      * @javascript Re-compilers must resolve the member of this static field to the
282      * identifier of the field name.
283      */
284     public static final Value.String.Member description = new Value.String.Member(Members.description);
285     /**
286      * <p>An <b>opaque</b> static field defining a member that is named by the field name
287      * without a qualifying member and to access the property of the name on an object.</p>
288      * <p>The property, identified by this member, of a {@link JsPlugin} object 
289      * refers to a read-only string that specifies the name of the file on disk that 
290      * contains the plug-in program itself. This name may vary from platform to 
291      * platform. The {@link #name} property is more useful than this property 
292      * for identifying a plug-in.</p> 
293      * @since 1.0
294      * @javascript Re-compilers must resolve the member of this static field to the
295      * identifier of the field name.
296      */
297     public static final Value.String.Member filename    = new Value.String.Member(Members.filename   );
298     /**
299      * <p>An <b>opaque</b> static field defining a member that is named by the field name
300      * without a qualifying member and to access the property of the name on an object.</p>
301      * <p>The property, identified by this member, of a {@link JsPlugin} object
302      * specifies the number of elements in the array as with all arrays, because 
303      * a {@link JsPlugin} object is also an array of {@link JsMimeType} objects 
304      * that specify the data formats supported by the plug-in.</p> 
305      * @since 1.0
306      * @javascript Re-compilers must resolve the member of this static field to the
307      * identifier of the field name.
308      */
309     public static final Value.Number.Member length      = new Value.Number.Member(Members.length     );
310     /**
311      * <p>An <b>opaque</b> static field defining a member that is named by the field name
312      * without a qualifying member and to access the property of the name on an object.</p>
313      * <p>The property, identified by this member, of a {@link JsPlugin} object 
314      * refers to a read-only string that specifies the plug-in. Each plug-in should 
315      * have a name that uniquely identifies it. The name of a plug-in can be used 
316      * as an index into the {@link JsNavigator#plugins} array. You can use this fact 
317      * to determine easily whether a particular named plug-in is installed in the 
318      * current browser.</p> 
319      * @since 1.0
320      * @javascript Re-compilers must resolve the member of this static field to the
321      * identifier of the field name.
322      */
323     public static final Value.String.Member name        = new Value.String.Member(Members.name       );
324 
325     @Override
326     /**
327      * <p>Returns the primitive value associated with the current instance, if there is one.
328      * This invocation simply returns the instance itself for the current instance is an 
329      * object and there is no primitive value for it.</p>
330      * @return The current object itself.
331      * @since 1.0
332      * @javascript Re-compilers must convert the instance invocation of this method directly
333      * into a JavaScript invocation on its current object instance without changing the 
334      * method name, but expanding variable arguments, if any, into comma-separated values. 
335      */
336     public JsPlugin valueOf() {
337         return new JsPlugin((JsObject)var().valueOf());
338     }
339 
340     /**
341      * <p>Reads an element of the current array instance.</p>
342      * @param i Array index of the element
343      * @return value of the element
344      * @since 1.0
345      * @javascript Re-compilers must convert the instance invocation of this method into the 
346      * JavaScript expression: 
347      * <pre>a[i]</pre>
348      * where <tt>a</tt> is the current array instance of the invocation.
349      */
350     public JsMimeType get(int i) {
351         return new JsMimeType((JsObject)new JsArray(this).get(i));
352     }
353 
354     /**
355      * <p>Gets the size of the current array instance.</p>
356      * @return size of the array
357      * @see jsx.core.ArrayLikes#length(ArrayObject)
358      * @since 1.0
359      * @javascript Re-compilers must convert the instance invocation of this method into the 
360      * JavaScript expression: 
361      * <pre>a.length</pre>
362      * where <tt>a</tt> is the current array instance of the invocation.
363      */
364     public int length() {
365         return length.with(this).intValue();
366     }
367 }