* @param resolver
* @param impl
*/
private void mergeComponentType(ModelResolver resolver, JavaImplementation impl) {
// FIXME: Need to clarify how to merge
ComponentType componentType = getComponentType(resolver, impl);
if (componentType != null && !componentType.isUnresolved()) {
Map<String, Reference> refMap = new HashMap<String, Reference>();
for (Reference ref : impl.getReferences()) {
refMap.put(ref.getName(), ref);
}
for (Reference reference : componentType.getReferences()) {
refMap.put(reference.getName(), reference);
}
impl.getReferences().clear();
impl.getReferences().addAll(refMap.values());
// Try to match references by type
Map<String, JavaElementImpl> refMembers = impl.getReferenceMembers();
for (Reference ref : impl.getReferences()) {
if (ref.getInterfaceContract() != null) {
Interface i = ref.getInterfaceContract().getInterface();
if (i instanceof JavaInterface) {
Class<?> type = ((JavaInterface)i).getJavaClass();
if (!refMembers.containsKey(ref.getName())) {
JavaElementImpl e = getMemeber(impl, ref.getName(), type);
if (e != null) {
refMembers.put(ref.getName(), e);
}
}
}
}
}
Map<String, Service> serviceMap = new HashMap<String, Service>();
for (Service svc : impl.getServices()) {
serviceMap.put(svc.getName(), svc);
}
for (Service service : componentType.getServices()) {
serviceMap.put(service.getName(), service);
}
impl.getServices().clear();
impl.getServices().addAll(serviceMap.values());
Map<String, Property> propMap = new HashMap<String, Property>();
for (Property prop : impl.getProperties()) {
propMap.put(prop.getName(), prop);
}
for (Property property : componentType.getProperties()) {
propMap.put(property.getName(), property);
}
impl.getProperties().clear();
impl.getProperties().addAll(propMap.values());
if (componentType.getConstrainingType() != null) {
impl.setConstrainingType(componentType.getConstrainingType());
}
}
}