Fixed FileTargetAdapterParser after changes to TargetAdapter (now a handler wrapped in endpoint)
This commit is contained in:
@@ -18,9 +18,14 @@ package org.springframework.integration.adapter.file.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.adapter.file.FileTargetAdapter;
|
||||
import org.springframework.integration.bus.Subscription;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
|
||||
/**
|
||||
* Parser for the <file-target/> element.
|
||||
@@ -30,7 +35,7 @@ import org.springframework.integration.adapter.file.FileTargetAdapter;
|
||||
public class FileTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return FileTargetAdapter.class;
|
||||
return DefaultMessageEndpoint.class;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
@@ -41,11 +46,15 @@ public class FileTargetAdapterParser extends AbstractSingleBeanDefinitionParser
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
String directory = element.getAttribute("directory");
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
RootBeanDefinition adapterDef = new RootBeanDefinition(FileTargetAdapter.class);
|
||||
adapterDef.getConstructorArgumentValues().addGenericArgumentValue(element.getAttribute("directory"));
|
||||
String adapterBeanName = parserContext.getReaderContext().generateBeanName(adapterDef);
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, adapterBeanName));
|
||||
builder.addPropertyReference("handler", adapterBeanName);
|
||||
String channel = element.getAttribute("channel");
|
||||
builder.addConstructorArg(directory);
|
||||
builder.addPropertyReference("channel", channel);
|
||||
Subscription subscription = new Subscription(channel);
|
||||
builder.addPropertyValue("subscription", subscription);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.adapter.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.file.FileTargetAdapter;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FileTargetAdapterParserTests {
|
||||
|
||||
@Test
|
||||
public void testFileTargetAdapterParser() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileTargetAdapterParserTests.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapter");
|
||||
assertEquals(FileTargetAdapter.class, endpoint.getHandler().getClass());
|
||||
assertEquals("adapter", endpoint.getName());
|
||||
assertEquals("testChannel", endpoint.getSubscription().getChannelName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="testChannel"/>
|
||||
|
||||
<si:file-target id="adapter" directory="${java.io.tmpdir}" channel="testChannel"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user