Source:
public void start(BundleContext context) throws Exception { registry = new ScriptProcessorRegistry(); serviceRegistration = context.registerService(ScriptProcessorRegistry.class.getName(), registry, null); context.addBundleListener(new BundleListener() { @Override public void bundleChanged(BundleEvent event) { processBundleExtensions(event.getBundle(), event.getType(), registry); } private void processBundleExtensions(Bundle bundle, int state, ScriptProcessorRegistry registry) { String scriptCfgs = (String) bundle.getHeaders().get("Script-Processor-Classes"); if (hasText(scriptCfgs)) { String[] names = scriptCfgs.split(","); for (String name : names) { name = name.trim(); if (state == BundleEvent.STARTED) { try { final Class<? extends ScriptProcessor> scriptProcessorClass = (Class<? extends ScriptProcessor>) bundle.loadClass(name); final String finalName = name; registry.registerProcessor(scriptProcessorClass.getSimpleName(), new Func<ScriptProcessor>() { @Override public ScriptProcessor invoke() { try { return scriptProcessorClass.newInstance(); } catch (InstantiationException e) { logger.severe(e.getMessage()); } catch (IllegalAccessException e) { logger.severe(e.getMessage()); } logger.severe("Cannot register script processor: " + finalName); return null; } }); } catch (Exception e) { logger.severe(e.getMessage()); } } else if (state == BundleEvent.UNINSTALLED) { final Class<? extends ScriptProcessor> scriptProcessorClass; try { scriptProcessorClass = (Class<? extends ScriptProcessor>) bundle.loadClass(name); registry.unregisterProcessor(scriptProcessorClass.getSimpleName()); } catch (ClassNotFoundException e) { logger.severe(e.getMessage()); logger.severe("Cannot unregister script processor: " + name); } } } } } }); }

Target:
public void start(BundleContext context) throws Exception { registry = new ScriptProcessorRegistry(); serviceRegistration = context.registerService(ScriptProcessorRegistry.class.getName(), registry, null); context.addBundleListener(new BundleListener() { @Override public void bundleChanged(BundleEvent event) { processBundleExtensions(event.getBundle(), event.getType(), registry); } private void processBundleExtensions(Bundle bundle, int state, ScriptProcessorRegistry registry) { String scriptCfgs = (String) bundle.getHeaders().get("Script-Processor-Classes"); if (hasText(scriptCfgs)) { String[] names = scriptCfgs.split(","); for (String name : names) { name = name.trim(); if (state == BundleEvent.STARTED) { try { final Class<? extends ScriptProcessor> scriptProcessorClass = (Class<? extends ScriptProcessor>) bundle.loadClass(name); final String finalName = name; registry.registerProcessor(scriptProcessorClass.getSimpleName(), new Func<ScriptProcessor>() { @Override public ScriptProcessor invoke() { try { return scriptProcessorClass.newInstance(); } catch (InstantiationException e) { logger.log(Level.SEVERE, e.getMessage(), e); } catch (IllegalAccessException e) { logger.log(Level.SEVERE, e.getMessage(), e); } logger.severe("Cannot register script processor: " + finalName); return null; } }); } catch (Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); } } else if (state == BundleEvent.UNINSTALLED) { final Class<? extends ScriptProcessor> scriptProcessorClass; try { scriptProcessorClass = (Class<? extends ScriptProcessor>) bundle.loadClass(name); registry.unregisterProcessor(scriptProcessorClass.getSimpleName()); } catch (ClassNotFoundException e) { logger.log(Level.SEVERE, e.getMessage(), e); logger.severe("Cannot unregister script processor: " + name); } } } } } }); }