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.Vars;
024 import jsx.Code;
025 import jsx.core.ArrayLikes;
026 
027 /**
028  * <p>An abstract base class for client-side non-disposable reflected objects that are finalized 
029  * automatically once out of reference.</p>
030  * 
031  * @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>
032  */
033 public abstract class Objective
034 {
035     /**
036      * <p>The package name <tt>java.lang</tt>.</p>
037      * @since 1.0
038      */
039     public final static String JAVA_LANG = Code.ref("java", "lang");
040     /**
041      * <p>The class name for {@link java.lang.Class}.</p>
042      * @since 1.0
043      */
044     public final static String JAVA_LANG_CLASS = Code.ref(JAVA_LANG, "Class");
045     /**
046      * <p>The class name for {@link java.lang.Object}.</p>
047      * @since 1.0
048      */
049     public final static String JAVA_LANG_OBJECT = Code.ref(JAVA_LANG, "Object");
050     /**
051      * <p>The class name for {@link java.lang.String}.</p>
052      * @since 1.0
053      */
054     public final static String JAVA_LANG_STRING = Code.ref(JAVA_LANG, "String");
055     /**
056      * <p>The package name <tt>java.lang.reflect</tt>.</p>
057      * @since 1.0
058      */
059     public final static String JAVA_LANG_REFLECT = Code.ref(JAVA_LANG, "reflect");
060     /**
061      * <p>The class name for {@link java.lang.reflect.Field}.</p>
062      * @since 1.0
063      */
064     public final static String JAVA_LANG_REFLECT_FIELD = Code.ref(JAVA_LANG_REFLECT, "Field");
065     /**
066      * <p>The class name for {@link java.lang.reflect.Method}.</p>
067      * @since 1.0
068      */
069     public final static String JAVA_LANG_REFLECT_METHOD = Code.ref(JAVA_LANG_REFLECT, "Method");
070 
071     /**
072      * <p>The {@link Reflector} object associated with the current {@link Objective} object.</p>
073      * @since 1.0
074      */
075     public final Reflector reflector;
076     /**
077      * <p>The underlying {@link Remote} object associated with the current {@link Objective} object.</p>
078      * @since 1.0
079      */
080     public final Remote remote;
081 
082     /**
083      * <p>The typical constructor for an {@link Objective} object.</p>
084      * @param reflector The {@link Reflector} object associated with the {@link Objective} object 
085      * being constructed.
086      * @param remote The underlying {@link Remote} object associated with the {@link Objective} 
087      * object being constructed.
088      * @since 1.0
089      */
090     protected Objective(Reflector reflector, Remote remote) {
091         this.reflector = reflector;
092         this.remote = remote;
093     }
094 
095     /**
096      * <p>Finalizes this object when all the references to it are out of scope.</p>
097      * <p>This method decreases the reference count of the remote object that reflects this one 
098      * by calling {@link Reflector#decrease(ArrayLike, jsx.Returnable)} without a 
099      * {@link jsx.Returnable}.</p>
100      * @since 1.0
101      */
102     @Override
103     protected void finalize() {
104         reflector.decrease(cat(), null);
105     }
106 
107     /**
108      * <p>Concatenates a {@link Remote} object to a new array to create an 
109      * array of arguments for calling remote object services.</p>
110      * @param remote A {@link Remote} object.
111      * @return An array of arguments for calling remote object services.
112      * @since 1.0
113      */
114     public static final ArrayLike<Remote> cat(Remote remote) {
115         return new Vars<Remote>().add(remote).var();
116     }
117 
118     /**
119      * <p>Concatenates the underlying {@link Remote} object to a new array to create an 
120      * array of arguments for calling remote object services.</p>
121      * @return An array of arguments for calling remote object services.
122      * @since 1.0
123      */
124     public final ArrayLike<Remote> cat() {
125         return cat(remote);
126     }
127 
128     /**
129      * <p>Concatenates the underlying {@link Remote} object to the given array to create an 
130      * array of arguments for calling remote object services.</p>
131      * @param args An array of {@link Remote} objects.
132      * @return The new array of arguments for calling remote object services.
133      * @since 1.0
134      */
135     public final ArrayLike<Remote> cat(ArrayLike<Remote> args) {
136         return ArrayLikes.concat(cat(), args);
137     }
138 
139     /**
140      * <p>Concatenates the underlying {@link Remote} object together with that of anther given
141      * {@link Objective} object to a new array to create an array of arguments for calling 
142      * remote object services.</p>
143      * @param o Another {@link Objective} object.
144      * @return An array of arguments for calling remote object services.
145      * @since 1.0
146      */
147     public final ArrayLike<Remote> cat(Objective o) {
148         return cat(o.cat());
149     }
150 }