com.vaadin.server
Class VaadinService

java.lang.Object
  extended by com.vaadin.server.VaadinService
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
VaadinPortletService, VaadinServletService

public abstract class VaadinService
extends java.lang.Object
implements java.io.Serializable

Provide deployment specific settings that are required outside terminal specific code.

Since:
7.0
Author:
Vaadin Ltd.
See Also:
Serialized Form

Field Summary
static java.lang.String URL_PARAMETER_CLOSE_APPLICATION
          Deprecated. Only supported for LegacyApplication.
static java.lang.String URL_PARAMETER_RESTART_APPLICATION
          Deprecated. Only supported for LegacyApplication.
 
Constructor Summary
VaadinService(DeploymentConfiguration deploymentConfiguration)
          Creates a new vaadin service based on a deployment configuration
 
Method Summary
 void addSessionDestroyListener(SessionDestroyListener listener)
          Adds a listener that gets notified when a Vaadin service session that has been initialized for this service is destroyed.
 void addSessionInitListener(SessionInitListener listener)
          Adds a listener that gets notified when a new Vaadin service session is initialized for this service.
protected abstract  AbstractCommunicationManager createCommunicationManager(VaadinServiceSession session)
          Create a communication manager to use for the given service session.
protected  VaadinServiceSession createVaadinSession(VaadinRequest request)
          Creates a new Vaadin service session.
 UI findUI(VaadinRequest request)
          Finds the UI that belongs to the provided request.
 VaadinServiceSession findVaadinSession(VaadinRequest request)
          Attempts to find a Vaadin service session associated with this request.
 void fireSessionDestroy(VaadinServiceSession vaadinSession)
           
 AddonContext getAddonContext()
           
 java.util.Iterator<AddonContextListener> getAddonContextListeners()
           
protected  java.net.URL getApplicationUrl(VaadinRequest request)
          Deprecated. Only used to support LegacyApplication.
abstract  java.io.File getBaseDirectory()
          Returns the context base directory.
 java.lang.ClassLoader getClassLoader()
          Get the class loader to use for loading classes loaded by name, e.g.
abstract  java.lang.String getConfiguredTheme(VaadinRequest request)
          Gets the theme that is configured for this deployment, e.g.
abstract  java.lang.String getConfiguredWidgetset(VaadinRequest request)
          Gets the widgetset that is configured for this deployment, e.g.
static VaadinService getCurrent()
          Gets the currently used Vaadin service.
static VaadinRequest getCurrentRequest()
          Gets the currently processed Vaadin request.
static VaadinResponse getCurrentResponse()
          Gets the currently processed Vaadin request.
 DeploymentConfiguration getDeploymentConfiguration()
          Gets the deployment configuration.
protected  VaadinServiceSession getExistingSession(VaadinRequest request, boolean allowSessionCreation)
           
abstract  java.lang.String getMimeType(java.lang.String resourceName)
          Returns the MIME type of the specified file, or null if the MIME type is not known.
abstract  java.lang.String getServiceName()
          Gets a unique name for this service.
abstract  java.lang.String getStaticFileLocation(VaadinRequest request)
          Return the URL from where static files, e.g.
abstract  SystemMessages getSystemMessages()
          Gets the system messages object
abstract  boolean isStandalone(VaadinRequest request)
          Checks whether the UI will be rendered on its own in the browser or whether it will be included into some other context.
 boolean preserveUIOnRefresh(UIProvider provider, UICreateEvent event)
          Check if the given UI should be associated with the window.name so that it can be re-used if the browser window is reloaded.
static void reinitializeSession(VaadinRequest request)
          Discards the current session and creates a new session with the same contents.
 void removeSessionDestroyListener(SessionDestroyListener listener)
          Removes a Vaadin service session destroy listener from this service.
 void removeSessionInitListener(SessionInitListener listener)
          Removes a Vaadin service session initialization listener from this service.
protected abstract  boolean requestCanCreateSession(VaadinRequest request)
          Checks whether it's valid to create a new service session as a result of the given request.
 void setAddonContext(AddonContext addonContext)
           
 void setCurrentInstances(VaadinRequest request, VaadinResponse response)
          Sets the this Vaadin service as the current service and also sets the current Vaadin request and Vaadin response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL_PARAMETER_RESTART_APPLICATION

@Deprecated
public static final java.lang.String URL_PARAMETER_RESTART_APPLICATION
Deprecated. Only supported for LegacyApplication.
See Also:
Constant Field Values

URL_PARAMETER_CLOSE_APPLICATION

@Deprecated
public static final java.lang.String URL_PARAMETER_CLOSE_APPLICATION
Deprecated. Only supported for LegacyApplication.
See Also:
Constant Field Values
Constructor Detail

VaadinService

