org.apache.wicket
Class Application

java.lang.Object
  extended by org.apache.wicket.Application
All Implemented Interfaces:
IEventSink, ISessionStore.UnboundListener
Direct Known Subclasses:
WebApplication

public abstract class Application
extends java.lang.Object
implements ISessionStore.UnboundListener, IEventSink

Base class for all Wicket applications. To create a Wicket application, you generally should not directly subclass this class. Instead, you will want to subclass some subclass of Application, like WebApplication, which is appropriate for the protocol and markup type you are working with.

Application has the following interesting features / attributes:

Author:
Jonathan Locke
See Also:
WebApplication

Field Summary
static java.lang.String CONFIGURATION
          Configuration constant for the 2 types
 
Constructor Summary
Application()
          Constructor.
 
Method Summary
 void configure()
          Configures application settings to good defaults.
 RequestCycle createRequestCycle(Request request, Response response)
           
 IHeaderResponse decorateHeaderResponse(IHeaderResponse response)
          INTERNAL METHOD - You shouldn't need to call this.
static boolean exists()
          Checks if the Application threadlocal is set in this thread
 Session fetchCreateAndSetSession(RequestCycle requestCycle)
           
static Application get()
          Get Application for current thread.
static Application get(java.lang.String applicationKey)
          Gets the Application based on the application key of that application.
abstract  java.lang.String getApplicationKey()
          Gets the unique key of this application within a given context (like a web application).
static java.util.Set<java.lang.String> getApplicationKeys()
          Gets the keys of the currently registered Wicket applications for this web application.
 IApplicationSettings getApplicationSettings()
           
 ComponentInitializationListenerCollection getComponentInitializationListeners()
           
 ComponentInstantiationListenerCollection getComponentInstantiationListeners()
           
 ComponentOnAfterRenderListenerCollection getComponentOnAfterRenderListeners()
           
 ComponentOnBeforeRenderListenerCollection getComponentPostOnBeforeRenderListeners()
           
 ComponentOnBeforeRenderListenerCollection getComponentPreOnBeforeRenderListeners()
           
abstract  RuntimeConfigurationType getConfigurationType()
          Gets the configuration mode to use for configuring the app, either RuntimeConfigurationType.DEVELOPMENT or RuntimeConfigurationType.DEPLOYMENT.
 IConverterLocator getConverterLocator()
           
 IDebugSettings getDebugSettings()
           
 IProvider<IExceptionMapper> getExceptionMapperProvider()
           
 IExceptionSettings getExceptionSettings()
           
 IFrameworkSettings getFrameworkSettings()
           
 HeaderContributorListenerCollection getHeaderContributorListenerCollection()
           
abstract  java.lang.Class<? extends Page> getHomePage()
          Application subclasses must specify a home page class by implementing this abstract method.
 IMapperContext getMapperContext()
           
 IMarkupSettings getMarkupSettings()
           
<T> T
getMetaData(MetaDataKey<T> key)
          Gets metadata for this application using the given key.
 java.lang.String getMimeType(java.lang.String fileName)
          Returns the mime type for given filename.
 java.lang.String getName()
          Gets the name of this application.
 IPageFactory getPageFactory()
          Returns IPageFactory for this application.
protected  IPageManagerContext getPageManagerContext()
           
 IPageManagerProvider getPageManagerProvider()
           
 IPageRendererProvider getPageRendererProvider()
           
 IPageSettings getPageSettings()
           
 RequestCycleListenerCollection getRequestCycleListeners()
           
 IRequestCycleProvider getRequestCycleProvider()
           
 IRequestCycleSettings getRequestCycleSettings()
           
 IRequestLogger getRequestLogger()
          Gets the IRequestLogger.
 IRequestLoggerSettings getRequestLoggerSettings()
           
 ResourceReferenceRegistry getResourceReferenceRegistry()
          Returns ResourceReferenceRegistry for this application.
 IResourceSettings getResourceSettings()
           
 IRequestMapper getRootRequestMapper()
           
 ICompoundRequestMapper getRootRequestMapperAsCompound()
          Converts the root mapper to a ICompoundRequestMapper if necessary and returns the converted instance.
 ISecuritySettings getSecuritySettings()
           
 ISessionSettings getSessionSettings()
           
 ISessionStore getSessionStore()
          Gets the facade object for working getting/ storing session instances.
 IProvider<ISessionStore> getSessionStoreProvider()
           
 SharedResources getSharedResources()
           
 IStoreSettings getStoreSettings()
           
