com.vaadin.terminal.gwt.client
Class ApplicationConnection

java.lang.Object
  extended by com.vaadin.terminal.gwt.client.ApplicationConnection

public class ApplicationConnection
extends Object

This is the client side communication "engine", managing client-server communication with its server side counterpart AbstractCommunicationManager. Client-side connectors receive updates from the corresponding server-side connector (typically component) as state updates or RPC calls. The connector has the possibility to communicate back with its server side counter part through RPC calls. TODO document better Entry point classes (widgetsets) define onModuleLoad().


Nested Class Summary
static class ApplicationConnection.MultiStepDuration
           
 
Field Summary
protected  boolean applicationRunning
           
static String CONNECTOR_RESOURCE_PREFIX
           
protected  boolean cssLoaded
           
static String DISABLED_CLASSNAME
           
static String ERROR_CLASSNAME_EXT
           
static String GENERATED_BODY_CLASSNAME
           
protected  int lastProcessingTime
          Holds the time spent rendering the last request
static String MODIFIED_CLASSNAME
           
static String PARAM_UNLOADBURST
           
static String REQUIRED_CLASSNAME_EXT
           
static String ROOT_ID_PARAMETER
          Name of the parameter used to transmit root ids back and forth
protected  int totalProcessingTime
          Holds the total time spent rendering requests during the lifetime of the session.
static String UIDL_REFRESH_TOKEN
          A string that, if found in a non-JSON response to a UIDL request, will cause the browser to refresh the page.
static String UIDL_SECURITY_HEADER
          Deprecated. use UIDL_SECURITY_TOKEN_ID instead
static String UIDL_SECURITY_TOKEN_ID
           
static String UPDATE_VARIABLE_INTERFACE
           
static String UPDATE_VARIABLE_METHOD
           
static char VAR_BURST_SEPARATOR
           
static char VAR_ESCAPE_CHARACTER
           
 
Constructor Summary
ApplicationConnection()
           
 
Method Summary
static String addGetParameters(String uri, String extraParams)
          Adds the get parameters to the uri and returns the new uri that contains the parameters.
 void addMethodInvocationToQueue(MethodInvocation invocation, boolean immediate)
          Adds an explicit RPC method invocation to the send queue.
 void analyzeLayouts()
          Requests an analyze of layouts, to find inconsistencies.
 void captionSizeUpdated(com.google.gwt.user.client.ui.Widget widget)
          Use to notify that the given component's caption has changed; layouts may have to be recalculated.
protected  void doAsyncUIDLRequest(String uri, String payload, com.google.gwt.http.client.RequestCallback requestCallback)
          Sends an asynchronous UIDL request to the server using the given URI.
protected  void doUidlRequest(String uri, String payload, boolean synchronous)
          Sends an asynchronous or synchronous UIDL request to the server using the given URI.
protected  void endRequest()
           
protected  String escapeBurstContents(String value)
          Encode burst separator characters in a String for transport over the network.
protected  void extendLiferaySession()
          If on Liferay and logged in, ask the client side session management JavaScript to extend the session duration.
 void forceLayout()
          This will cause re-layouting of all components.
 String getAppUri()
          Gets the application base URI.
 ApplicationConfiguration getConfiguration()
          Gets the ApplicationConfiguration for the current application.
 ServerConnector getConnector(String connectorId, int connectorType)
          Get either an existing ComponentConnector or create a new ComponentConnector with the given type and id.
static Console getConsole()
          Deprecated. Developers should use VConsole since 6.4.5
 VContextMenu getContextMenu()
          Singleton method to get instance of app's context menu.
 ComponentConnector getPaintable(UIDL uidl)
          Deprecated. 
 String getResource(String name)
          Gets a recource that has been pre-loaded via UIDL, such as custom layouts.
 RootConnector getRootConnector()
          Gets the main view
 SerializerMap getSerializerMap()
           
 String getThemeUri()
          Gets the URI for the current theme.
protected  String getUidlSecurityKey()
           
 VTooltip getVTooltip()
          Get VTooltip instance related to application connection
 boolean handleComponentRelativeSize(com.google.gwt.user.client.ui.Widget widget)
          Converts relative sizes into pixel sizes.