public VaadinService(DeploymentConfiguration deploymentConfiguration)
Creates a new vaadin service based on a deployment configuration

Parameters:
deploymentConfiguration - the deployment configuration for the service
Method Detail

getStaticFileLocation

public abstract java.lang.String getStaticFileLocation(VaadinRequest request)
Return the URL from where static files, e.g. the widgetset and the theme, are served. In a standard configuration the VAADIN folder inside the returned folder is what is used for widgetsets and themes. The returned folder is usually the same as the context path and independent of e.g. the servlet mapping.

Parameters:
request - the request for which the location should be determined
Returns:
The location of static resources (should contain the VAADIN directory). Never ends with a slash (/).

getConfiguredWidgetset

public abstract java.lang.String getConfiguredWidgetset(VaadinRequest request)
Gets the widgetset that is configured for this deployment, e.g. from a parameter in web.xml.

Parameters:
request - the request for which a widgetset is required
Returns:
the name of the widgetset

getConfiguredTheme

public abstract java.lang.String getConfiguredTheme(VaadinRequest request)
Gets the theme that is configured for this deployment, e.g. from a portal parameter or just some sensible default value.

Parameters:
request - the request for which a theme is required
Returns:
the name of the theme

isStandalone

public abstract boolean isStandalone(VaadinRequest request)
Checks whether the UI will be rendered on its own in the browser or whether it will be included into some other context. A standalone UI may do things that might interfere with other parts of a page, e.g. changing the page title and requesting focus upon loading.

Parameters:
request - the request for which the UI is loaded
Returns:
a boolean indicating whether the UI should be standalone

getClassLoader

public java.lang.ClassLoader getClassLoader()
Get the class loader to use for loading classes loaded by name, e.g. custom UI classes. null indicates that the default class loader should be used.

Returns:
the class loader to use, or null

getMimeType

public abstract java.lang.String getMimeType(java.lang.String resourceName)
Returns the MIME type of the specified file, or null if the MIME type is not known. The MIME type is determined by the configuration of the container, and may be specified in a deployment descriptor. Common MIME types are "text/html" and "image/gif".

Parameters:
resourceName - a String specifying the name of a file
Returns:
a String specifying the file's MIME type
See Also:
ServletContext.getMimeType(String), PortletContext.getMimeType(String)

getDeploymentConfiguration

public DeploymentConfiguration getDeploymentConfiguration()
Gets the deployment configuration.

Returns:
the deployment configuration

getAddonContextListeners

public java.util.Iterator<AddonContextListener> getAddonContextListeners()

getAddonContext

public AddonContext getAddonContext()

setAddonContext

public void setAddonContext(AddonContext addonContext)

getSystemMessages

public abstract SystemMessages getSystemMessages()
Gets the system messages object

Returns:
the system messages object

getBaseDirectory

public abstract java.io.File getBaseDirectory()
Returns the context base directory. Typically an application is deployed in a such way that is has an application directory. For web applications this directory is the root directory of the web applications. In some cases applications might not have an application directory (for example web applications running inside a war).

Returns:
The application base directory or null if the application has no base directory.

addSessionInitListener

public void addSessionInitListener(SessionInitListener listener)
Adds a listener that gets notified when a new Vaadin service session is initialized for this service.

Because of the way different service instances share the same session, the listener is not necessarily notified immediately when the session is created but only when the first request for that session is handled by this service.

Parameters:
listener - the Vaadin service session initialization listener
See Also:
removeSessionInitListener(SessionInitListener), SessionInitListener

removeSessionInitListener

public void removeSessionInitListener(SessionInitListener listener)
Removes a Vaadin service session initialization listener from this service.

Parameters:
listener - the Vaadin service session initialization listener to remove.
See Also:
addSessionInitListener(SessionInitListener)

addSessionDestroyListener

public void addSessionDestroyListener(SessionDestroyListener listener)
Adds a listener that gets notified when a Vaadin service session that has been initialized for this service is destroyed.

Parameters:
listener - the vaadin service session destroy listener
See Also:
addSessionInitListener(SessionInitListener)

fireSessionDestroy

public void fireSessionDestroy(VaadinServiceSession vaadinSession)

removeSessionDestroyListener

public void removeSessionDestroyListener(SessionDestroyListener listener)
Removes a Vaadin service session destroy listener from this service.

Parameters:
listener - the vaadin service session destroy listener
See Also:
addSessionDestroyListener(SessionDestroyListener)

findVaadinSession

public VaadinServiceSession findVaadinSession(VaadinRequest request)
                                       throws ServiceException,
                                              SessionExpiredException
Attempts to find a Vaadin service session associated with this request.

Parameters:
request - the request to get a vaadin service session for.
Returns:
the vaadin service session for the request, or null if no session is found and this is a request for which a new session shouldn't be created.
Throws:
ServiceException
SessionExpiredException
See Also:
VaadinServiceSession

