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 jsx.http.rpc.remote;
021 
022 import js.ArrayLike;
023 import js.Index;
024 import js.ObjectLike;
025 
026 /**
027  * <p>An abstract base class for remote reflect service providers.</p>
028  * <p>Note that a remote reflect service provider is also a {@link Remote} object.</p>
029  * 
030  * @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>
031  */
032 public abstract class RemoteReflector extends Remote
033 {
034     /**
035      * <p>The {@link Index} of the resource locator for remote reflect services.</p>
036      * @since 1.0
037      */
038     protected final static Index<String> URL = new Index<String>(3);
039 
040     /**
041      * <p>A typical constructor for a {@link RemoteReflector} object.</p>
042      * @param o An initializer for configuration.
043      * @since 1.0
044      */
045     protected RemoteReflector(ObjectLike o) {
046         super(o);
047     }
048 
049     /**
050      * <p>Gets the resource locator for the current reflector.</p>
051      * @return The resource locator for the current reflector.
052      * @since 1.0
053      */
054     public final String url() {
055         return string(this, URL);
056     }
057 
058     /**
059      * <p>A service type for a remote reflect service.</p>
060      * <p>This type of service is to register a remote reflector.</p>
061      * @since 1.0
062      */
063     public final static int REGISTER          = 0;
064     /**
065      * <p>A service type for a remote reflect service.</p>
066      * <p>This type of service is to increase reference count of remote objects.</p>
067      * @since 1.0
068      */
069     public final static int INCREASE          = 1;
070     /**
071      * <p>A service type for a remote reflect service.</p>
072      * <p>This type of service is to decrease reference count of remote objects.</p>
073      * @since 1.0
074      */
075     public final static int DECREASE          = 2;
076     /**
077      * <p>A service type for a remote reflect service.</p>
078      * <p>This type of service is to load a remote class.</p>
079      * @since 1.0
080      */
081     public final static int FOR_NAME          = 3;
082     /**
083      * <p>A service type for a remote reflect service.</p>
084      * <p>This type of service is to create an instance of a remote class.</p>
085      * @since 1.0
086      */
087     public final static int NEW_INSTANCE      = 4;
088     /**
089      * <p>A service type for a remote reflect service.</p>
090      * <p>This type of service is to get the remote class of a remote object.</p>
091      * @since 1.0
092      */
093     public final static int GET_REMOTE_CLASS  = 5;
094     /**
095      * <p>A service type for a remote reflect service.</p>
096      * <p>This type of service is to get an element of a remote array.</p>
097      * @since 1.0
098      */
099     public final static int GET_ARRAY_ELEMENT = 6;
100     /**
101      * <p>A service type for a remote reflect service.</p>
102      * <p>This type of service is to get the length of a remote array.</p>
103      * @since 1.0
104      */
105     public final static int GET_ARRAY_LENGTH  = 7;
106     /**
107      * <p>A service type for a remote reflect service.</p>
108      * <p>This type of service is to set the length of a remote array.</p>
109      * @since 1.0
110      */
111     public final static int SET_ARRAY_ELEMENT = 8;
112     /**
113      * <p>A service type for a remote reflect service.</p>
114      * <p>This type of service is to get a remote field of a remote object.</p>
115      * @since 1.0
116      */
117     public final static int GET_FIELD         = 9;
118     /**
119      * <p>A service type for a remote reflect service.</p>
120      * <p>This type of service is to evaluate a remote field.</p>
121      * @since 1.0
122      */
123     public final static int GET               = 10;
124     /**
125      * <p>A service type for a remote reflect service.</p>
126      * <p>This type of service is to get a remote method of a remote object.</p>
127      * @since 1.0
128      */
129     public final static int GET_METHOD        = 11;
130     /**
131      * <p>A service type for a remote reflect service.</p>
132      * <p>This type of service is to invoke a remote method.</p>
133      * @since 1.0
134      */
135     public final static int INVOKE            = 12;
136 
137     /**
138      * <p>Increases remote reference count for a remote object.</p>
139      * @param args An array of arguments. Only the first one is used here.
140      * @since 1.0
141      */
142     public abstract void increase(ArrayLike<Remote> args);
143     /**
144      * <p>Decreases remote reference count for a remote object.</p>
145      * @param args An array of arguments. Only the first one is used here.
146      * @since 1.0
147      */
148     public abstract void decrease(ArrayLike<Remote> args);
149     /**
150      * <p>Registers the current reflector.</p>
151      * @return A registered version of this reflector.
152      * @since 1.0
153      */
154     public abstract RemoteReflector register();
155     /**
156      * <p>Loads a remote class by the class name.</p>
157      * @param name A Java class name.
158      * @return The newly created remote class with the class name.
159      * @since 1.0
160      */
161     public abstract Remote forName(String name);
162     /**
163      * <p>Gets the remote class for a remote object.</p>
164      * @param o A remote object.
165      * @return The remote class for the remote object.
166      * @since 1.0
167      */
168     public abstract Remote getRemoteClass(Remote o);
169     /**
170      * <p>Creates a remote instance of a remote class.</p>
171      * @param o The remote class.
172      * @return The newly created remote object.
173      * @since 1.0
174      */
175     public abstract Remote newInstance(Remote o);
176     /**
177      * <p>Gets an element of a remote array.</p>
178      * @param o The remote array.
179      * @param i The array index for the element.
180      * @return A remote value or object.
181      * @since 1.0
182      */
183     public abstract Remote getArrayElement(Remote o, int i);
184     /**
185      * <p>Gets the current length of a remote array.</p>
186      * @param o The remote array.
187      * @return A remote value for the length.
188      * @since 1.0
189      */
190     public abstract Remote getArrayLength(Remote o);
191     /**
192      * <p>Sets an element of a remote array.</p>
193      * @param o The remote array.
194      * @param i The array index for the element.
195      * @param v The new value for the element.
196      * @return A remote value or object.
197      * @since 1.0
198      */
199     public abstract Remote setArrayElement(Remote o, int i, Remote v);
200     /**
201      * <p>Gets a remote field.</p>
202      * @param o The remote object for the base.
203      * @param name The name for the field.
204      * @return A remote field.
205      * @since 1.0
206      */
207     public abstract Remote getField(Remote o, String name);
208     /**
209      * <p>Evaluates a remote static field.</p>
210      * @param o The remote static field.
211      * @return A remote value or object.
212      * @since 1.0
213      */
214     public abstract Remote get(Remote o);
215     /**
216      * <p>Evaluates a remote instance field.</p>
217      * @param o The remote instance field.
218      * @param base The remote object for the base.
219      * @return A remote value or object.
220      * @since 1.0
221      */
222     public abstract Remote get(Remote o, Remote base);
223     /**
224      * <p>Gets a remote method.</p>
225      * @param o The remote object for the base.
226      * @param name The name for the method.
227      * @return A remote method.
228      * @since 1.0
229      */
230     public abstract Remote getMethod(Remote o, String name);
231     /**
232      * <p>Gets a remote method.</p>
233      * @param o The remote object for the base.
234      * @param name The name for the method.
235      * @param types An array of argument types for the remote method.
236      * @return A remote method.
237      * @since 1.0
238      */
239     public abstract Remote getMethod(Remote o, String name, ArrayLike<String> types);
240     /**
241      * <p>Invokes a remote method without arguments.</p>
242      * @param o The remote method.
243      * @return A remote value or object returned from the remote method invocation.
244      * @since 1.0
245      */
246     public abstract Remote invoke(Remote o);
247     /**
248      * <p>Invokes a remote method with arguments.</p>
249      * @param o The remote method.
250      * @param args An array of arguments.
251      * @return A remote value or object returned from the remote method invocation.
252      * @since 1.0
253      */
254     public abstract Remote invoke(Remote o, ArrayLike<Remote> args);
255 }