All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.gemini.blueprint.extender.OsgiApplicationContextCreator Maven / Gradle / Ivy

/******************************************************************************
 * Copyright (c) 2006, 2010 VMware Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution. 
 * The Eclipse Public License is available at 
 * http://www.eclipse.org/legal/epl-v10.html and the Apache License v2.0
 * is available at http://www.opensource.org/licenses/apache2.0.php.
 * You may elect to redistribute this code under either of these licenses. 
 * 
 * Contributors:
 *   VMware Inc.
 *****************************************************************************/

package org.eclipse.gemini.blueprint.extender;

import org.eclipse.gemini.blueprint.context.DelegatedExecutionOsgiBundleApplicationContext;
import org.osgi.framework.BundleContext;

/**
 * Extender hook for customizing the OSGi application context creation. Each
 * bundle started by the OSGi platform can create (or customize) an application
 * context that becomes managed by the Spring-DM extender.
 * 
 * For example, to create an application context based on the presence of a
 * manifest header, one could use the following code:
 * 
 * 
 class HeaderBasedAppCtxCreator implements
 * OsgiApplicationContextCreator {
 * 
 * /** location header */ private static final String HEADER =
 * "Context-Locations";
 * 
 * 
 * public DelegatedExecutionOsgiBundleApplicationContext
 * createApplicationContext(BundleContext bundleContext) { Bundle owningBundle =
 * bundleContext.getBundle();
 * 
 * Object value = owningBundle.getHeaders().get(HEADER); String[] locations =
 * null; if (value != null && value instanceof String) { locations =
 * StringUtils.commaDelimitedListToStringArray((String) value); } else {
 * locations = <default values> }
 * 
 * // create application context from 'locations'
 * 
 * return applicationContext; } } 
* *

* Note: The application contexts should be only created and initialized * but not started (i.e. refresh() method should not be called). * *

* The recommended way of configuring the extender is to attach any relevant * OsgiApplicationContextCreator implementation as fragments to * extender bundle. Please see the OSGi specification and Spring-DM reference * documentation for more information on how to do that. * *

* Note the extender also supports OsgiBeanFactoryPostProcessor for * application context customization. * *

* The creation of an application context doesn't guarantee that a bundle * becomes Spring-DM managed. The Spring-DM extender can do additional post * filtering that can discard the bundle (and associated context). * * @author Costin Leau * */ public interface OsgiApplicationContextCreator { /** * Creates an application context for the given bundle context. If no * application context needs to be created, then null should be * returned. Exceptions will be caught and logged but will not prevent the * creation of other application contexts. * * @param bundleContext OSGi bundle context determining the context creation * @return null if no context should be created, non- * null otherwise * @throws Exception if something goes wrong */ DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(BundleContext bundleContext) throws Exception; }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy