Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arthurtsang/5268194 to your computer and use it in GitHub Desktop.
Save arthurtsang/5268194 to your computer and use it in GitHub Desktop.
Bean definition parser for custom spring namespace
public class DynamicServiceActivatorBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
protected Class getBeanClass(Element element) {
return DefaultDynamicServiceActivator.class;
}
@Override
protected void doParse(Element element, BeanDefinitionBuilder bean) {
List<Element> methodElements = DomUtils.getChildElementsByTagName(element, "method");
ManagedMap<String, BeanDefinition> methodMetadataMap = null;
if (methodElements != null && methodElements.size() > 0) {
methodMetadataMap = new ManagedMap<String, BeanDefinition>();
}
for (Element methodElement : methodElements) {
String methodName = methodElement.getAttribute("name");
BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(
"...DynamicServiceActivatorMethod");
methodMetadataBuilder.addPropertyValue("name",methodName);
methodMetadataBuilder.addPropertyValue("replyChannel", methodElement.getAttribute("reply-channel"));
methodMetadataBuilder.addPropertyValue("expression", methodElement.getAttribute("expression"));
methodMetadataMap.put(methodName, methodMetadataBuilder.getBeanDefinition());
}
bean.addPropertyValue("methodMetadataMap", methodMetadataMap);
bean.getBeanDefinition().setScope("prototype");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment