// Connect each component service to the corresponding service
for (ComponentService componentService : component.getServices()) {
if (componentService.getService() != null || componentService.isCallback()) {
continue;
}
Service service = services.get(componentService.getName());
if (service != null) {
componentService.setService(service);
} else {
warning(monitor, "ServiceNotFoundForComponentService", component, component.getName(), componentService.getName());
}
}
// Create a component service for each service
if (component.getImplementation() != null) {
for (Service service : component.getImplementation().getServices()) {
if (!componentServices.containsKey(service.getName())) {
ComponentService componentService = assemblyFactory.createComponentService();
componentService.setIsCallback(service.isCallback());
String name = service.getName();
componentService.setName(name);
componentService.setService(service);
component.getServices().add(componentService);
componentServices.put(name, componentService);
}
}
}
//Reconcile each component service with its service
for (ComponentService componentService : component.getServices()) {
Service service = componentService.getService();
if (service != null) {
// Reconcile interface
InterfaceContract interfaceContract = service.getInterfaceContract();
if (componentService.getInterfaceContract() != null) {
if (interfaceContract != null && !componentService.getInterfaceContract().equals(interfaceContract)) {
if (!interfaceContractMapper.isCompatible(componentService.getInterfaceContract(),
interfaceContract)) {
warning(monitor, "ServiceIncompatibleComponentInterface", component, component.getName(), componentService.getName());
}
}
} else {
componentService.setInterfaceContract(interfaceContract);
}
// Reconcile bindings
if (componentService.getBindings().isEmpty()) {
componentService.getBindings().addAll(service.getBindings());
}
// Reconcile callback bindings
if (componentService.getCallback() == null) {
componentService.setCallback(service.getCallback());
if (componentService.getCallback() == null) {
// Create an empty callback to avoid null check
componentService.setCallback(assemblyFactory.createCallback());
}
} else if (componentService.getCallback().getBindings().isEmpty() && service
.getCallback() != null) {
componentService.getCallback().getBindings().addAll(service.getCallback()
.getBindings());
}
}
}
}