5.3 Programmatic Access to Personality-specific Features

Module personalities typically provide automatic access to features specific to the personality via custom manifest headers or other configuration mechanisms. There may be situations, however, for which programmatic access to such features is desirable or necessary. This section describes how to programmatically access personality-specific features from application code in a module.

5.3.1 Programmatic Access to Web Personality Features

5.3.1.1 Programmatic Access to the ApplicationContext

The SpringSource Application Platform automatically creates an ApplicationContext for Web Modules and Shared Services WARs which have Spring-DM powered ApplicationContext XML configuration files. For Web Modules in particular, a WebApplicationContext will be created which is typically used in conjunction with an auto-configured Spring MVC DispatcherServlet. In such scenarios, there is generally no need to access the WebApplicationContext programmatically, since all components of the web application are configured within the scope of the WebApplicationContext itself. For Shared Services WARs, or for Web Modules which do not directly rely on Spring MVC, you can alternatively access the Spring-DM powered ApplicationContext via the web application's ServletContext. The Web Personality subsystem stores the bundle's ApplicationContext in the ServletContext under the attribute name "BSN-ApplicationContext", where BSN is the Bundle-SymobolicName of your Shared Services WAR or Web Module. Thus, for a Web Module, you can use Spring MVC's WebApplicationContextUtils.getWebApplicationContext(servletContext, attributeName) method (or other means) to programmatically retrieve a reference to the WebApplicationContext, which is an instance of PlatformOsgiBundleXmlWebApplicationContext. For Shared Services WARs, you can programmatically retrieve the ApplicationContext directly from the ServletContext.

5.3.1.2 Programmatic Access to the BundleContext

Similar to programmatic access to the ApplicationContext as described above, you can access the BundleContext of your Shared Services WAR or Web Module via the web application's ServletContext. The Web Personality subsystem stores the bundle context under the attribute name with the value of the PlatformOsgiBundleXmlWebApplicationContext.BUNDLE_CONTEXT_ATTRIBUTE constant.

[Note]Note

PlatformOsgiBundleXmlWebApplicationContext resides in the com.springsource.platform.web.dm package which is automatically imported in your Web Module's or Shared Services WAR's bundle manifest.