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>Entity</tt> nodes.</p>
027  * <p>This <b>opaque</b> class represents an entity, either parsed or unparsed, in an 
028  * XML document. Programmers working exclusively with HTML documents never need to use 
029  * this class.</p>
030  * <p>Note that DOM2 specification only models the entity itself not the entity declaration. 
031  * Entity declaration modeling has been left for a later Level of the DOM specification.</p>
032  * <p>The inherited {@link JsNode#nodeName} attribute contains the name of the entity.</p>
033  * <p>An XML processor may choose to completely expand entities before the structure 
034  * model is passed to the DOM. In this case there will be no {@link JsEntityReference} 
035  * nodes in the document tree.</p>
036  * <p>XML does not mandate that a non-validating XML processor read and process entity 
037  * declarations made in the external subset or declared in external parameter entities. 
038  * This means that parsed entities declared in the external subset need not be expanded 
039  * by some classes of applications, and that the replacement value of the entity may not 
040  * be available. When the replacement value is available, the corresponding {@link JsEntity} 
041  * node's child list represents the structure of that replacement text. Otherwise, the 
042  * child list is empty.</p>
043  * <p>The DOM Level 2 does not support editing {@link JsEntity} nodes. If you want to 
044  * make changes to the contents of a {@link JsEntity} node, every related {@link JsEntityReference} 
045  * node has to be replaced in the structure model by a clone of the contents of the {@link JsEntity} 
046  * node, and then the desired changes must be made to each of those clones instead. {@link JsEntity} 
047  * nodes and all their descendants  are read-only.</p>
048  * <p>A {@link JsEntity} node does not have any parent, that is, {@link JsNode#parentNode} 
049  * property for a {@link JsEntity} node is always <tt>null</tt>.</p>
050  * <p>If the entity contains an unbound name space prefix, the {@link JsNode#namespaceURI} 
051  * property of the corresponding node in the {@link JsEntity} node subtree is <tt>null</tt>. 
052  * The same is <tt>true</tt> for {@link JsEntityReference} nodes that refer to this entity, 
053  * when they are created using the {@link JsDocument#createEntityReference(String)} method. 
054  * The DOM Level 2 does not support any mechanism to resolve name space prefixes.</p>
055  * <p>Note that main-stream web browsers do not support the <tt>Entity</tt> interface 
056  * declared by the DOM Core Specification. This <b>opaque</b> class inherits directly 
057  * from {@link JsNode} and for documentation purpose only.</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
062  * generated into the target codes. Re-compilers must exit with error on the operations of
063  * accessing that kind of class objects.
064  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
065  * and <tt>instanceof</tt> to it always <tt>true</tt>.
066  */
067 public class JsEntity extends JsNode
068 {
069     /**
070      * <p>An <b>internal</b> class containing membership data for its enclosing
071      * opaque class.</p>
072      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or
073      * class members.</p>
074      *
075      * @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>
076      * 
077      * @javascript Re-compilers must report error on resolving an <b>internal</b> class.
078      */
079     protected static abstract class Members extends JsClient.Node.Prototype.Members
080     {
081         /**
082          * <p>An <b>internal</b> static field defining a member ID of the field name and
083          * used internally to define a member of the same name.</p>
084          * @since 1.0
085          * @see JsEntity#publicId
086          * @see JsEntity.Member#publicId
087          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
088          */
089         public final static Mid publicId = id("publicId");
090         /**
091          * <p>An <b>internal</b> static field defining a member ID of the field name and
092          * used internally to define a member of the same name.</p>
093          * @since 1.0
094          * @see JsEntity#systemId
095          * @see JsEntity.Member#systemId
096          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
097          */
098         public final static Mid systemId = id("systemId");
099         /**
100          * <p>An <b>internal</b> static field defining a member ID of the field name and
101          * used internally to define a member of the same name.</p>
102          * @since 1.0
103          * @see JsEntity#notationName
104          * @see JsEntity.Member#notationName
105          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
106          */
107         public final static Mid notationName = id("notationName");
108     }
109     /**
110      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
111      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
112      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
113      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
114      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
115      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
116      * either circumstance, the field names must be exactly same as the member names, as 
117      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
118      * based on the field names.</p>
119      *
120      * @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>
121      * 
122      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
123      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
124      * of class objects.
125      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
126      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
127      * <pre>q.m</pre>
128      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
129      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
130      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
131      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
132      * <pre>m</pre>
133      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
134      * error on the access to <b>opaque</b> fields declared by this class under any other 
135      * circumstances.
136      */
137     public static class Member extends JsClient.Node.Prototype.Member
138     {
139         /**
140          * <p>Internally constructs a member based on a qualifying member.</p>
141          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
142          * or <b>internal</b> classes or class members.</p>
143          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
144          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
145          * declared in the declaring class of this constructor itself or its subclasses. 
146          * Under this circumstance, the field names must be exactly same as the member 
147          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
148          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
149          * to their names appending to the name resolved from the specified qualifying 
150          * member with a dot in between.</p>
151          * @param q A qualifying member
152          * @param mid The ID of the member to construct
153          * @since 1.0
154          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
155          */
156         public Member(JsObject.Member q, Mid mid) {
157             super(q, mid);
158         }
159         /**
160          * <p>Internally constructs a member without a qualifying member.</p>
161          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
162          * or <b>internal</b> classes or class members.</p>
163          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
164          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
165          * declared in <b>opaque</b> types other than the declaring class of this constructor 
166          * itself and its subclasses. Under this circumstance, the field names must be
167          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
168          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
169          * @param mid The ID of the member to construct
170          * @since 1.0
171          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
172          */
173         public Member(Mid mid) {
174             super(mid);
175         }
176         @Override
177         /**
178          * <p>Evaluates the property, represented by the current member instance, of the
179          * argument object.</p>
180          * @param o The argument object
181          * @return The value of the current member based on the object argument.
182          * @since 1.0
183          * @javascript Re-compilers must convert the instance invocation of this method into
184          * the JavaScript expression: 
185          * <pre>o.m</pre>
186          * where <tt>m</tt> is the identifier name resolved from the current member
187          * instance of the invocation.
188          */
189         public JsEntity with(ObjectLike o) {
190             return new JsEntity(super.with(o));
191         }
192 
193         /**
194          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
195          * name of this field, qualified by the current member instance of the field, and 
196          * to access the property of the name on an object.</p>
197          * <p>The property, identified by this member, of a {@link JsEntity} object 
198          * refers to a read-only string specifying the public identifier associated with 
199          * the entity, if specified. If the public identifier was not specified, this is 
200          * <tt>null</tt>.</p>
201          * @since 1.0
202          * @javascript Re-compilers must resolve the member of this instance field to the
203          * identifier of the field name appending to the identifier resolved from its 
204          * qualifying member with a dot in between.
205          */
206         public final Value.String.Member publicId = new Value.String.Member(this, Members.publicId);
207         /**
208          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
209          * name of this field, qualified by the current member instance of the field, and 
210          * to access the property of the name on an object.</p>
211          * <p>The property, identified by this member, of a {@link JsEntity} object 
212          * refers to a read-only string specifying the system identifier associated with 
213          * the entity, if specified. If the system identifier was not specified, this is 
214          * <tt>null</tt>.</p>
215          * @since 1.0
216          * @javascript Re-compilers must resolve the member of this instance field to the
217          * identifier of the field name appending to the identifier resolved from its 
218          * qualifying member with a dot in between.
219          */
220         public final Value.String.Member systemId = new Value.String.Member(this, Members.systemId);
221         /**
222          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
223          * name of this field, qualified by the current member instance of the field, and 
224          * to access the property of the name on an object.</p>
225          * <p>The property, identified by this member, of a {@link JsEntity} object 
226          * refers to a read-only string specifying the name of the notation the unparsed 
227          * entity. The property is <tt>null</tt> for a parsed entity.</p>
228          * @since 1.0
229          * @javascript Re-compilers must resolve the member of this instance field to the
230          * identifier of the field name appending to the identifier resolved from its 
231          * qualifying member with a dot in between.
232          */
233         public final Value.String.Member notationName = new Value.String.Member(this, Members.notationName);
234     }
235 
236     /**
237      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
238      * with the wrapping constructor.</p>
239      * @param var The argument of an <b>opaque</b> object.
240      * @since 1.0
241      * @javascript Re-compilers must ignore the construction operation of this constructor,
242      * that is, replacing it with its only argument.
243      */
244     public JsEntity(JsObject var) {
245         super(var);
246     }
247 
248     /**
249      * <p>An <b>opaque</b> static field defining a member that is named by the field name
250      * without a qualifying member and to access the property of the name on an object.</p>
251      * <p>The property, identified by this member, of a {@link JsEntity} object 
252      * refers to a read-only string specifying the public identifier associated with 
253      * the entity, if specified. If the public identifier was not specified, this is 
254      * <tt>null</tt>.</p>
255      * @since 1.0
256      * @javascript Re-compilers must resolve the member of this static field to the
257      * identifier of the field name.
258      */
259     public static final Value.String.Member publicId = new Value.String.Member(Members.publicId);
260     /**
261      * <p>An <b>opaque</b> static field defining a member that is named by the field name
262      * without a qualifying member and to access the property of the name on an object.</p>
263      * <p>The property, identified by this member, of a {@link JsEntity} object 
264      * refers to a read-only string specifying the system identifier associated with 
265      * the entity, if specified. If the system identifier was not specified, this is 
266      * <tt>null</tt>.</p>
267      * @since 1.0
268      * @javascript Re-compilers must resolve the member of this static field to the
269      * identifier of the field name.
270      */
271     public static final Value.String.Member systemId = new Value.String.Member(Members.systemId);
272     /**
273      * <p>An <b>opaque</b> static field defining a member that is named by the field name
274      * without a qualifying member and to access the property of the name on an object.</p>
275      * <p>The property, identified by this member, of a {@link JsEntity} object 
276      * refers to a read-only string specifying the name of the notation the unparsed 
277      * entity. The property is <tt>null</tt> for a parsed entity.</p>
278      * @since 1.0
279      * @javascript Re-compilers must resolve the member of this static field to the
280      * identifier of the field name.
281      */
282     public static final Value.String.Member notationName = new Value.String.Member(Members.notationName);
283 
284     @Override
285     /**
286      * <p>Returns the primitive value associated with the current instance, if there is one.
287      * This invocation simply returns the instance itself for the current instance is an 
288      * object and there is no primitive value for it.</p>
289      * @return The current object itself.
290      * @since 1.0
291      * @javascript Re-compilers must convert the instance invocation of this method directly
292      * into a JavaScript invocation on its current object instance without changing the 
293      * method name, but expanding variable arguments, if any, into comma-separated values. 
294      */
295     public JsEntity valueOf() {
296         return new JsEntity((JsObject)var().valueOf());
297     }
298 }