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;
021 
022 import java.applet.Applet;
023 
024 /**
025  * <p>A <b>normal</b> class extended to develop JS applets (also called JsApplets) which 
026  * can be re-compiled by third-party JS re-compilers into JavaScript applications (also 
027  * called scriptlets) as well as loaded and run directly with <tt>JS Simulation 
028  * (packed as sim.jar)</tt> as normal Java applets.</p>
029  * <p>Developers are only expected to extend this class to create JS applets and override
030  * its abstract method {@link JsApplet#onReady()} to make entry points for them. The members 
031  * of this class, except for this abstract method and {@link JsApplet#start()}, are all 
032  * <b>internal</b>. The superclass <tt>java.applet</tt> is obviously <b>internal</b>. Any 
033  * use, from the entry points, of the internal members shall cause re-compilation failure.</p>
034  *
035  * @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>
036  * 
037  * @javascript Re-compilers must first load the subclasses of this one which have concrete 
038  * methods overriding {@link JsApplet#onReady()}, replacing the naming references to this 
039  * class with that to the class <tt>com.javajavascript.emu.scriptlet</tt>, which is also 
040  * <b>normal</b>, then resolve those subclasses and start re-compilation processes from 
041  * the static <tt>onLoad(JsApplet)</tt> method of that class. 
042  */
043 
044 public abstract class JsApplet extends Applet
045 {
046     private static final long serialVersionUID = -581207089484628883L;
047 
048     /**
049      * <p>Internally initializes this Java applet.</p>
050      * <p>This method is <b>internal</b> and can only be called by JRE plugin at browser client.</p>
051      * @since 1.0
052      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
053      */
054     @Override
055     public final void init() {
056         Js.init(org.jscripter.sim.client.Embeded.create(this));
057     }
058 
059     /**
060      * <p>Internally destroys this Java applet.</p>
061      * <p>This method is <b>internal</b> and can only be called by JRE plugin at browser client.</p>
062      * @since 1.0
063      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
064      */
065     @Override
066     public final void destroy() {
067         Js.destroy();
068     }
069 
070     /**
071      * <p>Starts this Java applet.</p>
072      * <p>This method is <b>normal</b> but only expected to be called by JRE plugin at 
073      * browser client.</p>
074      * @since 1.0
075      */
076     @Override
077     public final void start() {
078         synchronized(JsApplet.class) {
079             onReady();
080         }
081     }
082 
083     /**
084      * <p>The entry point of the extended JS applet.</p>
085      * <p>The method is <b>normal</b> but not expected to be called. A concrete method 
086      * overriding this one is also <b>normal</b>, so we must write "normal" Java statements 
087      * to start the applet and re-compilation shall start its processing from there.</p>
088      * @since 1.0
089      * @javascript A Re-compiler must start the process from the concrete overriding method 
090      * in an extended JS applet and make an explicit invocation of it.
091      */
092     public abstract void onReady();
093 
094     /**
095      * <p>Internally stops this Java applet.</p>
096      * <p>This method is <b>internal</b> and can only be called by JRE plugin at browser client.</p>
097      * @since 1.0
098      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
099      */
100     @Override
101     public final void stop() {
102     }
103 
104     /**
105      * <p>Internally finalizes this Java applet.</p>
106      * <p>This method is <b>internal</b> and can only be called by JRE plugin at browser client.</p>
107      * @since 1.0
108      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
109      */
110     @Override
111     public final void finalize() {}
112 }