in modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java [705:796]
private void validateBeans(List<SpringBeanElement> beans,
List<SpringSCAServiceElement> services,
List<SpringSCAReferenceElement> references,
List<SpringSCAPropertyElement> scaproperties,
Monitor monitor) throws ContributionReadException {
// The value of the @name attribute of an <sca:service/> subelement of a <beans/> element
// MUST be unique amongst the <service/> subelements of the <beans/> element.
for (SpringSCAServiceElement serviceElement : services) {
for (SpringSCAServiceElement x : services) {
if (serviceElement != x && serviceElement.getName().equals(x.getName())) {
error(monitor, "ScaServiceNameNotUnique", beans);
}
}
}
// The @target attribute of a <service/> subelement of a <beans/> element
// MUST have the value of the @name attribute of one of the <bean/>
// subelements of the <beans/> element.
Iterator<SpringSCAServiceElement> its = services.iterator();
while (its.hasNext()) {
SpringSCAServiceElement serviceElement = its.next();
boolean targetBeanExists = false;
Iterator<SpringBeanElement> itb = beans.iterator();
while (itb.hasNext()) {
SpringBeanElement beanElement = itb.next();
if (serviceElement.getTarget().equals(beanElement.getId()))
targetBeanExists = true;
}
if (!targetBeanExists) {
// REVIEW: [rfeng] The target bean can exist in the parent Spring application context which we don't know
// until runtime
warning(monitor, "TargetBeanDoesNotExist", beans);
}
} // end while
// The value of the @name attribute of an <sca:reference/> subelement of a <beans/>
// element MUST be unique amongst the @name attributes of the <sca:property/>
// subelements and the <bean/> subelements of the <beans/> element.
// AND
// The @default attribute of a <sca:reference/> subelement of a <beans/>
// element MUST have the value of the @name attribute of one of the <bean/>
// subelements of the <beans/> element.
Iterator<SpringSCAReferenceElement> itr = references.iterator();
while (itr.hasNext()) {
SpringSCAReferenceElement referenceElement = itr.next();
boolean defaultBeanExists = false;
boolean isUniqueReferenceName = true;
Iterator<SpringBeanElement> itb = beans.iterator();
while (itb.hasNext()) {
SpringBeanElement beanElement = itb.next();
if (referenceElement.getDefaultBean() != null)
if (referenceElement.getDefaultBean().equals(beanElement.getId()))
defaultBeanExists = true;
if (referenceElement.getName().equals(beanElement.getId()))
isUniqueReferenceName = false;
}
Iterator<SpringSCAPropertyElement> itp = scaproperties.iterator();
while (itp.hasNext()) {
SpringSCAPropertyElement propertyElement = itp.next();
if (referenceElement.getName().equals(propertyElement.getName()))
isUniqueReferenceName = false;
}
if (!defaultBeanExists && referenceElement.getDefaultBean() != null)
error(monitor, "DefaultBeanDoesNotExist", beans);
if (!isUniqueReferenceName)
error(monitor, "ScaReferenceNameNotUnique", beans);
} // end while
// The value of the @name attribute of an <sca:property/> subelement of a <beans/>
// element MUST be unique amongst the @name attributes of the <sca:reference/>
// subelements and the <bean/> subelements of the <beans/> element.
Iterator<SpringSCAPropertyElement> itp = scaproperties.iterator();
while (itp.hasNext()) {
SpringSCAPropertyElement propertyElement = itp.next();
boolean isUniquePropertyName = true;
Iterator<SpringBeanElement> itb = beans.iterator();
while (itb.hasNext()) {
SpringBeanElement beanElement = itb.next();
if (propertyElement.getName().equals(beanElement.getId()))
isUniquePropertyName = false;
}
Iterator<SpringSCAReferenceElement> itrp = references.iterator();
while (itrp.hasNext()) {
SpringSCAReferenceElement referenceElement = itrp.next();
if (propertyElement.getName().equals(referenceElement.getName()))
isUniquePropertyName = false;
}
if (!isUniquePropertyName)
error(monitor, "ScaPropertyNameNotUnique", beans);
} // end while
}