org.apache.wicket
Class Application

java.lang.Object
  extended by org.apache.wicket.Application
Direct Known Subclasses:
WebApplication

public abstract class Application
extends Object

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 String CONFIGURATION
          Configuration constant for the 2 types
static String CONTEXTPATH
          Configuration type constant for getting the context path out of the web.xml
static String DEPLOYMENT
          Configuration type constant for deployment
static String DEVELOPMENT
          Configuration type constant for development
 
Constructor Summary
Application()
          Constructor.
 
Method Summary
 void addComponentInitializationListener(IComponentInitializationListener listener)
          Adds a component initialization listener.
 void addComponentInstantiationListener(IComponentInstantiationListener listener)
          Adds a component instantiation listener.
 void addComponentOnAfterRenderListener(IComponentOnAfterRenderListener listener)
          Adds an IComponentOnAfterRenderListener.
 void addPostComponentOnBeforeRenderListener(IComponentOnBeforeRenderListener listener)
          Adds an IComponentOnBeforeRenderListener.
 void addPreComponentOnBeforeRenderListener(IComponentOnBeforeRenderListener listener)
          Adds an IComponentOnBeforeRenderListener.
 void addRenderHeadListener(IHeaderContributor listener)
          Adds a listener that will be invoked for every header response
 void configure()
          Configures application settings to good defaults.
 IHeaderResponse decorateHeaderResponse(IHeaderResponse response)
          INTERNAL METHOD - You shouldn't need to call this.
protected  void destroy()
          Deprecated. use onDestroy() instead
static boolean exists()
          Checks if the Application threadlocal is set in this thread
 void fireComponentInitializationListeners(Component component)
          Fires registered IComponentInitializationListeners on the component
static Application get()
          Get Application for current thread.
static Application get(String applicationKey)
          Gets the Application based on the application key of that application.
abstract  String getApplicationKey()
          Gets the unique key of this application within a given context (like a web application).
static Set<String> getApplicationKeys()
          Gets the keys of the currently registered Wicket applications for this web application.
 IApplicationSettings getApplicationSettings()
           
abstract  String getConfigurationType()
          Gets the configuration mode to use for configuring the app, either DEVELOPMENT or DEPLOYMENT.
 IConverterLocator getConverterLocator()
           
 IDebugSettings getDebugSettings()
           
 IExceptionSettings getExceptionSettings()
           
 IFrameworkSettings getFrameworkSettings()
           
abstract  Class<? extends Page> getHomePage()
          Application subclasses must specify a home page class by implementing this abstract method.
 IMarkupCache getMarkupCache()
          Deprecated. please use IMarkupSettings.getMarkupCache() instead
 IMarkupSettings getMarkupSettings()
           
<T> T
getMetaData(MetaDataKey<T> key)
          Gets metadata for this application using the given key.
 String getName()
          Gets the name of this application.
 IPageSettings getPageSettings()
           
protected  Object getRequestCycleFactory()
          Deprecated. replaced by newRequestCycle(Request, Response)
 IRequestCycleSettings getRequestCycleSettings()
           
 IRequestLogger getRequestLogger()
          Gets the RequestLogger.
 IRequestLoggerSettings getRequestLoggerSettings()
           
 IResourceSettings getResourceSettings()
           
 ISecuritySettings getSecuritySettings()
           
protected  Object getSessionFactory()
          Deprecated. replaced by newSession(Request, Response)
 ISessionSettings getSessionSettings()
           
 ISessionStore getSessionStore()
          Gets the facade object for working getting/ storing session instances.
 SharedResources getSharedResources()
          Gets the shared resources.
protected  void init()
          Allows for initialization of the application by a subclass.
 void initializeComponents()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
protected  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(IRequestTarget target)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void logResponseTarget(IRequestTarget requestTarget)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
protected  IConverterLocator newConverterLocator()
          Creates and returns a new instance of IConverterLocator.
 RequestCycle newRequestCycle(Application application, Request request, Response response)
          Deprecated. Applications wishing to provide custom request cycles should override method newRequestCycle(Request, Response)
abstract  RequestCycle newRequestCycle(Request request, Response response)
          Creates a new RequestCycle object.
protected  IRequestLogger newRequestLogger()
          creates a new request logger when requests logging is enabled.
abstract  Session newSession(Request request, Response response)
          Creates a new session.
protected abstract  ISessionStore newSessionStore()
          Creates a new session facade.
 void notifyRenderHeadListener(IHeaderResponse response)
          INTERNAL
