Package com.saperion.web
Class WebAppInitUtil
java.lang.Object
com.saperion.web.WebAppInitUtil
- All Implemented Interfaces:
jakarta.servlet.ServletContextListener
,EventListener
This class is a web filter and can be used to initialize a web application. It is capable of
handling multiple instances of
WebAppInitializer
to dynamically initialize the web
application. WebAppInitializer
can be registered as initialization-parameters in the
web.xml. The order of the WebAppInitializer classes can be specified by the initialization
parameter 'INIT_ORDER'.- Author:
- sts
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
contextDestroyed
(jakarta.servlet.ServletContextEvent sce) Is called when is the server / the application is shut down.void
contextInitialized
(jakarta.servlet.ServletContextEvent sce) Is called when the server / the application is started.getInitializer
(String name) Returns the WebAppInitializer by the given name if existing, null otherwise.static WebAppInitUtil
Returns the instance of this WebAppInitUtil.protected void
loadInitilizers
(jakarta.servlet.ServletContext c) Loads the registered initializers as given as initialization parameters in web.xml.removeInitializer
(String name) Removes the WebAppInitializer by the given name if existing.setInitializer
(String name, WebAppInitializer webAppInitializer) Sets the given WebAppInitializer by the given name if not already existing.
-
Constructor Details
-
WebAppInitUtil
public WebAppInitUtil()
-
-
Method Details
-
getInstance
Returns the instance of this WebAppInitUtil. If no instance was created by the servlet container- Returns:
- the instance of this WebAppInitUtil.
-
getInitializer
Returns the WebAppInitializer by the given name if existing, null otherwise.- Parameters:
name
- The name of the WebAppInitializer to get.- Returns:
- the WebAppInitializer by the given name if existing, null otherwise.
- Throws:
Exception
- if this WebAppInitUtil was not initialized by the servlet container yet.
-
setInitializer
public WebAppInitUtil setInitializer(String name, WebAppInitializer webAppInitializer) throws Exception Sets the given WebAppInitializer by the given name if not already existing.- Parameters:
name
- The name of the WebAppInitializer to set.webAppInitializer
- The WebAppInitializer to set.- Returns:
- instance of this WebAppInitUtil.
- Throws:
Exception
- if this WebAppInitUtil was not initialized by the servlet container yet.
-
removeInitializer
Removes the WebAppInitializer by the given name if existing.- Parameters:
name
- The name of the WebAppInitializer to remove.- Returns:
- instance of this WebAppInitUtil.
- Throws:
Exception
- if this WebAppInitUtil was not initialized by the servlet container yet.
-
loadInitilizers
protected void loadInitilizers(jakarta.servlet.ServletContext c) Loads the registered initializers as given as initialization parameters in web.xml. Overwrite this method to load initializers more elegant.- Parameters:
c
- The ServletContext
-
contextInitialized
public void contextInitialized(jakarta.servlet.ServletContextEvent sce) Is called when the server / the application is started. Registers WebAppInitializer and callsonWepAppInit
on all registered WebAppInitializers.- Specified by:
contextInitialized
in interfacejakarta.servlet.ServletContextListener
- Parameters:
sce
- The ServletContextEvent.
-
contextDestroyed
public void contextDestroyed(jakarta.servlet.ServletContextEvent sce) Is called when is the server / the application is shut down. CallsonWepAppDestroy
on all registered WebAppInitializers.- Specified by:
contextDestroyed
in interfacejakarta.servlet.ServletContextListener
- Parameters:
sce
- The ServletContextEvent.
-