@Test public void shouldRegisterItselfAsListenerOnStartWhenNoConfigurationAdminServiceReferenceIsFound() throws Exception { BundleContext bundleContext = mock(BundleContext.class); when(bundleContext.getServiceReference(CONFIG_ADMIN_NAME)).thenReturn(null); Activator activator = new Activator() { @Override protected AccessManagerFactoryTracker getAccessManagerFactoryTracker() { return mock(AccessManagerFactoryTracker.class); } }; activator.start(bundleContext); verify(bundleContext).addServiceListener(activator, "(" + Constants.OBJECTCLASS + "=" + CONFIG_ADMIN_NAME + ")"); }
@Override public void start( BundleContext bundleContext ) throws Exception { this.bundleContext = bundleContext; if (null == activatorHelper) { this.activatorHelper = getActivatorHelper(); } ServiceReference configurationAdminServiceReference = bundleContext.getServiceReference(CONFIG_ADMIN_NAME); if (null != configurationAdminServiceReference) { activatorHelper.verifyConfiguration(configurationAdminServiceReference); } else { bundleContext.addServiceListener(this, String.format("(%s=%s)", Constants.OBJECTCLASS, CONFIG_ADMIN_NAME)); } AccessManagerFactoryTracker accessManagerFactoryTracker = getAccessManagerFactoryTracker(); if (null == accessManagerFactoryTracker) { accessManagerFactoryTracker = this.accessManagerFactoryTracker = activatorHelper.createAccessManagerFactoryTracker(); } accessManagerFactoryTracker.open(); ClassLoader bundleClassLoader = new BundleClassLoaderFactory(bundleContext).getClassLoader((String[])null); I18n.setLocalizationRepository(new ClasspathLocalizationRepository(bundleClassLoader)); }
Activator implements BundleActivator, ServiceListener { @Override public void start( BundleContext bundleContext ) throws Exception { this.bundleContext = bundleContext; if (null == activatorHelper) { this.activatorHelper = getActivatorHelper(); } ServiceReference configurationAdminServiceReference = bundleContext.getServiceReference(CONFIG_ADMIN_NAME); if (null != configurationAdminServiceReference) { activatorHelper.verifyConfiguration(configurationAdminServiceReference); } else { bundleContext.addServiceListener(this, String.format("(%s=%s)", Constants.OBJECTCLASS, CONFIG_ADMIN_NAME)); } AccessManagerFactoryTracker accessManagerFactoryTracker = getAccessManagerFactoryTracker(); if (null == accessManagerFactoryTracker) { accessManagerFactoryTracker = this.accessManagerFactoryTracker = activatorHelper.createAccessManagerFactoryTracker(); } accessManagerFactoryTracker.open(); ClassLoader bundleClassLoader = new BundleClassLoaderFactory(bundleContext).getClassLoader((String[])null); I18n.setLocalizationRepository(new ClasspathLocalizationRepository(bundleClassLoader)); } }
Activator implements BundleActivator, ServiceListener { @Override public void start( BundleContext bundleContext ) throws Exception { this.bundleContext = bundleContext; if (null == activatorHelper) { this.activatorHelper = getActivatorHelper(); } ServiceReference configurationAdminServiceReference = bundleContext.getServiceReference(CONFIG_ADMIN_NAME); if (null != configurationAdminServiceReference) { activatorHelper.verifyConfiguration(configurationAdminServiceReference); } else { bundleContext.addServiceListener(this, String.format("(%s=%s)", Constants.OBJECTCLASS, CONFIG_ADMIN_NAME)); } AccessManagerFactoryTracker accessManagerFactoryTracker = getAccessManagerFactoryTracker(); if (null == accessManagerFactoryTracker) { accessManagerFactoryTracker = this.accessManagerFactoryTracker = activatorHelper.createAccessManagerFactoryTracker(); } accessManagerFactoryTracker.open(); ClassLoader bundleClassLoader = new BundleClassLoaderFactory(bundleContext).getClassLoader((String[])null); I18n.setLocalizationRepository(new ClasspathLocalizationRepository(bundleClassLoader)); }  }
Activator implements BundleActivator, ServiceListener { @Override public void start( BundleContext bundleContext ) throws Exception { this.bundleContext = bundleContext; if (null == activatorHelper) { this.activatorHelper = getActivatorHelper(); } ServiceReference configurationAdminServiceReference = bundleContext.getServiceReference(CONFIG_ADMIN_NAME); if (null != configurationAdminServiceReference) { activatorHelper.verifyConfiguration(configurationAdminServiceReference); } else { bundleContext.addServiceListener(this, String.format("(%s=%s)", Constants.OBJECTCLASS, CONFIG_ADMIN_NAME)); } AccessManagerFactoryTracker accessManagerFactoryTracker = getAccessManagerFactoryTracker(); if (null == accessManagerFactoryTracker) { accessManagerFactoryTracker = this.accessManagerFactoryTracker = activatorHelper.createAccessManagerFactoryTracker(); } accessManagerFactoryTracker.open(); ClassLoader bundleClassLoader = new BundleClassLoaderFactory(bundleContext).getClassLoader((String[])null); I18n.setLocalizationRepository(new ClasspathLocalizationRepository(bundleClassLoader)); }  @Override void serviceChanged( ServiceEvent event ); @Override void start( BundleContext bundleContext ); @Override void stop( BundleContext bundleContext ); }
Activator implements BundleActivator, ServiceListener { @Override public void start( BundleContext bundleContext ) throws Exception { this.bundleContext = bundleContext; if (null == activatorHelper) { this.activatorHelper = getActivatorHelper(); } ServiceReference configurationAdminServiceReference = bundleContext.getServiceReference(CONFIG_ADMIN_NAME); if (null != configurationAdminServiceReference) { activatorHelper.verifyConfiguration(configurationAdminServiceReference); } else { bundleContext.addServiceListener(this, String.format("(%s=%s)", Constants.OBJECTCLASS, CONFIG_ADMIN_NAME)); } AccessManagerFactoryTracker accessManagerFactoryTracker = getAccessManagerFactoryTracker(); if (null == accessManagerFactoryTracker) { accessManagerFactoryTracker = this.accessManagerFactoryTracker = activatorHelper.createAccessManagerFactoryTracker(); } accessManagerFactoryTracker.open(); ClassLoader bundleClassLoader = new BundleClassLoaderFactory(bundleContext).getClassLoader((String[])null); I18n.setLocalizationRepository(new ClasspathLocalizationRepository(bundleClassLoader)); }  @Override void serviceChanged( ServiceEvent event ); @Override void start( BundleContext bundleContext ); @Override void stop( BundleContext bundleContext );  }