protected  void handleUIDLMessage(Date start, String jsonText, ValueMap json)
           
protected  void handleWhenCSSLoaded(String jsonText, ValueMap json)
           
 boolean hasActiveRequest()
          Indicates whether or not there are currently active UIDL requests.
 boolean hasEventListeners(ComponentConnector paintable, String eventIdentifier)
          Deprecated. Use ComponentState#hasEventListener(String) instead
 boolean hasEventListeners(com.google.gwt.user.client.ui.Widget widget, String eventIdentifier)
          Deprecated. 
 void init(WidgetSet widgetSet, ApplicationConfiguration cnf)
           
protected  boolean isCSSLoaded()
          Checks whether or not the CSS is loaded.
static boolean isDebugMode()
          Deprecated. use ApplicationConfiguration isDebugMode instead.
 boolean isLoadingIndicatorVisible()
          Determines whether or not the loading indicator is showing.
protected  void makeUidlRequest(String requestData, String extraParams, boolean forceSync)
          Makes an UIDL request to the server.
protected  void repaintAll()
           
 void runDescendentsLayout(com.google.gwt.user.client.ui.HasWidgets container)
          Causes a re-calculation/re-layout of all paintables in a container.
 void sendPendingVariableChanges()
          This method sends currently queued variable changes to server.
protected  void showAuthenticationError(String details)
          Shows the authentication error notification.
protected  void showCommunicationError(String details, int statusCode)
          Shows the communication error notification.
 void start()
          Starts this application.
protected  void startRequest()
           
 String translateVaadinUri(String uidlUri)
          Translates custom protocols in UIDL URI's to be recognizable by browser.
 void unregisterPaintable(ServerConnector p)
          Deprecated. 
 boolean updateComponent(com.google.gwt.user.client.ui.Widget component, UIDL uidl, boolean manageCaption)
          Deprecated. 
 void updateVariable(String paintableId, String variableName, boolean newValue, boolean immediate)
          Sends a new value for the given paintables given variable to the server.
 void updateVariable(String paintableId, String variableName, double newValue, boolean immediate)
          Sends a new value for the given paintables given variable to the server.
 void updateVariable(String paintableId, String variableName, float newValue, boolean immediate)
          Sends a new value for the given paintables given variable to the server.
 void updateVariable(String paintableId, String variableName, int newValue, boolean immediate)
          Sends a new value for the given paintables given variable to the server.
 void updateVariable(String paintableId, String variableName, long newValue, boolean immediate)
          Sends a new value for the given paintables given variable to the server.
 void updateVariable(String paintableId, String variableName, Map<String,Object> map, boolean immediate)
          Sends a new value for the given paintables given variable to the server.
 void updateVariable(String paintableId, String variableName, Object[] values, boolean immediate)
          Sends a new value for the given paintables given variable to the server.
 void updateVariable(String paintableId, String variableName, ServerConnector newValue, boolean immediate)
          Sends a new value for the given paintables given variable to the server.
 void updateVariable(String paintableId, String variableName, String[] values, boolean immediate)
          Sends a new value for the given paintables given variable to the server.
 void updateVariable(String paintableId, String variableName, String newValue, boolean immediate)
          Sends a new value for the given paintables given variable to the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONNECTOR_RESOURCE_PREFIX

public static final String CONNECTOR_RESOURCE_PREFIX
See Also:
Constant Field Values

GENERATED_BODY_CLASSNAME

public static final String GENERATED_BODY_CLASSNAME
See Also:
Constant Field Values

MODIFIED_CLASSNAME

public static final String MODIFIED_CLASSNAME
See Also:
Constant Field Values

DISABLED_CLASSNAME

public static final String DISABLED_CLASSNAME
See Also:
Constant Field Values

REQUIRED_CLASSNAME_EXT

public static final String REQUIRED_CLASSNAME_EXT
See Also:
Constant Field Values

ERROR_CLASSNAME_EXT

public static final String ERROR_CLASSNAME_EXT
See Also:
Constant Field Values

UPDATE_VARIABLE_INTERFACE

public static final String UPDATE_VARIABLE_INTERFACE
See Also:
Constant Field Values

UPDATE_VARIABLE_METHOD

public static final String UPDATE_VARIABLE_METHOD
See Also:
Constant Field Values

VAR_BURST_SEPARATOR

public static final char VAR_BURST_SEPARATOR
See Also:
Constant Field Values

VAR_ESCAPE_CHARACTER

public static final char VAR_ESCAPE_CHARACTER
See Also:
Constant Field Values

UIDL_SECURITY_TOKEN_ID

public static final String UIDL_SECURITY_TOKEN_ID
See Also:
Constant Field Values

ROOT_ID_PARAMETER

public static final String ROOT_ID_PARAMETER
Name of the parameter used to transmit root ids back and forth

See Also:
Constant Field Values

UIDL_SECURITY_HEADER

@Deprecated
public static final String UIDL_SECURITY_HEADER
Deprecated. use UIDL_SECURITY_TOKEN_ID instead
See Also:
Constant Field Values

PARAM_UNLOADBURST

public static final String PARAM_UNLOADBURST
See Also:
Constant Field Values

UIDL_REFRESH_TOKEN

public static final String UIDL_REFRESH_TOKEN
A string that, if found in a non-JSON response to a UIDL request, will cause the browser to refresh the page. If followed by a colon, optional whitespace, and a URI, causes the browser to synchronously load the URI.

This allows, for instance, a servlet filter to redirect the application to a custom login page when the session expires. For example:

 if (sessionExpired) {
     response.setHeader("Content-Type", "text/html");
     response.getWriter().write(
             myLoginPageHtml + "<!-- Vaadin-Refresh: "
                     + request.getContextPath() + " -->");
 }
 

See Also:
Constant Field Values

applicationRunning

protected boolean applicationRunning

cssLoaded

protected boolean cssLoaded

lastProcessingTime

protected int lastProcessingTime
Holds the time spent rendering the last request


totalProcessingTime

protected int totalProcessingTime
Holds the total time spent rendering requests during the lifetime of the session.

Constructor Detail

ApplicationConnection

public ApplicationConnection()
Method Detail

init

public void init(WidgetSet widgetSet,
                 ApplicationConfiguration cnf)

start

public void start()
Starts this application. Don't call this method directly - it's called by ApplicationConfiguration#startNextApplication(), which should be called once this application has started (first response received) or failed to start. This ensures that the applications are started in order, to avoid session-id problems.


extendLiferaySession

protected void extendLiferaySession()
If on Liferay and logged in, ask the client side session management JavaScript to extend the session duration. Otherwise, Liferay client side JavaScript will explicitly expire the session even though the server side considers the session to be active. See ticket #8305 for more information.


getConsole

@Deprecated
public static Console getConsole()
Deprecated. Developers should use VConsole since 6.4.5

Get the active Console for writing debug messages. May return an actual logging console, or the NullConsole if debugging is not turned on.

Returns:
the active Console

isDebugMode

@Deprecated
public static boolean isDebugMode()
Deprecated. use ApplicationConfiguration isDebugMode instead.

Checks if client side is in debug mode. Practically this is invoked by adding ?debug parameter to URI.

Returns:
true if client side is currently been debugged

getAppUri

public String getAppUri()
Gets the application base URI. Using this other than as the download action URI can cause problems in Portlet 2.0 deployments.

Returns:
application base URI

hasActiveRequest

public boolean hasActiveRequest()
Indicates whether or not there are currently active UIDL requests. Used internally to sequence requests properly, seldom needed in Widgets.

Returns:
true if there are active requests

repaintAll

protected void repaintAll()

analyzeLayouts

public void analyzeLayouts()
Requests an analyze of layouts, to find inconsistencies. Exclusively used for debugging during development.


makeUidlRequest

protected void makeUidlRequest(String requestData,
                               String extraParams,
                               boolean forceSync)
Makes an UIDL request to the server.

