}
return metadata;
}
private ComponentMetadata parseBeanMetadata(Element element, boolean topElement) {
BeanMetadataImpl metadata = new BeanMetadataImpl();
if (topElement) {
metadata.setId(getId(element));
if (element.hasAttribute(SCOPE_ATTRIBUTE)) {
metadata.setScope(element.getAttribute(SCOPE_ATTRIBUTE));
if (metadata.getScope().equals(BeanMetadata.SCOPE_PROTOTYPE)) {
if (element.hasAttribute(ACTIVATION_ATTRIBUTE)) {
if (element.getAttribute(ACTIVATION_ATTRIBUTE).equals(ACTIVATION_EAGER)) {
throw new ComponentDefinitionException("A <bean> with a prototype scope can not have an eager activation");
}
}
metadata.setActivation(ComponentMetadata.ACTIVATION_LAZY);
} else {
metadata.setActivation(parseActivation(element));
}
} else {
metadata.setActivation(parseActivation(element));
}
} else {
metadata.setActivation(ComponentMetadata.ACTIVATION_LAZY);
}
if (element.hasAttribute(CLASS_ATTRIBUTE)) {
metadata.setClassName(element.getAttribute(CLASS_ATTRIBUTE));
}
if (element.hasAttribute(DEPENDS_ON_ATTRIBUTE)) {
metadata.setDependsOn(parseList(element.getAttribute(DEPENDS_ON_ATTRIBUTE)));
}
if (element.hasAttribute(INIT_METHOD_ATTRIBUTE)) {
metadata.setInitMethod(element.getAttribute(INIT_METHOD_ATTRIBUTE));
}
if (element.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) {
metadata.setDestroyMethod(element.getAttribute(DESTROY_METHOD_ATTRIBUTE));
}
if (element.hasAttribute(FACTORY_REF_ATTRIBUTE)) {
metadata.setFactoryComponent(new RefMetadataImpl(element.getAttribute(FACTORY_REF_ATTRIBUTE)));
}
if (element.hasAttribute(FACTORY_METHOD_ATTRIBUTE)) {
String factoryMethod = element.getAttribute(FACTORY_METHOD_ATTRIBUTE);
metadata.setFactoryMethod(factoryMethod);
}
// Do some validation
if (metadata.getClassName() == null && metadata.getFactoryComponent() == null) {
throw new ComponentDefinitionException("Bean class or factory-ref must be specified");
}
if (metadata.getFactoryComponent() != null && metadata.getFactoryMethod() == null) {
throw new ComponentDefinitionException("factory-method is required when factory-component is set");
}
if (MetadataUtil.isPrototypeScope(metadata) && metadata.getDestroyMethod() != null) {
throw new ComponentDefinitionException("destroy-method must not be set for a <bean> with a prototype scope");
}
// Parse elements
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element e = (Element) node;
if (isBlueprintNamespace(node.getNamespaceURI())) {
if (nodeNameEquals(node, ARGUMENT_ELEMENT)) {
metadata.addArgument(parseBeanArgument(metadata, e));
} else if (nodeNameEquals(node, PROPERTY_ELEMENT)) {
metadata.addProperty(parseBeanProperty(metadata, e));
}
}
}
}
MetadataUtil.validateBeanArguments(metadata.getArguments());
ComponentMetadata m = metadata;
// Parse custom scopes
m = handleCustomScope(element.getAttributeNode(SCOPE_ATTRIBUTE), element, m);