INT-1158 fixed on the 1.0.x branch

This commit is contained in:
Mark Fisher
2010-06-08 23:40:30 +00:00
parent 2e15afc767
commit ee6bcfe2ce
2 changed files with 22 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.
@@ -18,12 +18,12 @@ package org.springframework.integration.mail.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Parser for the <imap-idle-channel-adapter> element in the 'mail' namespace.
@@ -51,32 +51,21 @@ public class ImapIdleChannelAdapterParser extends AbstractSingleBeanDefinitionPa
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String channel = element.getAttribute("channel");
Assert.hasText(channel, "the 'channel' attribute is required");
builder.addConstructorArgReference(this.parseImapMailReceiver(element, parserContext));
builder.addConstructorArgValue(this.parseImapMailReceiver(element, parserContext));
builder.addPropertyReference("outputChannel", channel);
String taskExecutorRef = element.getAttribute("task-executor");
if (StringUtils.hasText(taskExecutorRef)) {
builder.addPropertyReference("taskExecutor", taskExecutorRef);
}
String autoStartup = element.getAttribute("auto-startup");
if (StringUtils.hasText(autoStartup)) {
builder.addPropertyValue("autoStartup", autoStartup);
}
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "task-executor");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup");
}
private String parseImapMailReceiver(Element element, ParserContext parserContext) {
private BeanDefinition parseImapMailReceiver(Element element, ParserContext parserContext) {
String uri = element.getAttribute("store-uri");
Assert.hasText(uri, "the 'store-uri' attribute is required");
BeanDefinitionBuilder receiverBuilder = BeanDefinitionBuilder.genericBeanDefinition(
BASE_PACKAGE + ".ImapMailReceiver");
receiverBuilder.addConstructorArgValue(uri);
String propertiesRef = element.getAttribute("java-mail-properties");
if (StringUtils.hasText(propertiesRef)) {
receiverBuilder.addPropertyReference("javaMailProperties", propertiesRef);
}
receiverBuilder.addPropertyValue("shouldDeleteMessages",
!"false".equals(element.getAttribute("should-delete-messages")));
return BeanDefinitionReaderUtils.registerWithGeneratedName(
receiverBuilder.getBeanDefinition(), parserContext.getRegistry());
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(receiverBuilder, element, "java-mail-properties");
receiverBuilder.addPropertyValue("shouldDeleteMessages", element.getAttribute("should-delete-messages"));
return receiverBuilder.getBeanDefinition();
}
}

View File

@@ -2,17 +2,26 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mail="http://www.springframework.org/schema/integration/mail"
xmlns:integration="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/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail-1.0.xsd">
<context:property-placeholder properties-ref="configProperties"/>
<util:properties id="configProperties">
<prop key="mail.delete">false</prop>
</util:properties>
<integration:channel id="channel"/>
<mail:imap-idle-channel-adapter id="simpleAdapter"
@@ -25,11 +34,11 @@
store-uri="imap:foo"
channel="channel"
auto-startup="false"
java-mail-properties="props"
should-delete-messages="false"
java-mail-properties="javaMailProperties"
should-delete-messages="${mail.delete}"
task-executor="executor"/>
<util:properties id="props">
<util:properties id="javaMailProperties">
<prop key="foo">bar</prop>
</util:properties>