protected  void init()
          Allows for initialization of the application by a subclass.
 void initApplication()
          Initialize the application
 void initializeComponents()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void internalDestroy()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
protected  void internalInit()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void logEventTarget(IRequestHandler target)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void logResponseTarget(IRequestHandler requestTarget)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
protected  IConverterLocator newConverterLocator()
          Creates and returns a new instance of IConverterLocator.
protected  IMapperContext newMapperContext()
          Factory method for IMapperContext implementations.
protected  IPageFactory newPageFactory()
          Override to create custom IPageFactory
protected  IRequestLogger newRequestLogger()
          creates a new request logger when requests logging is enabled.
protected  ResourceReferenceRegistry newResourceReferenceRegistry()
          Override to create custom ResourceReferenceRegistry.
abstract  Session newSession(Request request, Response response)
          Creates a new session.
protected  SharedResources newSharedResources(ResourceReferenceRegistry registry)
           
protected  void onDestroy()
          Called when wicket servlet is destroyed.
 void onEvent(IEvent<?> event)
          Called when an event is sent to this sink
 void sessionUnbound(java.lang.String sessionId)
          Informs the listener that session with specific id has been unbound.
 void setApplicationSettings(IApplicationSettings applicationSettings)
           
 void setDebugSettings(IDebugSettings debugSettings)
           
 void setExceptionSettings(IExceptionSettings exceptionSettings)
           
 void setFrameworkSettings(IFrameworkSettings frameworkSettings)
           
 void setHeaderResponseDecorator(IHeaderResponseDecorator headerResponseDecorator)
          Sets an IHeaderResponseDecorator that you want your application to use to decorate header responses.
 void setMarkupSettings(IMarkupSettings markupSettings)
           
<T> void
setMetaData(MetaDataKey<T> key, java.lang.Object object)
          Sets the metadata for this application using the given key.
 void setName(java.lang.String name)
          Sets application name.
 void setPageManagerProvider(IPageManagerProvider provider)
           
 void setPageRendererProvider(IPageRendererProvider pageRendererProvider)
           
 void setPageSettings(IPageSettings pageSettings)
           
 void setRequestCycleProvider(IRequestCycleProvider requestCycleProvider)
           
 void setRequestCycleSettings(IRequestCycleSettings requestCycleSettings)
           
 void setRequestLoggerSettings(IRequestLoggerSettings requestLoggerSettings)
           
 void setResourceSettings(IResourceSettings resourceSettings)
           
 void setRootRequestMapper(IRequestMapper rootRequestMapper)
          Sets the root request mapper
 void setSecuritySettings(ISecuritySettings securitySettings)
           
 void setSessionSettings(ISessionSettings sessionSettings)
           
 void setSessionStoreProvider(IProvider<ISessionStore> sessionStoreProvider)
           
 void setStoreSettings(IStoreSettings storeSettings)
           
 boolean usesDeploymentConfig()
           
 boolean usesDevelopmentConfig()
           
protected  void validateInit()
          Gives the Application object a chance to validate if it has been properly initialized
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIGURATION

public static final java.lang.String CONFIGURATION
Configuration constant for the 2 types

See Also:
Constant Field Values
Constructor Detail

Application

public Application()
Constructor. Use init() for any configuration of your application instead of overriding the constructor.

Method Detail

exists

public static boolean exists()
Checks if the Application threadlocal is set in this thread

Returns:
true if get() can return the instance of application, false otherwise

get

public static Application get()
Get Application for current thread.

Returns:
The current thread's Application

get

public static Application get(java.lang.String applicationKey)
Gets the Application based on the application key of that application. You typically never have to use this method unless you are working on an integration project.

Parameters:
applicationKey - The unique key of the application within a certain context (e.g. a web application)
Returns:
The application or null if application has not been found

getApplicationKeys

public static java.util.Set<java.lang.String> getApplicationKeys()
Gets the keys of the currently registered Wicket applications for this web application. You typically never have to use this method unless you are working on an integration project.

Returns:
unmodifiable set with keys that correspond with getApplicationKey(). Never null, but possibly empty

configure

public final void configure()
Configures application settings to good defaults.


getApplicationKey

public abstract java.lang.String getApplicationKey()
Gets the unique key of this application within a given context (like a web application). NOT INTENDED FOR FRAMEWORK CLIENTS.

Returns:
The unique key of this application

getConfigurationType

public abstract RuntimeConfigurationType getConfigurationType()
Gets the configuration mode to use for configuring the app, either RuntimeConfigurationType.DEVELOPMENT or RuntimeConfigurationType.DEPLOYMENT.

