Last active
March 18, 2020 09:23
-
-
Save arthurtsang/5268194 to your computer and use it in GitHub Desktop.
Bean definition parser for custom spring namespace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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