001package votorola.a.web.gwt; // Copyright 2012-2013, Michael Allan.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE.
002
003import com.google.gwt.core.client.GWT;
004import com.google.gwt.user.client.Window;
005import votorola.g.web.gwt.*;
006
007
008/** The GWT library module for Votorola specific application code.  An instance of this
009  * class is automatically constructed and invoked per module definition <a
010  * href='../../../../../a/AMod.gwt.xml' target='_top'>AMod.gwt.xml</a>.  It then calls
011  * global JavaScript function <code>voGWTConfig.a</code> if it is defined.  Here is an
012  * example function definition suitable for use in the configuration script {@linkplain
013  * GWTConfig gwt.js}:<pre>
014  *
015  *     voGWTConfig.a = function()
016  *     {
017  *         a_web_gwt_App_setServletContextLocation( 'http://YOUR.DOM:8080/v' );
018  *         a_web_gwt_PollwikiG_setLocation( 'http://<var>YOUR.DOM</var>/wiki' );
019  *         a_web_gwt_PollwikiG_setPipeRecognizer( 'PREFIX', 'SUFFIX' );
020  *         // and so on
021  *     };</pre>
022  *
023  *     @see <a href='../../../../votorola/a/web/gwt/class-use/GWTConfigCallback.html'
024  *       >List of GWTConfigCallback methods</a>
025  */
026public final @GWTConfig class AMod implements EntryPointS
027{
028
029
030    /** Answers whether this module's {@linkplain GWTConfigCallback configurable classes} are
031      * currently being forced to initialize in preparation for configuration.  This is
032      * for asserting in boilerplate code that is liable to be incorrectly copied.  If you
033      * see the corresponding assertion error, then simply add the offending class to
034      * {@linkplain #onModuleLoad() onModuleLoad}'s forced initialization.
035      */
036    static boolean isForcedInit() { return isForcedInit; }
037
038
039        private static boolean isForcedInit;
040
041
042
043   // - E n t r y - P o i n t ------------------------------------------------------------
044
045
046    public void onModuleLoad()
047    {
048     // if( 1 == 2 ) // TEST
049        GWT.setUncaughtExceptionHandler( new GWT.UncaughtExceptionHandler()
050        {
051            public void onUncaughtException( final Throwable t )
052            {
053                GWTX.handleUncaughtException( t );
054            }
055        });
056        isForcedInit = true;
057        try // force class init prior to callback from config script gwt.js
058        {
059            App.forceInitClass();
060            PollwikiG.forceInitClass();
061        }
062        finally { isForcedInit = false; }
063        configureJS();
064        new App();
065        EntryPointS.U.schedule( AMod.this );
066    }
067
068
069
070   // - S c h e d u l e r . S c h e d u l e d - C o m m a n d ----------------------------
071
072
073    public void execute()
074    {
075        if( App.getServletContextLocation() == null )
076        {
077            Window.alert(  // fail quickly
078              "no servlet context, did page author call a_web_gwt_App_setServletContextLocation?" );
079        }
080    }
081
082
083
084//// P r i v a t e ///////////////////////////////////////////////////////////////////////
085
086
087    private static native void configureJS()
088    /*-{
089        var f;
090        try{ f = $wnd.voGWTConfig.a; } catch( e ) {} // in case parents undefined
091        if( f ) f();
092    }-*/;
093
094
095}