try {
// Deal with the services first....
Iterator<SpringSCAServiceElement> its = services.iterator();
while (its.hasNext()) {
SpringSCAServiceElement serviceElement = its.next();
Class<?> interfaze;
if (serviceElement.getType() != null) {
interfaze = resolveClass(resolver, serviceElement.getType(), context);
} else {
interfaze = getBeanInterface(resolver, serviceElement.getTarget(), beans, context);
}
Service theService = createService(interfaze, serviceElement.getName());
// Spring allows duplication of bean definitions in multiple context scenario,
// in such cases, the latest bean definition overrides the older ones, hence
// we will remove any older definition and use the latest.
Service duplicate = null;
for (Service service : componentType.getServices()) {
if (service.getName().equals(theService.getName()))
duplicate = service;
}
if (duplicate != null)
componentType.getServices().remove(duplicate);
componentType.getServices().add(theService);
// Add this service to the Service / Bean map
String beanName = serviceElement.getTarget();
boolean found = false;
for (SpringBeanElement beanElement : beans) {
if (beanName.equals(beanElement.getId())) {
if (isValidBeanForService(beanElement)) {
// add the required intents and policySets for the service
theService.getRequiredIntents().addAll(serviceElement.getRequiredIntents());
theService.getPolicySets().addAll(serviceElement.getPolicySets());
implementation.setBeanForService(theService, beanElement);
found = true;
break;
}
}
} // end for
if (!found) {
// REVIEW: Adding a SpringBeanElement "proxy" so that the bean id can be used at runtime to look
// up the bean instance from the parent context
implementation.setBeanForService(theService,
new SpringBeanElement(serviceElement.getTarget(), null));
}
} // end while
// Next handle the references
Iterator<SpringSCAReferenceElement> itr = references.iterator();