INT-1338, Added namespace support for 'event-types' attribute
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.integration.event;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -34,7 +34,7 @@ import org.springframework.util.CollectionUtils;
|
||||
*/
|
||||
public class ApplicationEventInboundChannelAdapter extends MessageProducerSupport implements ApplicationListener<ApplicationEvent> {
|
||||
|
||||
private final List<Class<? extends ApplicationEvent>> eventTypes = new CopyOnWriteArrayList<Class<? extends ApplicationEvent>>();
|
||||
private final Set<Class<? extends ApplicationEvent>> eventTypes = new CopyOnWriteArraySet<Class<? extends ApplicationEvent>>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ public class ApplicationEventInboundChannelAdapter extends MessageProducerSuppor
|
||||
* this adapter should send to the message channel. By default, all event
|
||||
* types will be sent.
|
||||
*/
|
||||
public void setEventTypes(List<Class<? extends ApplicationEvent>> eventTypes) {
|
||||
public void setEventTypes(Set<Class<? extends ApplicationEvent>> eventTypes) {
|
||||
Assert.notEmpty(eventTypes, "at least one event type is required");
|
||||
synchronized (this.eventTypes) {
|
||||
this.eventTypes.clear();
|
||||
|
||||
@@ -15,25 +15,49 @@
|
||||
*/
|
||||
package org.springframework.integration.event.config;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.integration.config.xml.AbstractChannelAdapterParser;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.integration.event.ApplicationEventInboundChannelAdapter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class EventInboundChannelAdapterParser extends AbstractChannelAdapterParser{
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected AbstractBeanDefinition doParse(Element element,
|
||||
ParserContext parserContext, String channelName) {
|
||||
BeanDefinitionBuilder adapterBuilder = BeanDefinitionBuilder.rootBeanDefinition(ApplicationEventInboundChannelAdapter.class);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(adapterBuilder, element, "channel", "outputChannel");
|
||||
String stringEventTypes = element.getAttribute("event-types");
|
||||
if (StringUtils.hasText(stringEventTypes)){
|
||||
//Set<String> eventTypes = StringUtils.commaDelimitedListToSet(stringEventTypes);
|
||||
StringTokenizer tokenizer = new StringTokenizer(stringEventTypes, " ,");
|
||||
Set<Class<? extends ApplicationEvent>> applicationEvents = new HashSet<Class<? extends ApplicationEvent>>();
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String fullyQualifiedClassname = tokenizer.nextToken();
|
||||
Class<? extends ApplicationEvent> clazz =
|
||||
(Class<? extends ApplicationEvent>) IntegrationNamespaceUtils.convertFqClassNameToClassObject(fullyQualifiedClassname, parserContext);
|
||||
Assert.notNull(clazz, "Class for the event type '" + fullyQualifiedClassname + "' can not be located");
|
||||
applicationEvents.add(clazz);
|
||||
}
|
||||
adapterBuilder.addPropertyValue("eventTypes", applicationEvents);
|
||||
}
|
||||
//IntegrationNamespaceUtils.setReferenceIfAttributeDefined(adapterBuilder, element, "event", "eventTypes");
|
||||
return adapterBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,15 @@
|
||||
Identifies inbound 'channel' which accepts Messages generated from Application Context events.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="event-types" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Comma delimited list of event types (classes that extend ApplicationEvent) that
|
||||
this adapter should send to the message channel. By default, all event
|
||||
types will be sent [OPTIONAL]
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
Reference in New Issue
Block a user