protected  void onDestroy()
          Called when wicket servlet is destroyed.
 void removeComponentInstantiationListener(IComponentInstantiationListener listener)
          Removes a component instantiation listener.
 void removeComponentOnAfterRenderListener(IComponentOnAfterRenderListener listener)
          Removes an IComponentOnAfterRenderListener.
 void removePostComponentOnBeforeRenderListener(IComponentOnBeforeRenderListener listener)
          Removes an IComponentOnBeforeRenderListener.
 void removePreComponentOnBeforeRenderListener(IComponentOnBeforeRenderListener listener)
          Removes an IComponentOnBeforeRenderListener.
 void removeRenderHeadListener(IHeaderContributor listener)
           
static void set(Application application)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void setHeaderResponseDecorator(IHeaderResponseDecorator headerResponseDecorator)
          Sets an IHeaderResponseDecorator that you want your application to use to decorate header responses.
<T> void
setMetaData(MetaDataKey<T> key, Object object)
          Sets the metadata for this application using the given key.
static void unset()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIGURATION

public static final String CONFIGURATION
Configuration constant for the 2 types

See Also:
Constant Field Values

CONTEXTPATH

public static final String CONTEXTPATH
Configuration type constant for getting the context path out of the web.xml

See Also:
Constant Field Values

DEPLOYMENT

public static final String DEPLOYMENT
Configuration type constant for deployment

See Also:
Constant Field Values

DEVELOPMENT

public static final String DEVELOPMENT
Configuration type constant for development

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(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 Set<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

set

public static void set(Application application)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT.

Parameters:
application - The current application or null for this thread

unset

public static void unset()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT.


addComponentInstantiationListener

public final void addComponentInstantiationListener(IComponentInstantiationListener listener)
Adds a component instantiation listener. This method should typically only be called during application startup; it is not thread safe.

Note: wicket does not guarantee the execution order of added listeners

Parameters:
listener - the listener to add

addComponentInitializationListener

public final void addComponentInitializationListener(IComponentInitializationListener listener)
Adds a component initialization listener. This method should typically only be called during application startup; it is not thread safe.

Each added listener will be notified after Component's Component.onInitialize() method has been executed.

Note: wicket does not guarantee the execution order of added listeners

Parameters:
listener - the listener to add

fireComponentInitializationListeners

public final void fireComponentInitializationListeners(Component component)
Fires registered IComponentInitializationListeners on the component

Parameters:
component -
See Also:
addComponentInitializationListener(IComponentInitializationListener)

configure

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


getApplicationKey

public abstract 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

getApplicationSettings

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

getConfigurationType

public abstract String getConfigurationType()
Gets the configuration mode to use for configuring the app, either DEVELOPMENT or 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)

getConverterLocator

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

getDebugSettings

public IDebugSettings getDebugSettings()
Returns:
Application's debug related settings
Since:
1.2
See Also:
IDebugSettings

getExceptionSettings

public IExceptionSettings getExceptionSettings()
Returns:
Application's exception handling settings
Since:
1.2
See Also:
IExceptionSettings

getFrameworkSettings

public IFrameworkSettings getFrameworkSettings()
Returns:
Wicket framework settings
Since:
1.2
See Also:
IFrameworkSettings

getHomePage

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

Returns:
Home page class for this application

getMarkupCache

@Deprecated
public final IMarkupCache getMarkupCache()
Deprecated. please use IMarkupSettings.getMarkupCache() instead

THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT.

Returns:
The markup cache associated with the application

getMarkupSettings

public IMarkupSettings getMarkupSettings()
Returns:
Application's markup related settings
Since:
1.2
See Also:
IMarkupSettings

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 String getName()
Gets the name of this application.

Returns:
The application name.

getPageSettings

public IPageSettings getPageSettings()
Returns:
Application's page related settings
Since:
1.2
See Also:
IPageSettings

getRequestCycleSettings

public IRequestCycleSettings getRequestCycleSettings()
Returns:
Application's request cycle related settings
Since:
1.2
See Also:
IDebugSettings

getRequestLogger

public final IRequestLogger getRequestLogger()
Gets the RequestLogger.

Returns:
The RequestLogger

getRequestLoggerSettings

public IRequestLoggerSettings getRequestLoggerSettings()
Returns:
Application's resources related settings
Since:
1.3
See Also:
IResourceSettings

getResourceSettings

