/******************************************************************************
* 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.context.support;
import org.eclipse.gemini.blueprint.context.BundleContextAware;
import org.osgi.framework.BundleContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
/**
* {@link BeanPostProcessor} handling classes that implement
* <code>BundleContextAware</code> interface.
*
* @author Adrian Colyer
* @author Costin Leau
*/
public class BundleContextAwareProcessor implements BeanPostProcessor {
private final BundleContext bundleContext;
public BundleContextAwareProcessor(BundleContext aContext) {
this.bundleContext = aContext;
}
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof BundleContextAware) {
((BundleContextAware) bean).setBundleContext(this.bundleContext);
}
return bean;
}
}