Parameters:
requestData - Data that is passed to the server.
extraParams - Parameters that are added as GET parameters to the url. Contains key=value pairs joined by & characters or is empty if no parameters should be added. Should not start with any special character.
forceSync - true if the request should be synchronous, false otherwise

doUidlRequest

protected void doUidlRequest(String uri,
                             String payload,
                             boolean synchronous)
Sends an asynchronous or synchronous UIDL request to the server using the given URI.

Parameters:
uri - The URI to use for the request. May includes GET parameters
payload - The contents of the request to send
synchronous - true if the request should be synchronous, false otherwise

doAsyncUIDLRequest

protected void doAsyncUIDLRequest(String uri,
                                  String payload,
                                  com.google.gwt.http.client.RequestCallback requestCallback)
                           throws com.google.gwt.http.client.RequestException
Sends an asynchronous UIDL request to the server using the given URI.

Parameters:
uri - The URI to use for the request. May includes GET parameters
payload - The contents of the request to send
requestCallback - The handler for the response
Throws:
com.google.gwt.http.client.RequestException - if the request could not be sent

handleWhenCSSLoaded

protected void handleWhenCSSLoaded(String jsonText,
                                   ValueMap json)

isCSSLoaded

protected boolean isCSSLoaded()
Checks whether or not the CSS is loaded. By default checks the size of the loading indicator element.

Returns:

showCommunicationError

protected void showCommunicationError(String details,
                                      int statusCode)
Shows the communication error notification.

Parameters:
details - Optional details for debugging.
statusCode - The status code returned for the request

showAuthenticationError

protected void showAuthenticationError(String details)
Shows the authentication error notification.

Parameters:
details - Optional details for debugging.

startRequest

protected void startRequest()

endRequest

protected void endRequest()

isLoadingIndicatorVisible

public boolean isLoadingIndicatorVisible()
Determines whether or not the loading indicator is showing.

Returns:
true if the loading indicator is visible

handleUIDLMessage

protected void handleUIDLMessage(Date start,
                                 String jsonText,
                                 ValueMap json)

addMethodInvocationToQueue

public void addMethodInvocationToQueue(MethodInvocation invocation,
                                       boolean immediate)
Adds an explicit RPC method invocation to the send queue.

Parameters:
invocation - RPC method invocation
immediate - true to trigger sending within a short time window (possibly combining subsequent calls to a single request), false to let the framework delay sending of RPC calls and variable changes until the next immediate change
Since:
7.0

sendPendingVariableChanges

public void sendPendingVariableChanges()
This method sends currently queued variable changes to server. It is called when immediate variable update must happen. To ensure correct order for variable changes (due servers multithreading or network), we always wait for active request to be handler before sending a new one. If there is an active request, we will put varible "burst" to queue that will be purged after current request is handled.


updateVariable

public void updateVariable(String paintableId,
                           String variableName,
                           ServerConnector newValue,
                           boolean immediate)
Sends a new value for the given paintables given variable to the server.

The update is actually queued to be sent at a suitable time. If immediate is true, the update is sent as soon as possible. If immediate is false, the update will be sent along with the next immediate update.

Parameters:
paintableId - the id of the paintable that owns the variable
variableName - the name of the variable
newValue - the new value to be sent
immediate - true if the update is to be sent as soon as possible

updateVariable

public void updateVariable(String paintableId,
                           String variableName,
                           String newValue,
                           boolean immediate)
Sends a new value for the given paintables given variable to the server.

The update is actually queued to be sent at a suitable time. If immediate is true, the update is sent as soon as possible. If immediate is false, the update will be sent along with the next immediate update.

Parameters:
paintableId - the id of the paintable that owns the variable
variableName - the name of the variable
newValue - the new value to be sent
immediate - true if the update is to be sent as soon as possible

updateVariable

public void updateVariable(String paintableId,
                           String variableName,
                           int newValue,
                           boolean immediate)
Sends a new value for the given paintables given variable to the server.

The update is actually queued to be sent at a suitable time. If immediate is true, the update is sent as soon as possible. If immediate is false, the update will be sent along with the next immediate update.