public IResourceSettings getResourceSettings()
Returns:
Application's resources related settings
Since:
1.2
See Also:
IResourceSettings

getSecuritySettings

public ISecuritySettings getSecuritySettings()
Returns:
Application's security related settings
Since:
1.2
See Also:
ISecuritySettings

getSessionSettings

public ISessionSettings getSessionSettings()
Returns:
Application's session related settings
Since:
1.2
See Also:
ISessionSettings

getSessionStore

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

Returns:
The session facade

getSharedResources

public final SharedResources getSharedResources()
Gets the shared resources.

Returns:
The SharedResources for this application.

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(IRequestTarget target)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL.

Parameters:
target -

logResponseTarget

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

Parameters:
requestTarget -

newRequestCycle

public abstract RequestCycle newRequestCycle(Request request,
                                             Response response)
Creates a new RequestCycle object. Override this method if you want to provide a custom request cycle.

Parameters:
request - The request
response - The response
Returns:
The request cycle
Since:
1.3

newRequestCycle

@Deprecated
public final RequestCycle newRequestCycle(Application application,
                                                     Request request,
                                                     Response response)
Deprecated. Applications wishing to provide custom request cycles should override method newRequestCycle(Request, Response)

FOR DEPRECATION ONLY.

Parameters:
application -
request -
response -
Returns:
nothing
Throws:
UnsupportedOperationException - always

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

removeComponentInstantiationListener

public final void removeComponentInstantiationListener(IComponentInstantiationListener listener)
Removes a component instantiation listener. This method should typicaly only be called during application startup; it is not thread safe.

Parameters:
listener - the listener to remove

setMetaData

public final <T> void setMetaData(MetaDataKey<T> key,
                                  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:
IllegalArgumentException
See Also:
MetaDataKey

destroy

@Deprecated
protected final void destroy()
Deprecated. use onDestroy() instead

Called when wicket servlet is destroyed. Overrides do not have to call super.


onDestroy

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


getRequestCycleFactory

@Deprecated
protected final Object getRequestCycleFactory()
Deprecated. replaced by newRequestCycle(Request, Response)

Returns:
Request cycle factory for this kind of session.

getSessionFactory

@Deprecated
protected final Object getSessionFactory()
Deprecated. replaced by newSession(Request, Response)

Gets the factory for creating session instances.

Returns:
Factory for creating session instances

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

protected 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.


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

newSessionStore

protected abstract ISessionStore newSessionStore()
Creates a new session facade. Is called once per application, and is typically not something clients reimplement.

Returns:
The session facade

addPreComponentOnBeforeRenderListener

public final void addPreComponentOnBeforeRenderListener(IComponentOnBeforeRenderListener listener)
Adds an IComponentOnBeforeRenderListener. This method should typically only be called during application startup; it is not thread safe.

Parameters:
listener -

removePreComponentOnBeforeRenderListener

public final void removePreComponentOnBeforeRenderListener(IComponentOnBeforeRenderListener listener)
Removes an IComponentOnBeforeRenderListener.

Parameters:
listener -

addPostComponentOnBeforeRenderListener

public final void addPostComponentOnBeforeRenderListener(IComponentOnBeforeRenderListener listener)
Adds an IComponentOnBeforeRenderListener. This method should typically only be called during application startup; it is not thread safe.

Parameters:
listener -

removePostComponentOnBeforeRenderListener

public final void removePostComponentOnBeforeRenderListener(IComponentOnBeforeRenderListener listener)
Removes an IComponentOnBeforeRenderListener.

Parameters:
listener -

addComponentOnAfterRenderListener

public final void addComponentOnAfterRenderListener(IComponentOnAfterRenderListener listener)
Adds an IComponentOnAfterRenderListener. This method should typically only be called during application startup; it is not thread safe.

Parameters:
listener -

removeComponentOnAfterRenderListener

public final void removeComponentOnAfterRenderListener(IComponentOnAfterRenderListener listener)
Removes an IComponentOnAfterRenderListener.

Parameters:
listener -

addRenderHeadListener

public final void addRenderHeadListener(IHeaderContributor listener)
Adds a listener that will be invoked for every header response

Parameters:
listener -

removeRenderHeadListener

public void removeRenderHeadListener(IHeaderContributor listener)
Parameters:
listener -

notifyRenderHeadListener

public void notifyRenderHeadListener(IHeaderResponse response)
INTERNAL

Parameters:
response -

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


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