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 <tt>EntityReference</tt> nodes.</p>
027  * <p>{@link JsEntityReference} objects may be inserted into the structure model when an 
028  * entity reference is in the source document, or when the user wishes to insert an 
029  * entity reference. Note that character references and references to predefined entities 
030  * are considered to be expanded by the HTML or XML processor so that characters are 
031  * represented by their Unicode equivalent rather than by an entity reference. Moreover, 
032  * the XML processor may completely expand references to entities while building the 
033  * structure model, instead of providing {@link JsEntityReference} objects. If it does 
034  * provide such objects, then for a given {@link JsEntityReference} node, it may be that 
035  * there is no {@link JsEntity} node representing the referenced entity. If such a {@link JsEntity} 
036  * node exists, then the subtree of the {@link JsEntityReference} node is in general a 
037  * copy of the {@link JsEntity} node subtree. However, this may not be true when an 
038  * entity contains an unbound name space prefix. In such a case, because the name space 
039  * prefix resolution depends on where the entity reference is, the descendants of the 
040  * {@link JsEntityReference} node may be bound to different namespace URIs.</p>
041  * <p>As for {@link JsEntity} nodes, {@link JsEntityReference} nodes and all their 
042  * descendants are read-only.</p>
043  * <p>Note that main-stream web browsers do not support the <tt>EntityReference</tt> interface 
044  * declared by the DOM Core Specification. This <b>opaque</b> class inherits directly 
045  * from {@link JsNode} and for documentation purpose only.</p>
046  *
047  * @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>
048  *
049  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be
050  * generated into the target codes. Re-compilers must exit with error on the operations of
051  * accessing that kind of class objects.
052  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
053  * and <tt>instanceof</tt> to it always <tt>true</tt>.
054  */
055 public class JsEntityReference extends JsNode
056 {
057     /**
058      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
059      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
060      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
061      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
062      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
063      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
064      * either circumstance, the field names must be exactly same as the member names, as 
065      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
066      * based on the field names.</p>
067      *
068      * @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>
069      * 
070      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
071      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
072      * of class objects.
073      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
074      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
075      * <pre>q.m</pre>
076      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
077      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
078      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
079      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
080      * <pre>m</pre>
081      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
082      * error on the access to <b>opaque</b> fields declared by this class under any other 
083      * circumstances.
084      */
085     public static class Member extends JsClient.Node.Prototype.Member
086     {
087         /**
088          * <p>Internally constructs a member based on a qualifying member.</p>
089          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
090          * or <b>internal</b> classes or class members.</p>
091          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
092          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
093          * declared in the declaring class of this constructor itself or its subclasses. 
094          * Under this circumstance, the field names must be exactly same as the member 
095          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
096          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
097          * to their names appending to the name resolved from the specified qualifying 
098          * member with a dot in between.</p>
099          * @param q A qualifying member
100          * @param mid The ID of the member to construct
101          * @since 1.0
102          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
103          */
104         public Member(JsObject.Member q, Mid mid) {
105             super(q, mid);
106         }
107         /**
108          * <p>Internally constructs a member without a qualifying member.</p>
109          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
110          * or <b>internal</b> classes or class members.</p>
111          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
112          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
113          * declared in <b>opaque</b> types other than the declaring class of this constructor 
114          * itself and its subclasses. Under this circumstance, the field names must be
115          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
116          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
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(Mid mid) {
122             super(mid);
123         }
124         @Override
125         /**
126          * <p>Evaluates the property, represented by the current member instance, of the
127          * argument object.</p>
128          * @param o The argument object
129          * @return The value of the current member based on the object argument.
130          * @since 1.0
131          * @javascript Re-compilers must convert the instance invocation of this method into
132          * the JavaScript expression: 
133          * <pre>o.m</pre>
134          * where <tt>m</tt> is the identifier name resolved from the current member
135          * instance of the invocation.
136          */
137         public JsEntityReference with(ObjectLike o) {
138             return new JsEntityReference(super.with(o));
139         }
140     }
141 
142     /**
143      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
144      * with the wrapping constructor.</p>
145      * @param var The argument of an <b>opaque</b> object.
146      * @since 1.0
147      * @javascript Re-compilers must ignore the construction operation of this constructor,
148      * that is, replacing it with its only argument.
149      */
150     public JsEntityReference(JsObject var) {
151         super(var);
152     }
153 
154     @Override
155     /**
156      * <p>Returns the primitive value associated with the current instance, if there is one.
157      * This invocation simply returns the instance itself for the current instance is an 
158      * object and there is no primitive value for it.</p>
159      * @return The current object itself.
160      * @since 1.0
161      * @javascript Re-compilers must convert the instance invocation of this method directly
162      * into a JavaScript invocation on its current object instance without changing the 
163      * method name, but expanding variable arguments, if any, into comma-separated values. 
164      */
165     public JsEntityReference valueOf() {
166         return new JsEntityReference((JsObject)var().valueOf());
167     }
168 }