Parameters:
paintableId - the id of the paintable that owns the variable
variableName - the name of the variable
newValue - the new value to be sent
immediate - true if the update is to be sent as soon as possible

updateVariable

public void updateVariable(String paintableId,
                           String variableName,
                           long newValue,
                           boolean immediate)
Sends a new value for the given paintables given variable to the server.

The update is actually queued to be sent at a suitable time. If immediate is true, the update is sent as soon as possible. If immediate is false, the update will be sent along with the next immediate update.

Parameters:
paintableId - the id of the paintable that owns the variable
variableName - the name of the variable
newValue - the new value to be sent
immediate - true if the update is to be sent as soon as possible

updateVariable

public void updateVariable(String paintableId,
                           String variableName,
                           float newValue,
                           boolean immediate)
Sends a new value for the given paintables given variable to the server.

The update is actually queued to be sent at a suitable time. If immediate is true, the update is sent as soon as possible. If immediate is false, the update will be sent along with the next immediate update.

Parameters:
paintableId - the id of the paintable that owns the variable
variableName - the name of the variable
newValue - the new value to be sent
immediate - true if the update is to be sent as soon as possible

updateVariable

public void updateVariable(String paintableId,
                           String variableName,
                           double newValue,
                           boolean immediate)
Sends a new value for the given paintables given variable to the server.

The update is actually queued to be sent at a suitable time. If immediate is true, the update is sent as soon as possible. If immediate is false, the update will be sent along with the next immediate update.

Parameters:
paintableId - the id of the paintable that owns the variable
variableName - the name of the variable
newValue - the new value to be sent
immediate - true if the update is to be sent as soon as possible

updateVariable

public void updateVariable(String paintableId,
                           String variableName,
                           boolean newValue,
                           boolean immediate)
Sends a new value for the given paintables given variable to the server.

The update is actually queued to be sent at a suitable time. If immediate is true, the update is sent as soon as possible. If immediate is false, the update will be sent along with the next immediate update.

Parameters:
paintableId - the id of the paintable that owns the variable
variableName - the name of the variable
newValue - the new value to be sent
immediate - true if the update is to be sent as soon as possible

updateVariable

public void updateVariable(String paintableId,
                           String variableName,
                           Map<String,Object> map,
                           boolean immediate)
Sends a new value for the given paintables given variable to the server.

The update is actually queued to be sent at a suitable time. If immediate is true, the update is sent as soon as possible. If immediate is false, the update will be sent along with the next immediate update.

Parameters:
paintableId - the id of the paintable that owns the variable
variableName - the name of the variable
map - the new values to be sent
immediate - true if the update is to be sent as soon as possible

updateVariable

public void updateVariable(String paintableId,
                           String variableName,
                           String[] values,
                           boolean immediate)
Sends a new value for the given paintables given variable to the server. The update is actually queued to be sent at a suitable time. If immediate is true, the update is sent as soon as possible. If immediate is false, the update will be sent along with the next immediate update. A null array is sent as an empty array.

Parameters:
paintableId - the id of the paintable that owns the variable
variableName - the name of the variable
values - the new value to be sent
immediate - true if the update is to be sent as soon as possible

updateVariable

public void updateVariable(String paintableId,
                           String variableName,
                           Object[] values,
                           boolean immediate)
Sends a new value for the given paintables given variable to the server. The update is actually queued to be sent at a suitable time. If immediate is true, the update is sent as soon as possible. If immediate is false, the update will be sent along with the next immediate update.

A null array is sent as an empty array.

Parameters:
paintableId - the id of the paintable that owns the variable
variableName - the name of the variable
values - the new value to be sent
immediate - true if the update is to be sent as soon as possible

escapeBurstContents

protected String escapeBurstContents(String value)
Encode burst separator characters in a String for transport over the network. This protects from separator injection attacks.

Parameters:
value - to encode
Returns:
encoded value

runDescendentsLayout

public void runDescendentsLayout(com.google.gwt.user.client.ui.HasWidgets container)
Causes a re-calculation/re-layout of all paintables in a container.

Parameters:
container -

forceLayout

