This commit is contained in:
Oleg Zhurakousky
2009-06-19 03:41:47 +00:00
parent db3b34fc9a
commit d058c511b6

View File

@@ -0,0 +1,59 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.config.xml;
import java.util.List;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.router.PayloadTypeRouter;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
/**
* Parser for the <payload-type-router/> element.
*
* @author Oleg Zhurakousky
*/
public class PayloadTypeRouterParser extends RouterParser {
@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder payloadTypeRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(PayloadTypeRouter.class);
List<Element> childElements = DomUtils.getChildElementsByTagName(element, "mapping");
Assert.notEmpty(childElements, "Type mapping must be provided (e.g., <mapping type=\"X\" channel=\"channel1\"/>)");
ManagedMap channelMap = new ManagedMap();
for (Element childElement : childElements) {
String typeName = childElement.getAttribute("type");
Assert.isTrue(ClassUtils.isPresent(typeName, ClassUtils.getDefaultClassLoader()), typeName + " can not be loaded");
channelMap.put(typeName, new RuntimeBeanReference(childElement.getAttribute("channel")));
}
payloadTypeRouterBuilder.addPropertyValue("payloadTypeChannelMap", channelMap);
BeanDefinitionBuilder rootBuilder = this.createBuilder();
rootBuilder.addPropertyValue("targetObject", payloadTypeRouterBuilder.getBeanDefinition());
return this.doParse(element, parserContext, rootBuilder);
}
}