List<SpringBeanElement> beans,
List<SpringSCAServiceElement> services,
List<SpringSCAReferenceElement> references,
List<SpringSCAPropertyElement> scaproperties, ProcessorContext context) throws ContributionReadException {
SpringBeanElement bean = null;
try {
boolean completed = false;
while (!completed) {
switch (reader.next()) {
case START_ELEMENT:
QName qname = reader.getName();
//System.out.println("Spring TypeLoader - found element with name: " + qname.toString());
if (SpringImplementationConstants.IMPORT_ELEMENT.equals(qname)) {
//FIXME - put the sequence of code below which gets the ireader into a subsidiary method
String location = reader.getAttributeValue(null, "resource");
if (location != null) {
// FIXME - need to find a right way of generating this path
String resourcePath = contextPath.substring(0, contextPath.lastIndexOf("/")+1) + location;
XMLStreamReader ireader = getApplicationContextReader(resolver, resourcePath, context);
// Read the context definition for the identified imported resource
readContextDefinition(resolver, ireader, contextPath, beans, services, references, scaproperties, context);
}
} else if (SpringImplementationConstants.SCA_SERVICE_ELEMENT.equals(qname)) {
// The value of the @name attribute of an <sca:service/> subelement of a <beans/>
// element MUST be unique amongst the <sca:service/> subelements of the <beans/> element.
if (!services.isEmpty() && (services.contains(reader.getAttributeValue(null, "name"))))
error("ScaServiceNameNotUnique", resolver);
SpringSCAServiceElement service =
new SpringSCAServiceElement(reader.getAttributeValue(null, "name"),
reader.getAttributeValue(null, "target"));
if (reader.getAttributeValue(null, "type") != null)
service.setType(reader.getAttributeValue(null, "type"));
policyProcessor.readPolicies(service, reader);
services.add(service);
} else if (SpringImplementationConstants.SCA_REFERENCE_ELEMENT.equals(qname)) {
// 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:reference/> subelements,
// of the <beans/> element.
if (!references.isEmpty() && (references.contains(reader.getAttributeValue(null, "name"))))
error("ScaReferenceNameNotUnique", resolver);
SpringSCAReferenceElement reference =
new SpringSCAReferenceElement(reader.getAttributeValue(null, "name"),
reader.getAttributeValue(null, "type"));
if (reader.getAttributeValue(null, "default") != null)
reference.setDefaultBean(reader.getAttributeValue(null, "default"));
policyProcessor.readPolicies(reference, reader);
references.add(reference);
} else if (SpringImplementationConstants.SCA_PROPERTY_ELEMENT.equals(qname)) {
// 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:property/> subelements,
// of the <beans/> element.
if (!scaproperties.isEmpty() && (scaproperties.contains(reader.getAttributeValue(null, "name"))))
error("ScaPropertyNameNotUnique", resolver);
SpringSCAPropertyElement scaproperty =
new SpringSCAPropertyElement(reader.getAttributeValue(null, "name"), reader
.getAttributeValue(null, "type"));
scaproperties.add(scaproperty);
} else if (SpringImplementationConstants.BEAN_ELEMENT.equals(qname)) {
bean = new SpringBeanElement(reader.getAttributeValue(null, "id"),
reader.getAttributeValue(null, "class"));
if (reader.getAttributeValue(null, "abstract") != null)
if (reader.getAttributeValue(null, "abstract").equals("true"))
bean.setAbstractBean(true);
if (reader.getAttributeValue(null, "parent") != null)
if (!reader.getAttributeValue(null, "parent").equals(""))
bean.setParentAttribute(true);
if (reader.getAttributeValue(null, "factory-bean") != null)
if (!reader.getAttributeValue(null, "factory-bean").equals(""))
bean.setFactoryBeanAttribute(true);
if (reader.getAttributeValue(null, "factory-method") != null)
if (!reader.getAttributeValue(null, "factory-method").equals(""))
bean.setFactoryMethodAttribute(true);
// Set the first name as bean name, when the @id attribute is absent.
if (reader.getAttributeValue(null, "id") == null) {
if (reader.getAttributeValue(null, "name") != null) {
String[] names = (reader.getAttributeValue(null, "name")).split(",");
bean.setId(names[0]);
}
}
beans.add(bean);
// Read the <bean> element and its child elements
readBeanDefinition(reader, bean, beans);