public void forceLayout()
This will cause re-layouting of all components. Mainly used for development. Published to JavaScript.


handleComponentRelativeSize

public boolean handleComponentRelativeSize(com.google.gwt.user.client.ui.Widget widget)
Converts relative sizes into pixel sizes.

Parameters:
child -
Returns:
true if the child has a relative size

getPaintable

@Deprecated
public ComponentConnector getPaintable(UIDL uidl)
Deprecated. 


getConnector

public ServerConnector getConnector(String connectorId,
                                    int connectorType)
Get either an existing ComponentConnector or create a new ComponentConnector with the given type and id. If a ComponentConnector with the given id already exists, returns it. Otherwise creates and registers a new ComponentConnector of the given type.

Parameters:
connectorId - Id of the paintable
connectorType - Type of the connector, as passed from the server side
Returns:
Either an existing ComponentConnector or a new ComponentConnector of the given type

getResource

public String getResource(String name)
Gets a recource that has been pre-loaded via UIDL, such as custom layouts.

Parameters:
name - identifier of the resource to get
Returns:
the resource

getContextMenu

public VContextMenu getContextMenu()
Singleton method to get instance of app's context menu.

Returns:
VContextMenu object

translateVaadinUri

public String translateVaadinUri(String uidlUri)
Translates custom protocols in UIDL URI's to be recognizable by browser. All uri's from UIDL should be routed via this method before giving them to browser due URI's in UIDL may contain custom protocols like theme://.

Parameters:
uidlUri - Vaadin URI from uidl
Returns:
translated URI ready for browser

getThemeUri

public String getThemeUri()
Gets the URI for the current theme. Can be used to reference theme resources.

Returns:
URI to the current theme

getUidlSecurityKey

protected String getUidlSecurityKey()

captionSizeUpdated

public void captionSizeUpdated(com.google.gwt.user.client.ui.Widget widget)
Use to notify that the given component's caption has changed; layouts may have to be recalculated.

Parameters:
component - the Paintable whose caption has changed

getRootConnector

public RootConnector getRootConnector()
Gets the main view

Returns:
the main view

getConfiguration

public ApplicationConfiguration getConfiguration()
Gets the ApplicationConfiguration for the current application.

Returns:
the configuration for this application
See Also:
ApplicationConfiguration

hasEventListeners

@Deprecated
public boolean hasEventListeners(ComponentConnector paintable,
                                            String eventIdentifier)
Deprecated. Use ComponentState#hasEventListener(String) instead

Checks if there is a registered server side listener for the event. The list of events which has server side listeners is updated automatically before the component is updated so the value is correct if called from updatedFromUIDL.

Parameters:
paintable - The connector to register event listeners for
eventIdentifier - The identifier for the event
Returns:
true if at least one listener has been registered on server side for the event identified by eventIdentifier.

addGetParameters

public static String addGetParameters(String uri,
                                      String extraParams)
Adds the get parameters to the uri and returns the new uri that contains the parameters.

Parameters:
uri - The uri to which the parameters should be added.
extraParams - One or more parameters in the format "a=b" or "c=d&e=f". An empty string is allowed but will not modify the url.
Returns:
The modified URI with the get parameters in extraParams added.

unregisterPaintable

@Deprecated
public void unregisterPaintable(ServerConnector p)
Deprecated. 


getVTooltip

public VTooltip getVTooltip()
Get VTooltip instance related to application connection

Returns:
VTooltip instance

updateComponent

@Deprecated
public boolean updateComponent(com.google.gwt.user.client.ui.Widget component,
                                          UIDL uidl,
                                          boolean manageCaption)
Deprecated. 

Method provided for backwards compatibility. Duties previously done by this method is now handled by the state change event handler in AbstractComponentConnector. The only function this method has is to return true if the UIDL is a "cached" update.

Parameters:
component -
uidl -
manageCaption -
Returns:

hasEventListeners

@Deprecated
public boolean hasEventListeners(com.google.gwt.user.client.ui.Widget widget,
                                            String eventIdentifier)
Deprecated. 


getSerializerMap

public SerializerMap getSerializerMap()


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.