"as the service object could not be obtained.", new Object[]{reference});
return null;
}
DynamicConfigurationService dcs = serviceLocator.getService(DynamicConfigurationService.class);
DynamicConfiguration config = dcs.createDynamicConfiguration();
AbstractActiveDescriptor<Object> descriptor = BuilderHelper.createConstantDescriptor(object);
// let's get the list of implemented contracts
String[] contractNames = (String[]) reference.getProperty("objectclass");
if (contractNames != null && contractNames.length > 0) {
// we will register this service under each contract it implements
for (String contractName : contractNames) {
String name = (String) reference.getProperty("component.name");
if (name == null) {
// let's get a name if possible, that will only work with Spring OSGi services
// we may need to find a better way to get a potential name.
name = (String) reference.getProperty("org.springframework.osgi.bean.name");
}
try {
final Class<?> contractType =
Class.forName(contractName, false, object.getClass().getClassLoader());
descriptor.addContractType(contractType);
if (name != null)
descriptor.setName(name);
logger.logp(Level.FINE, "HK2Main$HK2ServiceTrackerCustomizer",
"addingService", "registering service = {0}, contract = {1}, name = {2}", new Object[]{
object, contractName, name});
} catch (ClassNotFoundException e) {
logger.log(Level.SEVERE, "Cannot resolve contract " + contractName, e);
}
}
} else {
// this service does not implement a specific contract, let's register it by its type.
logger.logp(Level.FINE, "HK2Main$HK2ServiceTrackerCustomizer",
"addingService", "registering service = {0}", object);
}
config.addActiveDescriptor(descriptor);
config.commit();
return descriptor;
}