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#Attr} class.</p>
028  * <p>An object of this opaque class represents an attribute of an {@link JsElement} node. 
029  * Objects of this opaque class are associated with {@link JsElement} nodes but are not 
030  * directly part of the document tree (and have a <tt>null</tt> {@link JsNode#parentNode} 
031  * property. You can obtain an <tt>JsAttr</tt> object through the {@link JsNode#attributes} 
032  * property or by calling the {@link JsElement#getAttributeNode(String)} or {@link JsElement#getAttributeNodeNS(String, String)} 
033  * methods.</p>
034  * <p>The value of an attribute is represented by the descendant nodes of a node of this 
035  * opaque class. In HTML documents, a node of this opaque class always has a single Text 
036  * node child, and the {@link JsAttr#value} property provides a shortcut for reading and 
037  * writing the value of this child node.</p>
038  * <p>The XML grammar allows XML documents to have attributes that consist of Text nodes 
039  * and EntityReference nodes, which is why an attribute value cannot be fully represented 
040  * by a string. In practice, however, web browsers expand any entity references in XML 
041  * attribute values and do not implement the EntityReference interface. Therefore, in 
042  * client-side JavaScript, the {@link JsAttr#value} property is all that is needed to 
043  * read and write attribute values.</p>
044  * <p>Since attribute values can be completely represented by strings, it is not usually 
045  * necessary to use this opaque class at all. In most cases, the easiest way to work 
046  * with attributes is with the {@link JsElement#getAttribute(String)} and 
047  * {@link JsElement#setAttribute(String, Object)} methods. These methods use strings 
048  * for attribute values and avoid the use of this class altogether.</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
053  * generated into the target codes. Re-compilers must exit with error on the operations of
054  * accessing that kind of class objects.
055  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
056  * and <tt>instanceof</tt> to it always <tt>true</tt>.
057  */
058 public class JsAttr extends JsClient.Attr.Prototype
059 {
060     /**
061      * <p>An <b>internal</b> class containing membership data for its enclosing
062      * opaque class.</p>
063      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or
064      * class members.</p>
065      *
066      * @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>
067      * 
068      * @javascript Re-compilers must report error on resolving an <b>internal</b> class.
069      */
070     protected static abstract class Members extends JsClient.Attr.Prototype.Members
071     {
072         /**
073          * <p>An <b>internal</b> static field defining a member ID of the field name and
074          * used internally to define a member of the same name.</p>
075          * @since 1.0
076          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
077          */
078         public final static Mid name         = id("name"        );
079         /**
080          * <p>An <b>internal</b> static field defining a member ID of the field name and
081          * used internally to define a member of the same name.</p>
082          * @since 1.0
083          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
084          */
085         public final static Mid ownerElement = id("ownerElement");
086         /**
087          * <p>An <b>internal</b> static field defining a member ID of the field name and
088          * used internally to define a member of the same name.</p>
089          * @since 1.0
090          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
091          */
092         public final static Mid specified    = id("specified"   );
093         /**
094          * <p>An <b>internal</b> static field defining a member ID of the field name and
095          * used internally to define a member of the same name.</p>
096          * @since 1.0
097          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
098          */
099         public final static Mid value        = id("value"       );
100     }
101 
102     /**
103      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
104      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
105      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
106      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
107      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
108      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
109      * either circumstance, the field names must be exactly same as the member names, as 
110      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
111      * based on the field names.</p>
112      *
113      * @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>
114      * 
115      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
116      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
117      * of class objects.
118      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
119      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
120      * <pre>q.m</pre>
121      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
122      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
123      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
124      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
125      * <pre>m</pre>
126      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
127      * error on the access to <b>opaque</b> fields declared by this class under any other 
128      * circumstances.
129      */
130     public static class Member extends JsClient.Attr.Prototype.Member
131     {
132         /**
133          * <p>Internally constructs a member based on a qualifying member.</p>
134          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
135          * or <b>internal</b> classes or class members.</p>
136          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
137          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
138          * declared in the declaring class of this constructor itself or its subclasses. 
139          * Under this circumstance, the field names must be exactly same as the member 
140          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
141          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
142          * to their names appending to the name resolved from the specified qualifying 
143          * member with a dot in between.</p>
144          * @param q A qualifying member
145          * @param mid The ID of the member to construct
146          * @since 1.0
147          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
148          */
149         public Member(JsObject.Member q, Mid mid) {
150             super(q, mid);
151         }
152         /**
153          * <p>Internally constructs a member without a qualifying member.</p>
154          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
155          * or <b>internal</b> classes or class members.</p>
156          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
157          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
158          * declared in <b>opaque</b> types other than the declaring class of this constructor 
159          * itself and its subclasses. Under this circumstance, the field names must be
160          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
161          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
162          * @param mid The ID of the member to construct
163          * @since 1.0
164          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
165          */
166         public Member(Mid mid) {
167             super(mid);
168         }
169         @Override
170         /**
171          * <p>Evaluates the property, represented by the current member instance, of the
172          * argument object.</p>
173          * @param o The argument object
174          * @return The value of the current member based on the object argument.
175          * @since 1.0
176          * @javascript Re-compilers must convert the instance invocation of this method into
177          * the JavaScript expression: 
178          * <pre>o.m</pre>
179          * where <tt>m</tt> is the identifier name resolved from the current member
180          * instance of the invocation.
181          */
182         public JsAttr with(ObjectLike o) {
183             return new JsAttr(super.with(o));
184         }
185 
186         /**
187          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
188          * name of this field, qualified by the current member instance of the field, and 
189          * to access the property of the name on an object.</p>
190          * <p>The property, identified by this member, of a {@link JsAttr} node refers 
191          * to a read-only string value which is the name of the attribute.</p>
192          * @since 1.0
193          * @javascript Re-compilers must resolve the member of this instance field to the
194          * identifier of the field name appending to the identifier resolved from its 
195          * qualifying member with a dot in between.
196          */
197         public final Value.String.Member name  = new Value.String.Member(this, Members.name );
198         /**
199          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
200          * name of this field, qualified by the current member instance of the field, and 
201          * to access the property of the name on an object.</p>
202          * <p>The property, identified by this member, of a {@link JsAttr} node refers 
203          * to the value of the attribute. When reading the property, the attribute value 
204          * is returned as a string. When you set the property to a string, it automatically 
205          * creates a Text node that contains the same text and makes that Text node the 
206          * sole child of the {@link JsAttr} node.</p>
207          * @since 1.0
208          * @javascript Re-compilers must resolve the member of this instance field to the
209          * identifier of the field name appending to the identifier resolved from its 
210          * qualifying member with a dot in between.
211          */
212         public final Value.String.Member value = new Value.String.Member(this, Members.value);
213         /**
214          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
215          * name of this field, qualified by the current member instance of the field, and 
216          * to access the property of the name on an object.</p>
217          * <p>The property, identified by this member, of a {@link JsAttr} node is a 
218          * read-only reference to a {@link JsElement} object that contains the attribute, 
219          * or <tt>null</tt> if the {@link JsAttr} node is not currently associated with 
220          * any {@link JsElement} node.</p>
221          * @since 1.0
222          * @javascript Re-compilers must resolve the member of this instance field to the
223          * identifier of the field name appending to the identifier resolved from its 
224          * qualifying member with a dot in between.
225          */
226         public final JsElement.Member ownerElement = new JsElement.Member(this, Members.ownerElement);
227         /**
228          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
229          * name of this field, qualified by the current member instance of the field, and 
230          * to access the property of the name on an object.</p>
231          * <p>The property, identified by this member, of a {@link JsAttr} node is a 
232          * read-only reference to a boolean value. The boolean value is <tt>true</tt> if the 
233          * attribute is explicitly specified in the document source or set by a script; 
234          * The value is <tt>false</tt> if the attribute is not explicitly specified but 
235          * a default value is specified in the document's DTD.</p>
236          * @since 1.0
237          * @javascript Re-compilers must resolve the member of this instance field to the
238          * identifier of the field name appending to the identifier resolved from its 
239          * qualifying member with a dot in between.
240          */
241         public final Value.Boolean.Member specified = new Value.Boolean.Member(this, Members.specified);
242     }
243 
244     /**
245      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
246      * with the wrapping constructor.</p>
247      * @param var The argument of an <b>opaque</b> object.
248      * @since 1.0
249      * @javascript Re-compilers must ignore the construction operation of this constructor,
250      * that is, replacing it with its only argument.
251      */
252     public JsAttr(JsObject var) {
253         super(var);
254     }
255 
256     /**
257      * <p>An <b>opaque</b> static field defining a member that is named by the field name
258      * without a qualifying member and to access the property of the name on an object.</p>
259      * <p>The property, identified by this member, of a {@link JsAttr} node refers 
260      * to a read-only string value which is the name of the attribute.</p>
261      * @since 1.0
262      * @javascript Re-compilers must resolve the member of this static field to the
263      * identifier of the field name.
264      */
265     public static final Value.String.Member name  = new Value.String.Member(Members.name );
266     /**
267      * <p>An <b>opaque</b> static field defining a member that is named by the field name
268      * without a qualifying member and to access the property of the name on an object.</p>
269      * <p>The property, identified by this member, of a {@link JsAttr} node refers 
270      * to the value of the attribute. When reading the property, the attribute value 
271      * is returned as a string. When you set the property to a string, it automatically 
272      * creates a {@link JsText} node that contains the same text and makes that 
273      * {@link JsText} node the sole child of the {@link JsAttr} node.</p>
274      * @since 1.0
275      * @javascript Re-compilers must resolve the member of this static field to the
276      * identifier of the field name.
277      */
278     public static final Value.String.Member value = new Value.String.Member(Members.value);
279     /**
280      * <p>An <b>opaque</b> static field defining a member that is named by the field name
281      * without a qualifying member and to access the property of the name on an object.</p>
282      * <p>The property, identified by this member, of a {@link JsAttr} node is a 
283      * read-only reference to a {@link JsElement} object that contains the attribute, 
284      * or <tt>null</tt> if the {@link JsAttr} node is not currently associated with 
285      * any {@link JsElement} node.</p>
286      * @since 1.0
287      * @javascript Re-compilers must resolve the member of this static field to the
288      * identifier of the field name.
289      */
290     public static final JsElement.Member ownerElement = new JsElement.Member(Members.ownerElement);
291     /**
292      * <p>An <b>opaque</b> static field defining a member that is named by the field name
293      * without a qualifying member and to access the property of the name on an object.</p>
294      * <p>The property, identified by this member, of a {@link JsAttr} node is a 
295      * read-only reference to a {@link JsElement} object that contains the attribute, 
296      * or <tt>null</tt> if the {@link JsAttr} node is not currently associated with 
297      * any {@link JsElement} node.</p>
298      * @since 1.0
299      * @javascript Re-compilers must resolve the member of this static field to the
300      * identifier of the field name.
301      */
302     public static final Value.Boolean.Member specified = new Value.Boolean.Member(Members.specified);
303 
304     @Override
305     /**
306      * <p>Returns the primitive value associated with the current instance, if there is one.
307      * This invocation simply returns the instance itself for the current instance is an 
308      * object and there is no primitive value for it.</p>
309      * @return The current object itself.
310      * @since 1.0
311      * @javascript Re-compilers must convert the instance invocation of this method directly
312      * into a JavaScript invocation on its current object instance without changing the 
313      * method name, but expanding variable arguments, if any, into comma-separated values. 
314      */
315     public JsAttr valueOf() {
316         return new JsAttr((JsObject)var().valueOf());
317     }
318     public final JsElement var(JsElement.Member r) {
319         return r.with(this);
320     }
321 
322     @Override
323     public JsAttr cloneNode(Boolean deep) {
324         return new JsAttr(call(cloneNode, deep));
325     }
326     @Override
327     public JsAttr cloneNode(Value<Boolean> deep) {
328         return new JsAttr(call(cloneNode, deep));
329     }
330     @Override
331     public JsAttr cloneNode(JsBoolean deep) {
332         return new JsAttr(call(cloneNode, deep));
333     }
334 }