package votorola.a.web.gwt; // Copyright 2010-2012, 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. import com.google.gwt.core.client.*; import com.google.gwt.event.shared.GwtEvent; import com.google.gwt.event.shared.HasHandlers; import com.google.gwt.jsonp.client.JsonpRequestBuilder; import votorola.g.lang.*; import votorola.g.web.gwt.*; import votorola.g.web.gwt.event.*; /** A GWT web application under Votorola. State changes are expected as late as the * "finally" phase. Related events are subsequently dispatched in the "deferred" phase * where they appear atomic regardless of the number of state variables involved. */ public final class App implements HasHandlers { /** Does nothing itself but the call forces static initialization of this class. */ static void forceInitClass() {} /** The single instance of App. */ public static App i() { return instance; } private static App instance; { // constructed by AMod if( instance != null ) throw new IllegalStateException(); instance = App.this; } // ------------------------------------------------------------------------------------ /** The URL of the vote-server's context on the static mirror, or null if the context * is not statically mirrored. The location is specified without a trailing slash * (/). * * @see #staticContextLocation() * @see #setMirroredContextLocation(String) */ public static @GWTConfigCallback String getMirroredContextLocation() { return mirroredContextLocation; } private static String mirroredContextLocation; private static native void exposeMirroredContextLocation() /*-{ $wnd.a_web_gwt_App_getMirroredContextLocation = $entry( @votorola.a.web.gwt.App::getMirroredContextLocation() ); $wnd.a_web_gwt_App_setMirroredContextLocation = $entry( @votorola.a.web.gwt.App::setMirroredContextLocation(Ljava/lang/String;) ); }-*/; static { assert AMod.isForcedInit(): "forced init " + App.class.getName(); exposeMirroredContextLocation(); } /** Sets the URL of the vote-server's context on the static mirror. Call it from * the global configuration function {@linkplain AMod voGWTConfig.a} in this * manner:
   a_web_gwt_App_setMirroredContextLocation( 'http://HOST-NAME/PATH' );
          *       // default is null, meaning no static mirror
* *

The default value is appropriate for an out-of-the-box test deployment in a * servlet container such as Tomcat or Jetty. For an online vote-server it is * often more flexible and efficient to serve the static web pages * (like CONTEXT/xf/default.html) * and resource files (JavaScript, * CSS, and so forth) from a static web server such as Apache httpd. Here is an * example of that:

* * @throws IllegalArgumentException if the location ends with a slash '/' * character. * @see #getMirroredContextLocation() */ public static @GWTConfigCallback void setMirroredContextLocation( final String s ) { if( s.endsWith( "/" )) throw new IllegalArgumentException( "location ends with '/'" ); mirroredContextLocation = s; } /** The URL of the vote-server's context on the servlet container (Tomcat), without a * trailing slash (/). * * @see #staticContextLocation() * @see #setServletContextLocation(String) */ public static @GWTConfigCallback String getServletContextLocation() { return servletContextLocation; } private static String servletContextLocation; private static native void exposeServletContextLocation() /*-{ $wnd.a_web_gwt_App_getServletContextLocation = $entry( @votorola.a.web.gwt.App::getServletContextLocation() ); $wnd.a_web_gwt_App_setServletContextLocation = $entry( @votorola.a.web.gwt.App::setServletContextLocation(Ljava/lang/String;) ); }-*/; static { assert AMod.isForcedInit(): "forced init " + App.class.getName(); exposeServletContextLocation(); } /** Sets the URL of the vote-server's context on the servlet container (Tomcat). * Call it from the global configuration function {@linkplain AMod * voGWTConfig.a} in this manner:
   a_web_gwt_App_setServletContextLocation(
          *     'http://http://HOST-NAME:8080/VOTE-SERVER-NAME' );
          *     // there is no dependable default, you should set a value
* * @throws IllegalArgumentException if the location ends with a slash '/' * character. * @see #getServletContextLocation() */ public static @GWTConfigCallback void setServletContextLocation( final String s ) { if( s.endsWith( "/" )) throw new IllegalArgumentException( "location ends with '/'" ); servletContextLocation = s; } /** The name of the authenticated user if known, otherwise null. The value is bound via * the {@linkplain GWTX#bus() event bus} to property name username. * * @see votorola.a.voter.IDPair#username() * @see #setUsername(String) */ public static @GWTConfigCallback String getUsername() { return username; } private static String username; private static native void exposeUsername() /*-{ $wnd.a_web_gwt_App_getUsername = $entry( @votorola.a.web.gwt.App::getUsername() ); $wnd.a_web_gwt_App_setUsername = $entry( @votorola.a.web.gwt.App::setUsername(Ljava/lang/String;) ); }-*/; static { assert AMod.isForcedInit(): "forced init " + App.class.getName(); exposeUsername(); } /** Sets the name of the authenticated user. This configuration method is for * developers. Call it from the global configuration function {@linkplain * AMod voGWTConfig.a} like this for example:
   a_web_gwt_App_setUsername( 'Joe-GmailCom' ); // otherwise null
* * @see #getUsername() */ public static @GWTConfigCallback void setUsername( String newUsername ) { if( newUsername == null ) newUsername = username; if( ObjectX.nullEquals( username, newUsername )) return; username = newUsername; if( instance != null ) instance.gun.schedule( new PropertyChange( "username" )); } /** A common JSONP request builder with a default configuration. Do not change the * configuration. */ public JsonpRequestBuilder jsonp() { return jsonp; } private final JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); /** A common JSONP request builder configured for WAP requests. Do not change the * configuration. * * @see votorola.a.web.wap.WAP */ public JsonpRequestBuilder jsonpWAP() { return jsonpWAP; } private final JsonpRequestBuilder jsonpWAP = new JsonpRequestBuilder(); { jsonpWAP.setCallbackParam( "wCallback" ); } /** The localized messages for package {@linkplain votorola.a a}. */ public votorola.a.locale.gwt.A mesA() { return mesA; } private final votorola.a.locale.gwt.A mesA = (votorola.a.locale.gwt.A)GWT.create( votorola.a.locale.gwt.A.class ); /** The localized messages for package {@linkplain votorola.s s}. */ public votorola.a.locale.gwt.S mesS() { return mesS; } private final votorola.a.locale.gwt.S mesS = (votorola.a.locale.gwt.S)GWT.create( votorola.a.locale.gwt.S.class ); /** The pollwiki associated with the vote-server. */ public PollwikiG pollwiki() { return pollwiki; } private final PollwikiG pollwiki = new PollwikiG(); /** Returns the preferred location for fetching static files. This is on the mirror * if there is a mirror, otherwise the servlet container. * * @see #getMirroredContextLocation() * @see #getServletContextLocation() */ public String staticContextLocation() { return mirroredContextLocation == null? servletContextLocation: mirroredContextLocation; } // - H a s - H a n d l e r s ---------------------------------------------------------- public void fireEvent( final GwtEvent e ) { GWTX.i().bus().fireEventFromSource( e, App.this ); } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private final DelayedEventGun gun = new DelayedEventGun( /*source*/App.this, CoalescingSchedulerS.DEFERRED ); }