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#DOMImplementation} class.</p>
028  * <p>This class is a place-holder for methods that are not specific to any particular 
029  * {@link JsDocument} object but rather are "global" to an implementation of the DOM.</p>
030  * <p>A reference to the {@link JsDOMImplementation} object can be obtained through the 
031  * {@link JsDocument#implementation} property of any {@link JsDocument} object.</p>
032  *
033  * @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>
034  *
035  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be
036  * generated into the target codes. Re-compilers must exit with error on the operations of
037  * accessing that kind of class objects.
038  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
039  * and <tt>instanceof</tt> to it always <tt>true</tt>.
040  */
041 public class JsDOMImplementation extends JsClient.DOMImplementation.Prototype
042 {
043     /**
044      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
045      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
046      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
047      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
048      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
049      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
050      * either circumstance, the field names must be exactly same as the member names, as 
051      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
052      * based on the field names.</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 <b>Opaque</b> types can be resolved but no class objects for them can be created
057      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
058      * of class objects.
059      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
060      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
061      * <pre>q.m</pre>
062      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
063      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
064      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
065      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
066      * <pre>m</pre>
067      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
068      * error on the access to <b>opaque</b> fields declared by this class under any other 
069      * circumstances.
070      */
071     public static class Member extends JsClient.DOMImplementation.Prototype.Member
072     {
073         /**
074          * <p>Internally constructs a member based on a qualifying member.</p>
075          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
076          * or <b>internal</b> classes or class members.</p>
077          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
078          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
079          * declared in the declaring class of this constructor itself or its subclasses. 
080          * Under this circumstance, the field names must be exactly same as the member 
081          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
082          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
083          * to their names appending to the name resolved from the specified qualifying 
084          * member with a dot in between.</p>
085          * @param q A qualifying member
086          * @param mid The ID of the member to construct
087          * @since 1.0
088          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
089          */
090         public Member(JsObject.Member q, Mid mid) {
091             super(q, mid);
092         }
093         /**
094          * <p>Internally constructs a member without a qualifying member.</p>
095          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
096          * or <b>internal</b> classes or class members.</p>
097          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
098          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
099          * declared in <b>opaque</b> types other than the declaring class of this constructor 
100          * itself and its subclasses. Under this circumstance, the field names must be
101          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
102          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
103          * @param mid The ID of the member to construct
104          * @since 1.0
105          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
106          */
107         public Member(Mid mid) {
108             super(mid);
109         }
110         @Override
111         /**
112          * <p>Evaluates the property, represented by the current member instance, of the
113          * argument object.</p>
114          * @param o The argument object
115          * @return The value of the current member based on the object argument.
116          * @since 1.0
117          * @javascript Re-compilers must convert the instance invocation of this method into
118          * the JavaScript expression: 
119          * <pre>o.m</pre>
120          * where <tt>m</tt> is the identifier name resolved from the current member
121          * instance of the invocation.
122          */
123         public JsDOMImplementation with(ObjectLike o) {
124             return new JsDOMImplementation(super.with(o));
125         }
126     }
127 
128     /**
129      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
130      * with the wrapping constructor.</p>
131      * @param var The argument of an <b>opaque</b> object.
132      * @since 1.0
133      * @javascript Re-compilers must ignore the construction operation of this constructor,
134      * that is, replacing it with its only argument.
135      */
136     public JsDOMImplementation(JsObject var) {
137         super(var);
138     }
139 
140     @Override
141     /**
142      * <p>Returns the primitive value associated with the current instance, if there is one.
143      * This invocation simply returns the instance itself for the current instance is an 
144      * object and there is no primitive value for it.</p>
145      * @return The current object itself.
146      * @since 1.0
147      * @javascript Re-compilers must convert the instance invocation of this method directly
148      * into a JavaScript invocation on its current object instance without changing the 
149      * method name, but expanding variable arguments, if any, into comma-separated values. 
150      */
151     public JsDOMImplementation valueOf() {
152         return new JsDOMImplementation((JsObject)var().valueOf());
153     }
154     /**
155      * <p>creates a new XML {@link JsDocument} object and the specified root {@link JsDocument#documentElement} 
156      * object for that document.</p>
157      * <p>If the <tt>doctype</tt> argument is not <tt>null</tt>, the {@link JsNode#ownerDocument} 
158      * property of the {@link JsDocumentType} object is set to the newly created document.</p>
159      * <p>This method is used to create XML documents and may not be supported by HTML-only 
160      * implementations.</p>
161      * @param namespaceURI The unique identifier of the name space of the root element to be 
162      * created for the document, or null for no name space.
163      * @param qualifiedName The name of the root element to be created for this document. 
164      * If <tt>namespaceURI</tt> is not <tt>null</tt>, this name should include a name 
165      * space prefix and a colon.
166      * @param doctype The {@link JsDocumentType} object for the newly created {@link JsDocument} 
167      * node, or <tt>null</tt> if none is desired.
168      * @return A {@link JsDocument} object with its {@link JsDocument#documentElement} 
169      * property set to a root {@link JsElement} node of the specified type.
170      * @throws RuntimeException JavaScript throws a {@link JsDOMException} object with 
171      * the {@link JsDOMException#code} property of the value {@link JsDOMException#INVALID_CHARACTER_ERR} 
172      * if <tt>qualifiedName</tt> contains an illegal character, the value {@link JsDOMException#NAMESPACE_ERR} 
173      * if <tt>qualifiedName</tt> is malformed or there is a mismatch between <tt>qualifiedName</tt> 
174      * and <tt>namespaceURI</tt>, the value {@link JsDOMException#NOT_SUPPORTED_ERR} if 
175      * the current implementation does not support XML documents and has not implemented 
176      * this method, or the value {@link JsDOMException#WRONG_DOCUMENT_ERR} if <tt>doctype</tt> 
177      * is already in use for another document or was created by a different {@link JsDOMImplementation} 
178      * object. See {@link Js#err(Object)} for JS Simulation.
179      * @since 1.0
180      * @see #createDocumentType(String, String, String)
181      * @javascript Re-compilers must convert the instance invocation of this method directly
182      * into a JavaScript invocation on its current object instance without changing the 
183      * method name, but expanding variable arguments, if any, into comma-separated values. 
184      */
185     public final JsDocument createDocument(String namespaceURI, String qualifiedName, JsDocumentType doctype) {
186         return new JsDocument(call(createDocument, new Vars<Object>().add(namespaceURI).add(qualifiedName).add(doctype)));
187     }
188     /**
189      * <p>Creates a new {@link JsDocumentType} node.</p>
190      * <p>This method is useful only with XML documents. It specifies only an external 
191      * subset of the document type. As of Level 2, the DOM standard does not provide any 
192      * way to specify an internal subset, and the returned {@link JsDocumentType} does 
193      * not define any <tt>Entity</tt> or <tt>Notation</tt> nodes.</p>
194      * @param qualifiedName The name of the document type. If you are using XML name 
195      * spaces, this may be a qualified name that specifies a name space prefix and a 
196      * local name separated by a colon.
197      * @param publicId The public identifier of the document type, or <tt>null</tt>.
198      * @param systemId The system identifier of the document type, or <tt>null</tt>. 
199      * This argument typically specifies the local filename of a DTD file.
200      * @return A new {@link JsDocumentType} object with a {@link JsNode#ownerDocument} 
201      * property of <tt>null</tt>.
202      * @throws RuntimeException JavaScript throws a {@link JsDOMException} object with 
203      * the {@link JsDOMException#code} property of the value {@link JsDOMException#INVALID_CHARACTER_ERR} 
204      * if <tt>qualifiedName</tt> contains an illegal character, the value {@link JsDOMException#NAMESPACE_ERR} 
205      * if <tt>qualifiedName</tt> is malformed, or the value {@link JsDOMException#NOT_SUPPORTED_ERR} if 
206      * the current implementation does not support XML documents and has not implemented 
207      * this method. See {@link Js#err(Object)} for JS Simulation.
208      * @since 1.0
209      * @javascript Re-compilers must convert the instance invocation of this method directly
210      * into a JavaScript invocation on its current object instance without changing the 
211      * method name, but expanding variable arguments, if any, into comma-separated values. 
212      */
213     public final JsDocumentType createDocumentType(String qualifiedName, String publicId, String systemId) {
214         return new JsDocumentType(call(createDocumentType, new Vars<Object>().add(qualifiedName).add(publicId).add(systemId)));
215     }
216     /**
217      * <p>Checks whether the current implementation supports a specified version of a 
218      * named feature.</p>
219      * <p>The W3C DOM standard is modular, and implementations are not required to 
220      * implement all modules or features of the standard. This method tests whether a 
221      * DOM implementation supports a named module of the DOM specification.</p>
222      * @param feature The name of the feature for which support is being tested. 
223      * Feature names are case-insensitive. 
224      * The complete set of valid module names for the 
225      * DOM Level 2 standard that may be used as this argument are listed as follows:
226      * <ul>
227      * <li>Core: Node, Element, Document, Text, and the other fundamental interfaces 
228      * required by all DOM implementations are implemented. All conforming implementations 
229      * must support this module.</li>
230      * <li>HTML: HTMLElement, HTMLDocument, and the other HTML-specific interfaces are 
231      * implemented.</li>
232      * <li>XML: Entity, EntityReference, ProcessingInstruction, Notation, and the other 
233      * node types that are useful only with XML documents are implemented.</li>
234      * <li>StyleSheets: Simple interfaces describing generic style-sheets are implemented.</li>
235      * <li>CSS: Interfaces that are specific to CSS style-sheets are implemented.</li>
236      * <li>CSS2: The CSS2Properties interface is implemented.</li>
237      * <li>Events: The basic event-handling interfaces are implemented.</li>
238      * <li>UIEvents: The interfaces for user-interface events are implemented.</li>
239      * <li>MouseEvents: The interfaces for mouse events are implemented.</li>
240      * <li>HTMLEvents: The interfaces for HTML events are implemented.</li>
241      * <li>MutationEvents: The interfaces for document mutation events are implemented.</li>
242      * <li>Range: The interfaces for manipulating ranges of a document are implemented.</li>
243      * <li>Traversal: The interfaces for advanced document traversal are implemented.</li>
244      * <li>Views: The interfaces for document views are implemented.</li>
245      * </ul>
246      * @param version The feature version number for which support is being tested, or 
247      * <tt>null</tt> or the empty string "" if support for any version of the feature 
248      * is sufficient. In the Level 2 DOM specification, supported version numbers are 
249      * 1.0 and 2.0.
250      * @return <tt>true</tt> if the implementation completely supports the specified 
251      * version of the specified feature; <tt>false</tt> otherwise. If no version number 
252      * is specified, the method returns <tt>true</tt> if the implementation completely 
253      * supports any version of the specified feature.
254      * @since 1.0
255      * @see JsNode#isSupported(Object, Object)
256      * @javascript Re-compilers must convert the instance invocation of this method directly
257      * into a JavaScript invocation on its current object instance without changing the 
258      * method name, but expanding variable arguments, if any, into comma-separated values. 
259      */
260     public final Boolean hasFeature(String feature, String version) {
261         return call(hasFeature, new Vars<Object>().add(feature).add(version));
262     }
263 }