Skip to content

Instantly share code, notes, and snippets.

@pentaho-nbaker
Created August 18, 2015 19:46
Show Gist options
  • Save pentaho-nbaker/0396799e7ddefd5ec5da to your computer and use it in GitHub Desktop.
Save pentaho-nbaker/0396799e7ddefd5ec5da to your computer and use it in GitHub Desktop.
Setting BundleContext
package org.pentaho.platform.osgi;
import org.osgi.framework.BundleContext;
import org.pentaho.platform.engine.core.system.PentahoSystem;
import org.pentaho.platform.engine.core.system.objfac.OSGIObjectFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletContext;
/**
* Standard OSGI Activator class which is called when the OSGI environment is started. Work to integrate the OSGI
* container with the PentahoSystem is started from this class
*/
public class PentahoOSGIActivator {
private Logger logger = LoggerFactory.getLogger( getClass() );
private static OSGIObjectFactory objectFactory;
public void setBundleContext( BundleContext bundleContext ) throws Exception {
logger.debug( "Registering OSGIObjectFactory" );
if ( objectFactory != null ) {
logger.debug( "De-Registering Previous OSGIObjectFactory" );
PentahoSystem.deregisterObjectFactory( objectFactory );
}
objectFactory = new OSGIObjectFactory( bundleContext );
PentahoSystem.registerObjectFactory( objectFactory );
PentahoSystem.setBundleContext( bundleContext );
Object context = PentahoSystem.getApplicationContext().getContext();
if( context instanceof ServletContext ){
((ServletContext) context).setAttribute( BundleContext.class.getName(), bundleContext );
}
logger.debug( "OSGIObjectFactory installed" );
}
public void shutdown() {
if ( objectFactory != null ) {
PentahoSystem.deregisterObjectFactory( objectFactory );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment