@Override public void registrationAdded(final Registration onmsRegistration) { final Map<String, String> onmsProperties = onmsRegistration.getProperties() == null ? Collections.<String,String>emptyMap() : onmsRegistration.getProperties(); if (OSGI_SOURCE.equals(onmsProperties.get(REGISTRATION_SOURCE))) return; final Class<?>[] providerInterfaces = onmsRegistration.getProvidedInterfaces(); final String[] serviceClasses = new String[providerInterfaces.length]; for(int i = 0; i < providerInterfaces.length; i++) { serviceClasses[i] = providerInterfaces[i].getName(); } final Dictionary<String,String> props = new Hashtable<String,String>(); for(final Entry<String, String> entry : onmsProperties.entrySet()) { props.put(entry.getKey(), entry.getValue()); } props.put(REGISTRATION_SOURCE, ONMS_SOURCE); final BundleContext bundleContext = m_bundleContext.get(); if (bundleContext != null) { ServiceRegistration<?> osgiRegistration = bundleContext.registerService(serviceClasses, onmsRegistration.getProvider(), props); m_onmsRegistration2osgiRegistrationMap.put(onmsRegistration, osgiRegistration); } }
@Override public void registrationAdded(final Registration onmsRegistration) { final Map<String, String> onmsProperties = onmsRegistration.getProperties() == null ? Collections.<String,String>emptyMap() : onmsRegistration.getProperties(); if (OSGI_SOURCE.equals(onmsProperties.get(REGISTRATION_SOURCE))) return; final Class<?>[] providerInterfaces = onmsRegistration.getProvidedInterfaces(); final String[] serviceClasses = new String[providerInterfaces.length]; for(int i = 0; i < providerInterfaces.length; i++) { serviceClasses[i] = providerInterfaces[i].getName(); } final Dictionary<String,String> props = new Hashtable<String,String>(); for(final Entry<String, String> entry : onmsProperties.entrySet()) { props.put(entry.getKey(), entry.getValue()); } props.put(REGISTRATION_SOURCE, ONMS_SOURCE); final BundleContext bundleContext = m_bundleContext.get(); if (bundleContext != null) { ServiceRegistration<?> osgiRegistration = bundleContext.registerService(serviceClasses, onmsRegistration.getProvider(), props); m_onmsRegistration2osgiRegistrationMap.put(onmsRegistration, osgiRegistration); } }
@Test @DirtiesContext public void testInjected() { assertEquals(m_provider, m_simpleRegistration.getProvider(Hello.class)); assertContains(m_simpleRegistration.getProvidedInterfaces(), Hello.class); assertEquals(m_provider, m_nestedRegistration.getProvider(Hello.class)); assertContains(m_nestedRegistration.getProvidedInterfaces(), Hello.class, Goodbye.class); }