The configuration type. Must currently be either DEVELOPMENT or DEPLOYMENT. Currently, if the configuration type is DEVELOPMENT, resources are polled for changes, component usage is checked, wicket tags are not stripped from output and a detailed exception page is used. If the type is DEPLOYMENT, component usage is not checked, wicket tags are stripped from output and a non-detailed exception page is used to display errors.

Note that you should not run Wicket in DEVELOPMENT mode on production servers - the various debugging checks and resource polling is inefficient and may leak resources, particularly on webapp redeploy.

To change the deployment mode, add the following to your web.xml, inside your mapping (or mapping if you're using 1.3.x):

 <init-param>
             <param-name>configuration</param-name>
             <param-value>deployment</param-value>
 </init-param>
 

You can alternatively set this as a <context-param> on the whole context.

Another option is to set the "wicket.configuration" system property to either "deployment" or "development". The value is not case-sensitive.

The system property is checked first, allowing you to add a web.xml param for deployment, and a command-line override when you want to run in development mode during development.

You may also override Application.getConfigurationType() to provide your own custom switch, in which case none of the above logic is used.

IMPORTANT NOTE

THIS METHOD IS CALLED OFTEN FROM MANY DIFFERENT POINTS IN CODE, INCLUDING DURING THE RENDER PROCESS, THEREFORE THE IMPLEMENTATION SHOULD BE FAST - PREFERRABLY USING A FAST-TO-RETRIEVE CACHED VALUE

Returns:
configuration
Since:
1.2.3 (function existed as a property getter), 1.3.0 (abstract, used to configure things)

getHomePage

public abstract java.lang.Class<? extends Page> getHomePage()
Application subclasses must specify a home page class by implementing this abstract method.

Returns:
Home page class for this application

getConverterLocator

public final IConverterLocator getConverterLocator()
Returns:
The converter locator for this application

getMetaData

public final <T> T getMetaData(MetaDataKey<T> key)
Gets metadata for this application using the given key.

Type Parameters:
T -
Parameters:
key - The key for the data
Returns:
The metadata
See Also:
MetaDataKey

getName

public final java.lang.String getName()
Gets the name of this application.

Returns:
The application name.

getRequestLogger

public final IRequestLogger getRequestLogger()
Gets the IRequestLogger.

Returns:
The RequestLogger

getSessionStore

public final ISessionStore getSessionStore()
Gets the facade object for working getting/ storing session instances.

Returns:
The session facade

sessionUnbound

public void sessionUnbound(java.lang.String sessionId)
Description copied from interface: ISessionStore.UnboundListener
Informs the listener that session with specific id has been unbound.

Specified by:
sessionUnbound in interface ISessionStore.UnboundListener
See Also:
ISessionStore.UnboundListener.sessionUnbound(java.lang.String)

initializeComponents

public final void initializeComponents()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL. Initializes wicket components.


logEventTarget

public void logEventTarget(IRequestHandler target)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL.

Parameters:
target -

logResponseTarget

public void logResponseTarget(IRequestHandler requestTarget)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL.

Parameters:
requestTarget -

newSession

public abstract Session newSession(Request request,
                                   Response response)
Creates a new session. Override this method if you want to provide a custom session.

Parameters:
request - The request that will create this session.
response - The response to initialize, for example with cookies. This is important to use cases involving unit testing because those use cases might want to be able to sign a user in automatically when the session is created.
Returns:
The session
Since:
1.3

setMetaData

public final <T> void setMetaData(MetaDataKey<T> key,
                                  java.lang.Object object)
Sets the metadata for this application using the given key. If the metadata object is not of the correct type for the metadata key, an IllegalArgumentException will be thrown. For information on creating MetaDataKeys, see MetaDataKey.

Type Parameters:
T -
Parameters:
key - The singleton key for the metadata
object - The metadata object
Throws:
java.lang.IllegalArgumentException
See Also:
MetaDataKey

onDestroy

protected void onDestroy()
Called when wicket servlet is destroyed. Overrides do not have to call super.


init

protected void init()
Allows for initialization of the application by a subclass. Use this method for any application setup instead of the constructor.


internalDestroy

public void internalDestroy()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.


internalInit

protected void internalInit()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT OVERRIDE OR CALL. Internal initialization.


getExceptionMapperProvider

public IProvider<IExceptionMapper> getExceptionMapperProvider()
Returns:
the exception mapper provider

getSessionStoreProvider

public final IProvider<ISessionStore> getSessionStoreProvider()
Returns:
Session state provider

setSessionStoreProvider

public final void setSessionStoreProvider(IProvider<ISessionStore> sessionStoreProvider)
Parameters:
sessionStoreProvider -

newConverterLocator

protected IConverterLocator newConverterLocator()
Creates and returns a new instance of IConverterLocator.

Returns:
A new IConverterLocator instance

newRequestLogger

protected IRequestLogger newRequestLogger()
creates a new request logger when requests logging is enabled.

Returns:
The new request logger

getRootRequestMapperAsCompound

public final ICompoundRequestMapper getRootRequestMapperAsCompound()
Converts the root mapper to a ICompoundRequestMapper if necessary and returns the converted instance.

Returns:
compound instance of the root mapper

getRootRequestMapper

public final IRequestMapper getRootRequestMapper()
Returns:
The root request mapper

setRootRequestMapper

public final void setRootRequestMapper(IRequestMapper rootRequestMapper)
Sets the root request mapper

Parameters:
rootRequestMapper -

initApplication

public final void initApplication()
Initialize the application


validateInit

protected void validateInit()
Gives the Application object a chance to validate if it has been properly initialized


setName

public final void setName(java.lang.String name)
Sets application name. This method must be called before any other methods are invoked and can only be called once per application instance.

Parameters:
name - unique application name

getMimeType

public java.lang.String getMimeType(java.lang.String fileName)
Returns the mime type for given filename.

Parameters:
fileName -
Returns:
mime type

onEvent

public void onEvent(IEvent<?> event)
Called when an event is sent to this sink

Specified by:
onEvent in interface IEventSink

getHeaderContributorListenerCollection

public final HeaderContributorListenerCollection getHeaderContributorListenerCollection()
Returns:
Gets the application's HeaderContributorListenerCollection

getComponentInstantiationListeners

public final ComponentInstantiationListenerCollection getComponentInstantiationListeners()
Returns:
Gets the application's ComponentInstantiationListenerCollection

getComponentInitializationListeners

public final ComponentInitializationListenerCollection getComponentInitializationListeners()
Returns:
Gets the application's ComponentInitializationListeners

getComponentPreOnBeforeRenderListeners

public final ComponentOnBeforeRenderListenerCollection getComponentPreOnBeforeRenderListeners()
Returns:
ComponentOnBeforeRenderListenerCollection

getComponentPostOnBeforeRenderListeners

public final ComponentOnBeforeRenderListenerCollection getComponentPostOnBeforeRenderListeners()
Returns:
ComponentOnBeforeRenderListenerCollection

getComponentOnAfterRenderListeners

public final ComponentOnAfterRenderListenerCollection getComponentOnAfterRenderListeners()
Returns:
on after render listeners collection

getRequestCycleListeners

public RequestCycleListenerCollection getRequestCycleListeners()
Returns:
the unmodifiable request list of IRequestCycleListeners in this application

getApplicationSettings

public final IApplicationSettings getApplicationSettings()
Returns:
Application's application-wide settings
Since:
1.2

setApplicationSettings

public final void setApplicationSettings(IApplicationSettings applicationSettings)
Parameters:
applicationSettings -

getDebugSettings

public final IDebugSettings getDebugSettings()
Returns:
Application's debug related settings

setDebugSettings

public final void setDebugSettings(IDebugSettings debugSettings)
Parameters:
debugSettings -

getExceptionSettings

public final IExceptionSettings getExceptionSettings()
Returns:
Application's exception handling settings

setExceptionSettings

public final void setExceptionSettings(IExceptionSettings exceptionSettings)
Parameters:
exceptionSettings -

getFrameworkSettings

public final IFrameworkSettings getFrameworkSettings()
Returns:
Wicket framework settings

setFrameworkSettings

public final void setFrameworkSettings(IFrameworkSettings frameworkSettings)
Parameters:
frameworkSettings -

getPageSettings

public final IPageSettings getPageSettings()
Returns:
Application's page related settings

setPageSettings

public final void setPageSettings(IPageSettings pageSettings)
Parameters:
pageSettings -

getRequestCycleSettings

public final IRequestCycleSettings getRequestCycleSettings()
Returns:
Application's request cycle related settings

setRequestCycleSettings

public final void setRequestCycleSettings(IRequestCycleSettings requestCycleSettings)
Parameters:
requestCycleSettings -

getMarkupSettings

public IMarkupSettings getMarkupSettings()
Returns:
Application's markup related settings

setMarkupSettings

public final void setMarkupSettings(IMarkupSettings markupSettings)
Parameters:
markupSettings -

getRequestLoggerSettings

public final IRequestLoggerSettings getRequestLoggerSettings()
Returns:
Application's request logger related settings

setRequestLoggerSettings

public final void setRequestLoggerSettings(IRequestLoggerSettings requestLoggerSettings)
Parameters:
requestLoggerSettings -

getResourceSettings

public final IResourceSettings getResourceSettings()
Returns:
Application's resources related settings

setResourceSettings

public final void setResourceSettings(IResourceSettings resourceSettings)
Parameters:
resourceSettings -

getSecuritySettings

public final ISecuritySettings getSecuritySettings()
Returns:
Application's security related settings

setSecuritySettings

public final void setSecuritySettings(ISecuritySettings securitySettings)
Parameters:
securitySettings -

getSessionSettings

public final ISessionSettings getSessionSettings()
Returns:
Application's session related settings

setSessionSettings

public final void setSessionSettings(ISessionSettings sessionSettings)
Parameters:
sessionSettings -

getStoreSettings

public final IStoreSettings getStoreSettings()
Returns:
Application's stores related settings

setStoreSettings

public final void setStoreSettings(IStoreSettings storeSettings)
Parameters:
storeSettings -

getPageManagerProvider

public final IPageManagerProvider getPageManagerProvider()
Returns:
PageManagerProvider

setPageManagerProvider

public final void setPageManagerProvider(IPageManagerProvider provider)
Parameters:
provider -

getPageManagerContext

protected IPageManagerContext getPageManagerContext()
Returns:
the page manager context

getPageRendererProvider

public final IPageRendererProvider getPageRendererProvider()
Returns:
PageRendererProvider

setPageRendererProvider

public final void setPageRendererProvider(IPageRendererProvider pageRendererProvider)
Parameters:
pageRendererProvider -

newResourceReferenceRegistry

protected ResourceReferenceRegistry newResourceReferenceRegistry()
Override to create custom ResourceReferenceRegistry.

Returns:
new ResourceReferenceRegistry instance.

getResourceReferenceRegistry

public final ResourceReferenceRegistry getResourceReferenceRegistry()
Returns ResourceReferenceRegistry for this application.

Returns:
ResourceReferenceRegistry

newSharedResources

protected SharedResources newSharedResources(ResourceReferenceRegistry registry)
Parameters:
registry -
Returns:
SharedResources

getSharedResources

public SharedResources getSharedResources()
Returns:
SharedResources

newPageFactory

protected IPageFactory newPageFactory()
Override to create custom IPageFactory

Returns:
new IPageFactory instance.

getPageFactory

public final IPageFactory getPageFactory()
Returns IPageFactory for this application.

Returns:
page factory

getMapperContext

public final IMapperContext getMapperContext()
Returns:
mapper context

newMapperContext

protected IMapperContext newMapperContext()
Factory method for IMapperContext implementations. DefaultMapperContext may be a good starting point for custom implementations.

Returns:
new instance of mapper context to be used in the application

fetchCreateAndSetSession

public Session fetchCreateAndSetSession(RequestCycle requestCycle)
Parameters:
requestCycle -
Returns:
Session

getRequestCycleProvider

public IRequestCycleProvider getRequestCycleProvider()
Returns:
RequestCycleProvider

setRequestCycleProvider

public void setRequestCycleProvider(IRequestCycleProvider requestCycleProvider)
Parameters:
requestCycleProvider -

createRequestCycle

public final RequestCycle createRequestCycle(Request request,
                                             Response response)
Parameters:
request -
response -
Returns:
request cycle

setHeaderResponseDecorator

public void setHeaderResponseDecorator(IHeaderResponseDecorator headerResponseDecorator)
Sets an IHeaderResponseDecorator that you want your application to use to decorate header responses.

Parameters:
headerResponseDecorator - your custom decorator

decorateHeaderResponse

public final IHeaderResponse decorateHeaderResponse(IHeaderResponse response)
INTERNAL METHOD - You shouldn't need to call this. This is called every time Wicket creates an IHeaderResponse. It gives you the ability to incrementally add features to an IHeaderResponse implementation by wrapping it in another implementation. To decorate an IHeaderResponse in your application, set the IHeaderResponseDecorator on the application.

Parameters:
response - the response Wicket created
Returns:
the response Wicket should use in IHeaderContributor traversal
See Also:
IHeaderResponseDecorator

usesDevelopmentConfig

public final boolean usesDevelopmentConfig()
Returns:
true, of app is in Development mode

usesDeploymentConfig

public final boolean usesDeploymentConfig()
Returns:
true, of app is in Deployment mode


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.