Class PortletApplicationContextLocator
java.lang.Object
org.jasig.portlet.newsreader.spring.PortletApplicationContextLocator
- All Implemented Interfaces:
EventListener,javax.servlet.ServletContextListener
public class PortletApplicationContextLocator
extends Object
implements javax.servlet.ServletContextListener
Provides standard access to the portal's
ApplicationContext. If running in a web application a
WebApplicationContext is available.
getApplicationContext(String) should be used by most uPortal code that needs access to the portal's
ApplicationContext. It ensures that a single ApplicationContext is used portal-wide both
when the portal is running as a web-application and when tools are run from the command line.
For legacy portal code that is not yet Spring managed and does not have access to the ServletContext this
class provides similar functionality to WebApplicationContextUtils via the
getWebApplicationContext() and getRequiredWebApplicationContext(). These methods are deprecated as
any code that requires a WebApplicationContext should either be refactored as a Spring managed bean or have
access to the ServletContext- Since:
- 5.1.1
- Author:
- Eric Dalquist
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSubset of the main context; used in hbm2dll and importing -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcontextDestroyed(javax.servlet.ServletContextEvent sce) voidcontextInitialized(javax.servlet.ServletContextEvent sce) static org.springframework.context.ApplicationContextgetApplicationContext(String importExportContextFile) If running in a web application the existingWebApplicationContextwill be returned.static org.springframework.web.context.WebApplicationContextDeprecated.static org.springframework.web.context.WebApplicationContextDeprecated.This method is a work-around for areas in uPortal that do not have the ability to use theWebApplicationContextUtils.getWebApplicationContext(ServletContext)directly.static booleanDeprecated.Only needed for usinggetRequiredWebApplicationContext()orgetWebApplicationContext().static voidshutdown()If the ApplicationContext returned bygetApplicationContext(String)is 'portal managed' the shutdown hook for the context is called, closing and cleaning up all spring managed resources.
-
Field Details
-
DATABASE_CONTEXT_LOCATION
Subset of the main context; used in hbm2dll and importing- See Also:
-
-
Constructor Details
-
PortletApplicationContextLocator
public PortletApplicationContextLocator()
-
-
Method Details
-
contextInitialized
public void contextInitialized(javax.servlet.ServletContextEvent sce) - Specified by:
contextInitializedin interfacejavax.servlet.ServletContextListener
-
contextDestroyed
public void contextDestroyed(javax.servlet.ServletContextEvent sce) - Specified by:
contextDestroyedin interfacejavax.servlet.ServletContextListener
-
isRunningInWebApplication
Deprecated.Only needed for usinggetRequiredWebApplicationContext()orgetWebApplicationContext().isRunningInWebApplication.
- Returns:
trueif a WebApplicationContext is available,falseif only an ApplicationContext is available
-
getRequiredWebApplicationContext
@Deprecated public static org.springframework.web.context.WebApplicationContext getRequiredWebApplicationContext()Deprecated.This method is a work-around for areas in uPortal that do not have the ability to use theWebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext)directly.getRequiredWebApplicationContext.
- Returns:
- The WebApplicationContext for the portal
- Throws:
IllegalStateException- if no ServletContext is available to retrieve a WebApplicationContext for or if the root WebApplicationContext could not be found
-
getWebApplicationContext
@Deprecated public static org.springframework.web.context.WebApplicationContext getWebApplicationContext()Deprecated.This method is a work-around for areas in uPortal that do not have the ability to use theWebApplicationContextUtils.getWebApplicationContext(ServletContext)directly.getWebApplicationContext.
- Returns:
- The WebApplicationContext for the portal, null if no ServletContext is available
-
getApplicationContext
public static org.springframework.context.ApplicationContext getApplicationContext(String importExportContextFile) If running in a web application the existingWebApplicationContextwill be returned. if not a singletonApplicationContextis created if needed and returned. Unless aWebApplicationContextis specifically needed this method should be used as it will work both when running in and out of a web application- Parameters:
importExportContextFile- aStringobject- Returns:
- The
ApplicationContextfor the portal.
-
shutdown
public static void shutdown()If the ApplicationContext returned bygetApplicationContext(String)is 'portal managed' the shutdown hook for the context is called, closing and cleaning up all spring managed resources. If the ApplicationContext returned bygetApplicationContext(String)is actually a WebApplicationContext this method does nothing but log an error message.
-
WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext)directly.