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#CharacterData} class.</p>
028  * <p>This class defines functionality for its subclasses {@link JsText} and {@link JsComment}.</p>
029  * <p>Note that it is not necessary to use the string-manipulation methods defined by 
030  * this class. The {@link JsCharacterData#data} property is of string type, and you can 
031  * manipulate it with various string and regular expression methods.</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 JsCharacterData extends JsClient.CharacterData.Prototype
042 {
043     /**
044      * <p>An <b>internal</b> class containing membership data for its enclosing
045      * opaque class.</p>
046      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or
047      * class members.</p>
048      *
049      * @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>
050      * 
051      * @javascript Re-compilers must report error on resolving an <b>internal</b> class.
052      */
053     protected static abstract class Members extends JsClient.CharacterData.Prototype.Members
054     {
055         /**
056          * <p>An <b>internal</b> static field defining a member ID of the field name and
057          * used internally to define a member of the same name.</p>
058          * @since 1.0
059          * @see JsCharacterData#data
060          * @see JsCharacterData.Member#data
061          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
062          */
063         public final static Mid data   = id("data"  );
064         /**
065          * <p>An <b>internal</b> static field defining a member ID of the field name and
066          * used internally to define a member of the same name.</p>
067          * @since 1.0
068          * @see JsCharacterData#length
069          * @see JsCharacterData.Member#length
070          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
071          */
072         public final static Mid length = id("length");
073     }
074     /**
075      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
076      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
077      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
078      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
079      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
080      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
081      * either circumstance, the field names must be exactly same as the member names, as 
082      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
083      * based on the field names.</p>
084      *
085      * @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>
086      * 
087      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
088      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
089      * of class objects.
090      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
091      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
092      * <pre>q.m</pre>
093      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
094      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
095      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
096      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
097      * <pre>m</pre>
098      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
099      * error on the access to <b>opaque</b> fields declared by this class under any other 
100      * circumstances.
101      */
102     public static class Member extends JsClient.CharacterData.Prototype.Member
103     {
104         /**
105          * <p>Internally constructs a member based on a qualifying member.</p>
106          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
107          * or <b>internal</b> classes or class members.</p>
108          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
109          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
110          * declared in the declaring class of this constructor itself or its subclasses. 
111          * Under this circumstance, the field names must be exactly same as the member 
112          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
113          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
114          * to their names appending to the name resolved from the specified qualifying 
115          * member with a dot in between.</p>
116          * @param q A qualifying member
117          * @param mid The ID of the member to construct
118          * @since 1.0
119          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
120          */
121         public Member(JsObject.Member q, Mid mid) {
122             super(q, mid);
123         }
124         /**
125          * <p>Internally constructs a member without a qualifying member.</p>
126          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
127          * or <b>internal</b> classes or class members.</p>
128          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
129          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
130          * declared in <b>opaque</b> types other than the declaring class of this constructor 
131          * itself and its subclasses. Under this circumstance, the field names must be
132          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
133          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
134          * @param mid The ID of the member to construct
135          * @since 1.0
136          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
137          */
138         public Member(Mid mid) {
139             super(mid);
140         }
141         @Override
142         /**
143          * <p>Evaluates the property, represented by the current member instance, of the
144          * argument object.</p>
145          * @param o The argument object
146          * @return The value of the current member based on the object argument.
147          * @since 1.0
148          * @javascript Re-compilers must convert the instance invocation of this method into
149          * the JavaScript expression: 
150          * <pre>o.m</pre>
151          * where <tt>m</tt> is the identifier name resolved from the current member
152          * instance of the invocation.
153          */
154         public JsCharacterData with(ObjectLike o) {
155             return new JsCharacterData(super.with(o));
156         }
157 
158         /**
159          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
160          * name of this field, qualified by the current member instance of the field, and 
161          * to access the property of the name on an object.</p>
162          * <p>The property, identified by this member, of a {@link JsCharacterData} 
163          * node object refers to the text value contained by the node.</p>
164          * @since 1.0
165          * @javascript Re-compilers must resolve the member of this instance field to the
166          * identifier of the field name appending to the identifier resolved from its 
167          * qualifying member with a dot in between.
168          */
169         public final Value.String.Member data   = new Value.String.Member(this, Members.data  );
170         /**
171          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
172          * name of this field, qualified by the current member instance of the field, and 
173          * to access the property of the name on an object.</p>
174          * <p>The property, identified by this member, of a {@link JsCharacterData} 
175          * node object refers to the number of characters contained by the node.</p>
176          * @since 1.0
177          * @javascript Re-compilers must resolve the member of this instance field to the
178          * identifier of the field name appending to the identifier resolved from its 
179          * qualifying member with a dot in between.
180          */
181         public final Value.Number.Member length = new Value.Number.Member(this, Members.length);
182     }
183 
184     /**
185      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
186      * with the wrapping constructor.</p>
187      * @param var The argument of an <b>opaque</b> object.
188      * @since 1.0
189      * @javascript Re-compilers must ignore the construction operation of this constructor,
190      * that is, replacing it with its only argument.
191      */
192     public JsCharacterData(JsObject var) {
193         super(var);
194     }
195 
196     /**
197      * <p>An <b>opaque</b> static field defining a member that is named by the field name
198      * without a qualifying member and to access the property of the name on an object.</p>
199      * <p>The property, identified by this member, of a {@link JsCharacterData} 
200      * node object refers to the text value contained by the node.</p>
201      * @since 1.0
202      * @javascript Re-compilers must resolve the member of this static field to the
203      * identifier of the field name.
204      */
205     public static final Value.String.Member data   = new Value.String.Member(Members.data  );
206     /**
207      * <p>An <b>opaque</b> static field defining a member that is named by the field name
208      * without a qualifying member and to access the property of the name on an object.</p>
209      * <p>The property, identified by this member, of a {@link JsCharacterData} 
210      * node object refers to the number of characters contained by the node.</p>
211      * @since 1.0
212      * @javascript Re-compilers must resolve the member of this static field to the
213      * identifier of the field name.
214      */
215     public static final Value.Number.Member length = new Value.Number.Member(Members.length);
216 
217     @Override
218     /**
219      * <p>Returns the primitive value associated with the current instance, if there is one.
220      * This invocation simply returns the instance itself for the current instance is an 
221      * object and there is no primitive value for it.</p>
222      * @return The current object itself.
223      * @since 1.0
224      * @javascript Re-compilers must convert the instance invocation of this method directly
225      * into a JavaScript invocation on its current object instance without changing the 
226      * method name, but expanding variable arguments, if any, into comma-separated values. 
227      */
228     public JsCharacterData valueOf() {
229         return new JsCharacterData((JsObject)var().valueOf());
230     }
231     /**
232      * <p>Appends the specified string to the text contained by this node.</p>
233      * <p>This method appends the string <tt>arg</tt> to the end of the {@link #data} 
234      * property for the current node.</p>
235      * @param arg The string to be appended to the current node.
236      * @throws RuntimeException JavaScript throws a {@link JsDOMException} object with 
237      * the {@link JsDOMException#code} property of the value {@link JsDOMException#NO_MODIFICATION_ALLOWED_ERR} 
238      * if this method was called on a node that is read-only and may not be modified. 
239      * See {@link Js#err(Object)} for JS Simulation.
240      * @since 1.0
241      * @javascript Re-compilers must convert the instance invocation of this method directly
242      * into a JavaScript invocation on its current object instance without changing the 
243      * method name, but expanding variable arguments, if any, into comma-separated values. 
244      */
245     public final void appendData(String arg) {
246         call(appendData, arg);
247     }
248     /**
249      * <p>Appends the specified string to the text contained by this node.</p>
250      * <p>This method appends the string <tt>arg</tt> to the end of the {@link #data} 
251      * property for the current node.</p>
252      * @param arg The string to be appended to the current node.
253      * @throws RuntimeException JavaScript throws a {@link JsDOMException} object with 
254      * the {@link JsDOMException#code} property of the value {@link JsDOMException#NO_MODIFICATION_ALLOWED_ERR} 
255      * if this method was called on a node that is read-only and may not be modified. 
256      * See {@link Js#err(Object)} for JS Simulation.
257      * @since 1.0
258      * @javascript Re-compilers must convert the instance invocation of this method directly
259      * into a JavaScript invocation on its current object instance without changing the 
260      * method name, but expanding variable arguments, if any, into comma-separated values. 
261      */
262     public final void appendData(StringLike arg) {
263         call(appendData, arg);
264     }
265     /**
266      * <p>Deletes text from the current node, starting with the character at the 
267      * specified offset and continuing for the specified number of characters.</p>
268      * <p>This method deletes characters from the current node, starting with the 
269      * character at the position <tt>offset</tt> and continuing for <tt>count</tt> 
270      * characters. If <tt>offset</tt> plus <tt>count</tt> is greater than the number of 
271      * characters in the current node, all characters from <tt>offset</tt> to the end of 
272      * the string are deleted..</p>
273      * @param offset The position of the first character to be deleted.
274      * @param count The number of characters to be deleted.
275      * @throws RuntimeException JavaScript throws a {@link JsDOMException} object with 
276      * the {@link JsDOMException#code} property of the value {@link JsDOMException#NO_MODIFICATION_ALLOWED_ERR} 
277      * if this method was called on a node that is read-only and may not be modified, or 
278      * the value {@link JsDOMException#INDEX_SIZE_ERR} if the <tt>offset</tt> or <tt>count</tt> 
279      * argument is negative, or <tt>offset</tt> is greater than the {@link #length} of 
280      * the current node. See {@link Js#err(Object)} for JS Simulation.
281      * @since 1.0
282      * @javascript Re-compilers must convert the instance invocation of this method directly
283      * into a JavaScript invocation on its current object instance without changing the 
284      * method name, but expanding variable arguments, if any, into comma-separated values. 
285      */
286     public final void deleteData(Number offset, Number count) {
287         call(deleteData, new Vars<Object>().add(offset).add(count));
288     }
289     /**
290      * <p>Inserts the specified string into the text of the current node at the specified 
291      * character offset.</p>
292      * <p>This method inserts the specified string <tt>arg</tt> into the text of the 
293      * current node at the specified position <tt>offset</tt>.</p>
294      * @param offset The character position within the current node at which the string 
295      * is to be inserted.
296      * @param arg The string to insert.
297      * @throws RuntimeException JavaScript throws a {@link JsDOMException} object with 
298      * the {@link JsDOMException#code} property of the value {@link JsDOMException#NO_MODIFICATION_ALLOWED_ERR} 
299      * if this method was called on a node that is read-only and may not be modified, or 
300      * the value {@link JsDOMException#INDEX_SIZE_ERR} if the <tt>offset</tt> argument 
301      * is negative or greater than the {@link #length} of the current node. See 
302      * {@link Js#err(Object)} for JS Simulation.
303      * @since 1.0
304      * @javascript Re-compilers must convert the instance invocation of this method directly
305      * into a JavaScript invocation on its current object instance without changing the 
306      * method name, but expanding variable arguments, if any, into comma-separated values. 
307      */
308     public final void insertData(Number offset, String arg) {
309         call(insertData, new Vars<Object>().add(offset).add(arg));
310     }
311     /**
312      * <p>Replaces the characters starting at the specified character offset and 
313      * continuing for the specified number of characters with the specified string.</p>
314      * <p>This method replaces <tt>count</tt> characters starting at position <tt>offset</tt> 
315      * within the string <tt>arg</tt>. If the sum of <tt>offset</tt> and <tt>count</tt> 
316      * is greater than the {@link #length} of the current node, all characters from 
317      * <tt>offset</tt> on are replaced.</p>
318      * @param offset The character position within the current node at which the 
319      * replacement is to begin.
320      * @param count The number of characters to be replaced.
321      * @param arg The string that replaces the characters specified by <tt>offset</tt> 
322      * and <tt>count</tt>.
323      * @throws RuntimeException JavaScript throws a {@link JsDOMException} object with 
324      * the {@link JsDOMException#code} property of the value {@link JsDOMException#NO_MODIFICATION_ALLOWED_ERR} 
325      * if this method was called on a node that is read-only and may not be modified, or 
326      * the value {@link JsDOMException#INDEX_SIZE_ERR} if the <tt>offset</tt> or <tt>count</tt> 
327      * argument is negative, or <tt>offset</tt> is greater than the {@link #length} of 
328      * the current node. See {@link Js#err(Object)} for JS Simulation.
329      * @since 1.0
330      * @javascript Re-compilers must convert the instance invocation of this method directly
331      * into a JavaScript invocation on its current object instance without changing the 
332      * method name, but expanding variable arguments, if any, into comma-separated values. 
333      */
334     public final void replaceData(Number offset, Number count, String arg) {
335         call(replaceData, new Vars<Object>().add(offset).add(count).add(arg));
336     }
337     /**
338      * <p>Returns a copy of the text starting at the specified character offset and 
339      * continuing for the specified number of characters.</p>
340      * <p>This method extracts the substring that starts at position <tt>offset</tt> and 
341      * continues for <tt>count</tt> characters from the text of the current node. This 
342      * method is useful only when the amount of text contained by the current node is 
343      * larger than the maximum number of characters that can fit in a string in a 
344      * browser's JavaScript implementation. In this case, a JavaScript program cannot 
345      * use the {@link #data} property of the node directly and must instead work with 
346      * shorter substrings of the node's text. This situation is unlikely to arise in 
347      * practice.</p>
348      * @param offset The position of the first character to be returned.
349      * @param count The number of characters in the substring to be returned.
350      * @return A string that consists of <tt>count</tt> characters of the current node 
351      * starting with the character at position <tt>offset</tt>.
352      * @throws RuntimeException JavaScript throws a {@link JsDOMException} object with 
353      * the {@link JsDOMException#code} property of the value {@link JsDOMException#DOMSTRING_SIZE_ERR} 
354      * if specified range of text is too long to fit into a string in the browser's JavaScript 
355      * implementation, or the value {@link JsDOMException#INDEX_SIZE_ERR} if the <tt>offset</tt> 
356      * argument is negative or greater than the {@link #length} of the current node. 
357      * See {@link Js#err(Object)} for JS Simulation.
358      * @since 1.0
359      * @javascript Re-compilers must convert the instance invocation of this method directly
360      * into a JavaScript invocation on its current object instance without changing the 
361      * method name, but expanding variable arguments, if any, into comma-separated values. 
362      */
363     public final String substringData(Number offset, Number count) {
364         return call(substringData, new Vars<Object>().add(offset).add(count));
365     }
366 }