getApplicationUrl

@Deprecated
protected java.net.URL getApplicationUrl(VaadinRequest request)
                                  throws java.net.MalformedURLException
Deprecated. Only used to support LegacyApplication.

Get the base URL that should be used for sending requests back to this service.

This is only used to support legacy cases.

Parameters:
request -
Returns:
Throws:
java.net.MalformedURLException

createCommunicationManager

protected abstract AbstractCommunicationManager createCommunicationManager(VaadinServiceSession session)
Create a communication manager to use for the given service session.

Parameters:
session - the service session for which a new communication manager is needed
Returns:
a new communication manager

createVaadinSession

protected VaadinServiceSession createVaadinSession(VaadinRequest request)
                                            throws ServiceException
Creates a new Vaadin service session.

Parameters:
request -
Returns:
Throws:
javax.servlet.ServletException
java.net.MalformedURLException
ServiceException

getExistingSession

protected VaadinServiceSession getExistingSession(VaadinRequest request,
                                                  boolean allowSessionCreation)
                                           throws SessionExpiredException
Throws:
SessionExpiredException

requestCanCreateSession

protected abstract boolean requestCanCreateSession(VaadinRequest request)
Checks whether it's valid to create a new service session as a result of the given request.

Parameters:
request - the request
Returns:
true if it's valid to create a new service session for the request; else false

getCurrent

public static VaadinService getCurrent()
Gets the currently used Vaadin service. The current service is automatically defined when processing requests related to the service and in threads started at a point when the current service is defined (see InheritableThreadLocal). In other cases, (e.g. from background threads started in some other way), the current service is not automatically defined.

Returns:
the current Vaadin service instance if available, otherwise null
See Also:
setCurrentInstances(VaadinRequest, VaadinResponse)

setCurrentInstances

public void setCurrentInstances(VaadinRequest request,
                                VaadinResponse response)
Sets the this Vaadin service as the current service and also sets the current Vaadin request and Vaadin response. This method is used by the framework to set the current instances when a request related to the service is processed and they are cleared when the request has been processed.

The application developer can also use this method to define the current instances outside the normal request handling, e.g. when initiating custom background threads.

Parameters:
request - the Vaadin request to set as the current request, or null if no request should be set.
response - the Vaadin response to set as the current response, or null if no response should be set.
See Also:
getCurrent(), getCurrentRequest(), getCurrentResponse()

getCurrentRequest

public static VaadinRequest getCurrentRequest()
Gets the currently processed Vaadin request. The current request is automatically defined when the request is started. The current request can not be used in e.g. background threads because of the way server implementations reuse request instances.

Returns:
the current Vaadin request instance if available, otherwise null
See Also:
setCurrentInstances(VaadinRequest, VaadinResponse)

getCurrentResponse

public static VaadinResponse getCurrentResponse()
Gets the currently processed Vaadin request. The current request is automatically defined when the request is started. The current request can not be used in e.g. background threads because of the way server implementations reuse request instances.

Returns:
the current Vaadin request instance if available, otherwise null
See Also:
setCurrentInstances(VaadinRequest, VaadinResponse)

getServiceName

public abstract java.lang.String getServiceName()
Gets a unique name for this service. The name should be unique among different services of the same type but the same for corresponding instances running in different JVMs in a cluster. This is typically based on e.g. the configured servlet's or portlet's name.

Returns:
the unique name of this service instance.

findUI

public UI findUI(VaadinRequest request)
Finds the UI that belongs to the provided request. This is generally only supported for UIDL requests as other request types are not related to any particular UI or have the UI information encoded in a non-standard way. The returned UI is also set as the current UI ( UI.setCurrent(UI)).

Parameters:
request - the request for which a UI is desired
Returns:
the UI belonging to the request

preserveUIOnRefresh

public boolean preserveUIOnRefresh(UIProvider provider,
                                   UICreateEvent event)
Check if the given UI should be associated with the window.name so that it can be re-used if the browser window is reloaded. This is typically determined by the UI provider which typically checks the @PreserveOnRefresh annotation but UI providers and ultimately VaadinService implementations may choose to override the defaults.

Parameters:
provider - the UI provider responsible for the UI
event - the UI create event with details about the UI
Returns:
true if the UI should be preserved on refresh; false if a new UI instance should be initialized on refreshed.

reinitializeSession

public static void reinitializeSession(VaadinRequest request)
Discards the current session and creates a new session with the same contents. The purpose of this is to introduce a new session key in order to avoid session fixation attacks.

Please note that this method makes certain assumptions about how data is stored in the underlying session and may thus not be compatible with some environments.

Parameters:
request - The Vaadin request for which the session should be reinitialized


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