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#MimeType} class.</p>
028  * <p>An object of {@link JsMimeType} represents a MIME type (i.e., a data format) 
029  * supported by a web browser. The format may be supported directly by the browser, or 
030  * through an external helper application or a plug-in for embedded data. {@link JsMimeType} 
031  * objects are members of the {@link JsNavigator#mimeTypes} array of the {@link JsNavigator} 
032  * object. The array may be indexed numerically or with the name of the desired MIME type 
033  * which is the value of the {@link #type} property. In IE, the array is always empty, 
034  * and there is no equivalent of this functionality.</p>
035  *
036  * @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>
037  * @see JsNavigator
038  * @see JsPlugin
039  *
040  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be
041  * generated into the target codes. Re-compilers must exit with error on the operations of
042  * accessing that kind of class objects.
043  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
044  * and <tt>instanceof</tt> to it always <tt>true</tt>.
045  */
046 public class JsMimeType extends JsClient.MimeType.Prototype
047 {
048     /**
049      * <p>An <b>internal</b> class containing membership data for its enclosing
050      * opaque class.</p>
051      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or
052      * class members.</p>
053      *
054      * @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>
055      * 
056      * @javascript Re-compilers must report error on resolving an <b>internal</b> class.
057      */
058     protected static abstract class Members extends JsClient.MimeType.Prototype.Members
059     {
060         /**
061          * <p>An <b>internal</b> static field defining a member ID of the field name and
062          * used internally to define a member of the same name.</p>
063          * @since 1.0
064          * @see JsMimeType#description
065          * @see JsMimeType.Member#description
066          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
067          */
068         public final static Mid description   = id("description"  );
069         /**
070          * <p>An <b>internal</b> static field defining a member ID of the field name and
071          * used internally to define a member of the same name.</p>
072          * @since 1.0
073          * @see JsMimeType#enabledPlugin
074          * @see JsMimeType.Member#enabledPlugin
075          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
076          */
077         public final static Mid enabledPlugin = id("enabledPlugin");
078         /**
079          * <p>An <b>internal</b> static field defining a member ID of the field name and
080          * used internally to define a member of the same name.</p>
081          * @since 1.0
082          * @see JsMimeType#suffixes
083          * @see JsMimeType.Member#suffixes
084          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
085          */
086         public final static Mid suffixes      = id("suffixes"     );
087         /**
088          * <p>An <b>internal</b> static field defining a member ID of the field name and
089          * used internally to define a member of the same name.</p>
090          * @since 1.0
091          * @see JsMimeType#type
092          * @see JsMimeType.Member#type
093          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
094          */
095         public final static Mid type          = id("type"         );
096     }
097     /**
098      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
099      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
100      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
101      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
102      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
103      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
104      * either circumstance, the field names must be exactly same as the member names, as 
105      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
106      * based on the field names.</p>
107      *
108      * @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>
109      * 
110      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
111      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
112      * of class objects.
113      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
114      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
115      * <pre>q.m</pre>
116      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
117      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
118      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
119      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
120      * <pre>m</pre>
121      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
122      * error on the access to <b>opaque</b> fields declared by this class under any other 
123      * circumstances.
124      */
125     public static class Member extends JsClient.MimeType.Prototype.Member
126     {
127         /**
128          * <p>Internally constructs a member based on a qualifying member.</p>
129          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
130          * or <b>internal</b> classes or class members.</p>
131          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
132          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
133          * declared in the declaring class of this constructor itself or its subclasses. 
134          * Under this circumstance, the field names must be exactly same as the member 
135          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
136          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
137          * to their names appending to the name resolved from the specified qualifying 
138          * member with a dot in between.</p>
139          * @param q A qualifying member
140          * @param mid The ID of the member to construct
141          * @since 1.0
142          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
143          */
144         public Member(JsObject.Member q, Mid mid) {
145             super(q, mid);
146         }
147         /**
148          * <p>Internally constructs a member without a qualifying member.</p>
149          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
150          * or <b>internal</b> classes or class members.</p>
151          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
152          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
153          * declared in <b>opaque</b> types other than the declaring class of this constructor 
154          * itself and its subclasses. Under this circumstance, the field names must be
155          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
156          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
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(Mid mid) {
162             super(mid);
163         }
164         @Override
165         /**
166          * <p>Evaluates the property, represented by the current member instance, of the
167          * argument object.</p>
168          * @param o The argument object
169          * @return The value of the current member based on the object argument.
170          * @since 1.0
171          * @javascript Re-compilers must convert the instance invocation of this method into
172          * the JavaScript expression: 
173          * <pre>o.m</pre>
174          * where <tt>m</tt> is the identifier name resolved from the current member
175          * instance of the invocation.
176          */
177         public JsMimeType with(ObjectLike o) {
178             return new JsMimeType(super.with(o));
179         }
180 
181         /**
182          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
183          * name of this field, qualified by the current member instance of the field, and 
184          * to access the property of the name on an object.</p>
185          * <p>The property, identified by this member, of a {@link JsMimeType} object 
186          * refers to a read-only string that provides a human-readable description 
187          * (in English) of the data type described by the MIME Type.</p> 
188          * @since 1.0
189          * @see JsMimeType#description
190          * @javascript Re-compilers must resolve the member of this instance field to the
191          * identifier of the field name appending to the identifier resolved from its 
192          * qualifying member with a dot in between.
193          */
194         public final Value.String.Member description = new Value.String.Member(this, Members.description  );
195         /**
196          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
197          * name of this field, qualified by the current member instance of the field, and 
198          * to access the property of the name on an object.</p>
199          * <p>The property, identified by this member, of a {@link JsMimeType} object is 
200          * a read-only reference to {@link JsPlugin} object that represents the installed 
201          * and enabled plug-in that handles the specified MIME type. If the MIME type is 
202          * not handled by any plug-ins (for example, if it's handled directly by the 
203          * browser), the value of this property is <tt>null</tt>. The property is also 
204          * <tt>null</tt> when a plug-in exists but has been disabled.</p> 
205          * @since 1.0
206          * @see JsMimeType#enabledPlugin
207          * @javascript Re-compilers must resolve the member of this instance field to the
208          * identifier of the field name appending to the identifier resolved from its 
209          * qualifying member with a dot in between.
210          */
211         public final JsPlugin.Member enabledPlugin = new JsPlugin.Member(this, Members.enabledPlugin);
212         /**
213          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
214          * name of this field, qualified by the current member instance of the field, and 
215          * to access the property of the name on an object.</p>
216          * <p>The property, identified by this member, of a {@link JsMimeType} object 
217          * refers to a read-only string that contains a comma-separated list of filename 
218          * suffixes (not including the "." character) that are commonly used with files 
219          * of the specified MIME type. For example, the suffixes for the "text/html" 
220          * MIME type are "html, htm".</p> 
221          * @since 1.0
222          * @see JsMimeType#suffixes
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 suffixes    = new Value.String.Member(this, Members.suffixes     );
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 JsMimeType} object 
233          * refers to a read-only string that specifies the name of the MIME type. This 
234          * is a unique string such as "text/html" or "image/jpeg" that distinguishes 
235          * the MIME type from all others. It describes the general type of data and the 
236          * data format used. The value of the property can also be used as an index to 
237          * access the elements of the {@link JsNavigator#mimeTypes} array.</p> 
238          * @since 1.0
239          * @see JsMimeType#type
240          * @javascript Re-compilers must resolve the member of this instance field to the
241          * identifier of the field name appending to the identifier resolved from its 
242          * qualifying member with a dot in between.
243          */
244         public final Value.String.Member type        = new Value.String.Member(this, Members.type         );
245     }
246 
247     /**
248      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
249      * with the wrapping constructor.</p>
250      * @param var The argument of an <b>opaque</b> object.
251      * @since 1.0
252      * @javascript Re-compilers must ignore the construction operation of this constructor,
253      * that is, replacing it with its only argument.
254      */
255     public JsMimeType(JsObject var) {
256         super(var);
257     }
258 
259     /**
260      * <p>An <b>opaque</b> static field defining a member that is named by the field name
261      * without a qualifying member and to access the property of the name on an object.</p>
262      * <p>The property, identified by this member, of a {@link JsMimeType} object 
263      * refers to a read-only string that provides a human-readable description 
264      * (in English) of the data type described by the MIME Type.</p> 
265      * @since 1.0
266      * @see JsMimeType.Member#description
267      * @javascript Re-compilers must resolve the member of this static field to the
268      * identifier of the field name.
269      */
270     public static final Value.String.Member description   = new Value.String.Member(Members.description  );
271     /**
272      * <p>An <b>opaque</b> static field defining a member that is named by the field name
273      * without a qualifying member and to access the property of the name on an object.</p>
274      * <p>The property, identified by this member, of a {@link JsMimeType} object is 
275      * a read-only reference to {@link JsPlugin} object that represents the installed 
276      * and enabled plug-in that handles the specified MIME type. If the MIME type is 
277      * not handled by any plug-ins (for example, if it's handled directly by the 
278      * browser), the value of this property is <tt>null</tt>. The property is also 
279      * <tt>null</tt> when a plug-in exists but has been disabled.</p> 
280      * @since 1.0
281      * @see JsMimeType.Member#enabledPlugin
282      * @javascript Re-compilers must resolve the member of this static field to the
283      * identifier of the field name.
284      */
285     public static final JsPlugin.Member enabledPlugin = new JsPlugin.Member(Members.enabledPlugin);
286     /**
287      * <p>An <b>opaque</b> static field defining a member that is named by the field name
288      * without a qualifying member and to access the property of the name on an object.</p>
289      * <p>The property, identified by this member, of a {@link JsMimeType} object 
290      * refers to a read-only string that contains a comma-separated list of filename 
291      * suffixes (not including the "." character) that are commonly used with files 
292      * of the specified MIME type. For example, the suffixes for the "text/html" 
293      * MIME type are "html, htm".</p> 
294      * @since 1.0
295      * @see JsMimeType.Member#suffixes
296      * @javascript Re-compilers must resolve the member of this static field to the
297      * identifier of the field name.
298      */
299     public static final Value.String.Member suffixes      = new Value.String.Member(Members.suffixes     );
300     /**
301      * <p>An <b>opaque</b> static field defining a member that is named by the field name
302      * without a qualifying member and to access the property of the name on an object.</p>
303      * <p>The property, identified by this member, of a {@link JsMimeType} object 
304      * refers to a read-only string that specifies the name of the MIME type. This 
305      * is a unique string such as "text/html" or "image/jpeg" that distinguishes 
306      * the MIME type from all others. It describes the general type of data and the 
307      * data format used. The value of the property can also be used as an index to 
308      * access the elements of the {@link JsNavigator#mimeTypes} array.</p> 
309      * @since 1.0
310      * @see JsMimeType.Member#type
311      * @javascript Re-compilers must resolve the member of this static field to the
312      * identifier of the field name.
313      */
314     public static final Value.String.Member type          = new Value.String.Member(Members.type         );
315 
316     @Override
317     /**
318      * <p>Returns the primitive value associated with the current instance, if there is one.
319      * This invocation simply returns the instance itself for the current instance is an 
320      * object and there is no primitive value for it.</p>
321      * @return The current object itself.
322      * @since 1.0
323      * @javascript Re-compilers must convert the instance invocation of this method directly
324      * into a JavaScript invocation on its current object instance without changing the 
325      * method name, but expanding variable arguments, if any, into comma-separated values. 
326      */
327     public JsMimeType valueOf() {
328         return new JsMimeType((JsObject)var().valueOf());
329     }
330 }