return component;
}
private ComponentMetadata decorateManagedProperties(ParserContext context, Element element, ComponentMetadata component) {
if (!(component instanceof MutableBeanMetadata)) {
throw new ComponentDefinitionException("Element " + MANAGED_PROPERTIES_ELEMENT + " must be used inside a <bp:bean> element");
}
generateIdIfNeeded(context, ((MutableBeanMetadata) component));
MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
metadata.setProcessor(true);
metadata.setId(getId(context, element));
metadata.setRuntimeClass(CmManagedProperties.class);
String persistentId = element.getAttribute(PERSISTENT_ID_ATTRIBUTE);
// if persistentId is "" the managed properties element in nested in managed-service-factory
// and the configuration object will come from the factory. So we only really need to register
// ManagedService if the persistentId is not an empty string.
if (persistentId.length() > 0) {
metadata.setInitMethod("init");
metadata.setDestroyMethod("destroy");
}
metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
metadata.addProperty("configAdmin", createConfigAdminProxy(context));
metadata.addProperty("managedObjectManager", createRef(context, MANAGED_OBJECT_MANAGER_NAME));
metadata.addProperty("persistentId", createValue(context, persistentId));
String updateStrategy = element.getAttribute(UPDATE_STRATEGY_ATTRIBUTE);
if (updateStrategy != null) {
metadata.addProperty("updateStrategy", createValue(context, updateStrategy));
}
if (element.hasAttribute(UPDATE_METHOD_ATTRIBUTE)) {
metadata.addProperty("updateMethod", createValue(context, element.getAttribute(UPDATE_METHOD_ATTRIBUTE)));
} else if ("component-managed".equals(updateStrategy)) {
throw new ComponentDefinitionException(UPDATE_METHOD_ATTRIBUTE + " attribute must be set when " + UPDATE_STRATEGY_ATTRIBUTE + " is set to 'component-managed'");
}
metadata.addProperty("beanName", createIdRef(context, component.getId()));
context.getComponentDefinitionRegistry().registerComponentDefinition(metadata);
return component;
}