4.5 Programmatic Access to Personality-specific Features
Prev | 4. Developing Applications | Next

## 4.5 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.

### Programmatic Access to Web Personality Features

#### Programmatic Access to the WebApplicationContext

The Virgo Web Server automatically creates a `WebApplicationContext` for Web Bundles and WAR files. When used in conjuction with an an auto-configured Spring MVC `DispatcherServlet`, 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. However, if you wish to access the `WebApplicationContext` you can do so via the web application’s `ServletContext`. The Web Personality subsystem stores the bundle’s `WebApplicationContext` in the ServletContext under the attribute name "`BSN-ApplicationContext`", where `BSN` is the `Bundle-SymbolicName` of your WAR or Web Bundle.

Alternatively, since the Web Personality subsystem also stores the `WebApplicationContext` under the attribute name with the value of the `WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE` constant, you may choose to use Spring MVC’s WebApplicationContextUtils’ `getWebApplicationContext(servletContext)` or `getRequiredWebApplicationContext(servletContext)` methods to access the `WebApplicationContext` without providing an explicit attribute name.

#### Programmatic Access to the BundleContext

As required by the OSGi Web Container specification, you can access the `BundleContext` of your WAR or Web Bundle via the web application’s `ServletContext`. The bundle context is stored in the `ServletContext` under the attribute name `osgi-bundlecontext`.

Prev | Up | Next
4.4 Creating and Using Configuration Artifacts | Home | 4.6 Automatic Imports