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#XMLSerializer} class.</p>
028  * <p>This class enables you to convert or serialize an XML {@link JsDocument} or {@link JsNode} 
029  * object to a string of unparsed XML mark-up. To use this class, instantiate an object 
030  * {@link JsClient#XMLSerializer}, 
031  * and then call its {@link #serializeToString(JsNode)} method:
032  * <pre>String s = Js.win().XMLSerializer.create().serializeToString(e);</pre>
033  * </p>
034  * <p>IE does not implement this class. Instead, it makes XML text available through the 
035  * {@link JsNode#xml} property of {@link JsNode} objects.</p>
036  *
037  * @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>
038  * @see JsNode#xml
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 JsXMLSerializer extends JsClient.XMLSerializer.Prototype
047 {
048     /**
049      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
050      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
051      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
052      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
053      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
054      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
055      * either circumstance, the field names must be exactly same as the member names, as 
056      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
057      * based on the field names.</p>
058      *
059      * @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>
060      * 
061      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
062      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
063      * of class objects.
064      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
065      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
066      * <pre>q.m</pre>
067      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
068      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
069      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
070      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
071      * <pre>m</pre>
072      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
073      * error on the access to <b>opaque</b> fields declared by this class under any other 
074      * circumstances.
075      */
076     public static class Member extends JsClient.XMLSerializer.Prototype.Member
077     {
078         /**
079          * <p>Internally constructs a member based on a qualifying member.</p>
080          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
081          * or <b>internal</b> classes or class members.</p>
082          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
083          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
084          * declared in the declaring class of this constructor itself or its subclasses. 
085          * Under this circumstance, the field names must be exactly same as the member 
086          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
087          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
088          * to their names appending to the name resolved from the specified qualifying 
089          * member with a dot in between.</p>
090          * @param q A qualifying member
091          * @param mid The ID of the member to construct
092          * @since 1.0
093          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
094          */
095         public Member(JsObject.Member q, Mid mid) {
096             super(q, mid);
097         }
098         /**
099          * <p>Internally constructs a member without a qualifying member.</p>
100          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
101          * or <b>internal</b> classes or class members.</p>
102          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
103          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
104          * declared in <b>opaque</b> types other than the declaring class of this constructor 
105          * itself and its subclasses. Under this circumstance, the field names must be
106          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
107          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
108          * @param mid The ID of the member to construct
109          * @since 1.0
110          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
111          */
112         public Member(Mid mid) {
113             super(mid);
114         }
115         @Override
116         /**
117          * <p>Evaluates the property, represented by the current member instance, of the
118          * argument object.</p>
119          * @param o The argument object
120          * @return The value of the current member based on the object argument.
121          * @since 1.0
122          * @javascript Re-compilers must convert the instance invocation of this method into
123          * the JavaScript expression: 
124          * <pre>o.m</pre>
125          * where <tt>m</tt> is the identifier name resolved from the current member
126          * instance of the invocation.
127          */
128         public JsXMLSerializer with(ObjectLike o) {
129             return new JsXMLSerializer(super.with(o));
130         }
131         /**
132          * <p>Evaluates a property, represented by the current member instance, of the
133          * JavaScript global object, that is, evaluates the member to a global identifier.</p>
134          * @return The value of the current member based on the JavaScript global object.
135          * @since 1.0
136          * @javascript Re-compilers must convert the instance invocation of this method into
137          * the JavaScript expression: 
138          * <pre>m</pre>
139          * where <tt>m</tt> is the identifier name resolved from the current member
140          * instance of the invocation.
141          */
142         public JsXMLSerializer with() {
143             return with(Js.win());
144         }
145     }
146 
147     /**
148      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
149      * with the wrapping constructor.</p>
150      * @param var The argument of an <b>opaque</b> object.
151      * @since 1.0
152      * @javascript Re-compilers must ignore the construction operation of this constructor,
153      * that is, replacing it with its only argument.
154      */
155     public JsXMLSerializer(JsObject var) {
156         super(var);
157     }
158 
159     @Override
160     /**
161      * <p>Returns the primitive value associated with the current instance, if there is one.
162      * This invocation simply returns the instance itself for the current instance is an 
163      * object and there is no primitive value for it.</p>
164      * @return The current object itself.
165      * @since 1.0
166      * @javascript Re-compilers must convert the instance invocation of this method directly
167      * into a JavaScript invocation on its current object instance without changing the 
168      * method name, but expanding variable arguments, if any, into comma-separated values. 
169      */
170     public JsXMLSerializer valueOf() {
171         return new JsXMLSerializer((JsObject)var().valueOf());
172     }
173     /**
174      * <p>Performs the actual serialization on the {@link JsDocument} object or 
175      * {@link JsElement} node.</p>
176      * @param node The XML node to be serialized. This may be a {@link JsDocument} 
177      * object or any {@link JsElement} node within the document.
178      * @return A string of XML mark-up that represents the serialized form of the 
179      * specified <tt>node</tt> and all its descendants.
180      * @since 1.0
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 String serializeToString(JsNode node) {
186         return call(serializeToString, node);
187     }
188 }