Map<String, Service> services,
Map<String, ComponentService> componentServices) {
// Connect each component service to the corresponding service
for (ComponentService componentService : component.getServices()) {
Service service = services.get(componentService.getName());
if (service != null) {
componentService.setService(service);
} else {
warning("Service not found for component service: " + component.getName()
+ "/"
+ componentService.getName(), component);
}
}
// 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
if (componentService.getInterfaceContract() != null) {
if (!componentService.getInterfaceContract().equals(service
.getInterfaceContract())) {
if (!interfaceContractMapper.isCompatible(componentService
.getInterfaceContract(), service.getInterfaceContract())) {
warning("Component service interface incompatible with service interface: " + component
.getName()
+ "/"
+ componentService.getName(),
component);
}
}
} else {
componentService.setInterfaceContract(service.getInterfaceContract());
}
// 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());
}
}
}
}