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#CDATASection} class.</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  *
031  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be
032  * generated into the target codes. Re-compilers must exit with error on the operations of
033  * accessing that kind of class objects.
034  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
035  * and <tt>instanceof</tt> to it always <tt>true</tt>.
036  */
037 public class JsCDATASection extends JsClient.CDATASection.Prototype
038 {
039     /**
040      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
041      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
042      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
043      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
044      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
045      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
046      * either circumstance, the field names must be exactly same as the member names, as 
047      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
048      * based on the field names.</p>
049      *
050      * @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>
051      * 
052      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
053      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
054      * of class objects.
055      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
056      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
057      * <pre>q.m</pre>
058      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
059      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
060      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
061      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
062      * <pre>m</pre>
063      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
064      * error on the access to <b>opaque</b> fields declared by this class under any other 
065      * circumstances.
066      */
067     public static class Member extends JsClient.CDATASection.Prototype.Member
068     {
069         /**
070          * <p>Internally constructs a member based on a qualifying member.</p>
071          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
072          * or <b>internal</b> classes or class members.</p>
073          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
074          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
075          * declared in the declaring class of this constructor itself or its subclasses. 
076          * Under this circumstance, the field names must be exactly same as the member 
077          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
078          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
079          * to their names appending to the name resolved from the specified qualifying 
080          * member with a dot in between.</p>
081          * @param q A qualifying member
082          * @param mid The ID of the member to construct
083          * @since 1.0
084          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
085          */
086         public Member(JsObject.Member q, Mid mid) {
087             super(q, mid);
088         }
089         /**
090          * <p>Internally constructs a member without a qualifying member.</p>
091          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
092          * or <b>internal</b> classes or class members.</p>
093          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
094          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
095          * declared in <b>opaque</b> types other than the declaring class of this constructor 
096          * itself and its subclasses. Under this circumstance, the field names must be
097          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
098          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
099          * @param mid The ID of the member to construct
100          * @since 1.0
101          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
102          */
103         public Member(Mid mid) {
104             super(mid);
105         }
106         @Override
107         /**
108          * <p>Evaluates the property, represented by the current member instance, of the
109          * argument object.</p>
110          * @param o The argument object
111          * @return The value of the current member based on the object argument.
112          * @since 1.0
113          * @javascript Re-compilers must convert the instance invocation of this method into
114          * the JavaScript expression: 
115          * <pre>o.m</pre>
116          * where <tt>m</tt> is the identifier name resolved from the current member
117          * instance of the invocation.
118          */
119         public JsCDATASection with(ObjectLike o) {
120             return new JsCDATASection(super.with(o));
121         }
122     }
123 
124     /**
125      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
126      * with the wrapping constructor.</p>
127      * @param var The argument of an <b>opaque</b> object.
128      * @since 1.0
129      * @javascript Re-compilers must ignore the construction operation of this constructor,
130      * that is, replacing it with its only argument.
131      */
132     public JsCDATASection(JsObject var) {
133         super(var);
134     }
135 
136     @Override
137     /**
138      * <p>Returns the primitive value associated with the current instance, if there is one.
139      * This invocation simply returns the instance itself for the current instance is an 
140      * object and there is no primitive value for it.</p>
141      * @return The current object itself.
142      * @since 1.0
143      * @javascript Re-compilers must convert the instance invocation of this method directly
144      * into a JavaScript invocation on its current object instance without changing the 
145      * method name, but expanding variable arguments, if any, into comma-separated values. 
146      */
147     public JsCDATASection valueOf() {
148         return new JsCDATASection((JsObject)var().valueOf());
149     }
150 
151     /**
152      * <p>Splits this {@link JsCDATASection} node into two at the specified character position 
153      * and returns the new {@link JsCDATASection} node.</p>
154      * <p>This method splits a {@link JsCDATASection} node in two at the specified <tt>offset</tt>. 
155      * The original {@link JsCDATASection} node is modified so that it contains all text content 
156      * up to, but not including, the character at position <tt>offset</tt>. A new {@link JsCDATASection} 
157      * node is created to contain all the characters from and including the position <tt>offset</tt> 
158      * to the end of the string. The new {@link JsCDATASection} node is the return value of the 
159      * method. Additionally, if the original {@link JsCDATASection} node has a {@link JsNode#parentNode}, 
160      * the new node is inserted into this parent node immediately after the original node.</p>
161      * @param offset The character position at which to split the {@link JsCDATASection} node.
162      * @return The {@link JsCDATASection} node that was split from this node.
163      * @throws RuntimeException JavaScript throws a a {@link JsDOMException} object with 
164      * the {@link JsDOMException#code} property of the value {@link JsDOMException#NO_MODIFICATION_ALLOWED_ERR} 
165      * if the node is read-only and may not be modified or the value {@link JsDOMException#INDEX_SIZE_ERR} 
166      * if <tt>offset</tt> is negative or is greater than the length of the {@link JsCDATASection} or 
167      * {@link JsComment} node. 
168      * See {@link Js#err(Object)} for JS Simulation.
169      * @since 1.0
170      * @see #splitText(NumberLike)
171      * @javascript Re-compilers must convert the instance invocation of this method directly
172      * into a JavaScript invocation on its current object instance without changing the 
173      * method name, but expanding variable arguments, if any, into comma-separated values. 
174      */
175     @Override
176     public final JsCDATASection splitText(Number offset) {
177         return new JsCDATASection(call(splitText, offset));
178     }
179     /**
180      * <p>Splits this {@link JsCDATASection} node into two at the specified character position 
181      * and returns the new {@link JsCDATASection} node.</p>
182      * <p>This method splits a {@link JsCDATASection} node in two at the specified <tt>offset</tt>. 
183      * The original {@link JsCDATASection} node is modified so that it contains all text content 
184      * up to, but not including, the character at position <tt>offset</tt>. A new {@link JsCDATASection} 
185      * node is created to contain all the characters from and including the position <tt>offset</tt> 
186      * to the end of the string. The new {@link JsCDATASection} node is the return value of the 
187      * method. Additionally, if the original {@link JsCDATASection} node has a {@link JsNode#parentNode}, 
188      * the new node is inserted into this parent node immediately after the original node.</p>
189      * <p>This class inherits from {@link JsText}. The newly created node of {@link #splitText(Number)} 
190      * is a {@link JsCDATASection} node rather than a {@link JsText} node as of 
191      * {@link JsText#splitText(Number)}.</p>
192      * <p>This class inherits from {@link JsText}. The newly created node of {@link #splitText(NumberLike)} 
193      * is a {@link JsCDATASection} node rather than a {@link JsText} node as of 
194      * {@link JsText#splitText(Number)}.</p>
195      * @param offset The character position at which to split the {@link JsCDATASection} node.
196      * @return The {@link JsCDATASection} node that was split from this node.
197      * @throws RuntimeException JavaScript throws a a {@link JsDOMException} object with 
198      * the {@link JsDOMException#code} property of the value {@link JsDOMException#NO_MODIFICATION_ALLOWED_ERR} 
199      * if the node is read-only and may not be modified or the value {@link JsDOMException#INDEX_SIZE_ERR} 
200      * if <tt>offset</tt> is negative or is greater than the length of the {@link JsCDATASection} or 
201      * {@link JsComment} node. 
202      * See {@link Js#err(Object)} for JS Simulation.
203      * @since 1.0
204      * @see #splitText(Number)
205      * @javascript Re-compilers must convert the instance invocation of this method directly
206      * into a JavaScript invocation on its current object instance without changing the 
207      * method name, but expanding variable arguments, if any, into comma-separated values. 
208      */
209     @Override
210     public final JsCDATASection splitText(NumberLike<?> offset) {
211         return splitText(Js.valueOf(offset));
212     }
213 }