Example usage for org.springframework.integration.channel.interceptor GlobalChannelInterceptorWrapper getPatterns

List of usage examples for org.springframework.integration.channel.interceptor GlobalChannelInterceptorWrapper getPatterns

Introduction

In this page you can find the example usage for org.springframework.integration.channel.interceptor GlobalChannelInterceptorWrapper getPatterns.

Prototype

public String[] getPatterns() 

Source Link

Usage

From source file:org.springframework.integration.channel.interceptor.GlobalChannelInterceptorBeanPostProcessor.java

/**
 * Adds any interceptor whose pattern matches against the channel's name. 
 *///www.j  a  v  a2  s  .  co m
private void addMatchingInterceptors(MessageChannel channel, String beanName) {
    List<ChannelInterceptor> interceptors = this.getExistingInterceptors(channel);
    if (interceptors != null) {
        List<GlobalChannelInterceptorWrapper> tempInterceptors = new ArrayList<GlobalChannelInterceptorWrapper>();
        for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.positiveOrderInterceptors) {
            String[] patterns = globalChannelInterceptorWrapper.getPatterns();
            patterns = StringUtils.trimArrayElements(patterns);
            if (PatternMatchUtils.simpleMatch(patterns, beanName)) {
                tempInterceptors.add(globalChannelInterceptorWrapper);
            }
        }
        Collections.sort(tempInterceptors, this.comparator);
        for (GlobalChannelInterceptorWrapper next : tempInterceptors) {
            interceptors.add(next.getChannelInterceptor());
        }
        tempInterceptors = new ArrayList<GlobalChannelInterceptorWrapper>();
        for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.negativeOrderInterceptors) {
            String[] patterns = globalChannelInterceptorWrapper.getPatterns();
            patterns = StringUtils.trimArrayElements(patterns);
            if (PatternMatchUtils.simpleMatch(patterns, beanName)) {
                tempInterceptors.add(globalChannelInterceptorWrapper);
            }
        }
        Collections.sort(tempInterceptors, comparator);
        if (!tempInterceptors.isEmpty()) {
            for (int i = tempInterceptors.size() - 1; i >= 0; i--) {
                interceptors.add(0, tempInterceptors.get(i).getChannelInterceptor());
            }
        }
    } else if (logger.isDebugEnabled()) {
        logger.debug("Global Channel interceptors will not be applied to Channel: " + beanName);
    }
}

From source file:org.springframework.integration.config.GlobalChannelInterceptorProcessor.java

/**
 * Adds any interceptor whose pattern matches against the channel's name.
 *//*  w ww  .  j  a va 2  s  . c om*/
private void addMatchingInterceptors(ChannelInterceptorAware channel, String beanName) {
    if (logger.isDebugEnabled()) {
        logger.debug("Applying global interceptors on channel '" + beanName + "'");
    }
    List<GlobalChannelInterceptorWrapper> tempInterceptors = new ArrayList<GlobalChannelInterceptorWrapper>();
    for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.positiveOrderInterceptors) {
        String[] patterns = globalChannelInterceptorWrapper.getPatterns();
        patterns = StringUtils.trimArrayElements(patterns);
        if (PatternMatchUtils.simpleMatch(patterns, beanName)) {
            tempInterceptors.add(globalChannelInterceptorWrapper);
        }
    }
    Collections.sort(tempInterceptors, this.comparator);
    for (GlobalChannelInterceptorWrapper next : tempInterceptors) {
        ChannelInterceptor channelInterceptor = next.getChannelInterceptor();
        if (!(channelInterceptor instanceof VetoCapableInterceptor)
                || ((VetoCapableInterceptor) channelInterceptor).shouldIntercept(beanName, channel)) {
            channel.addInterceptor(channelInterceptor);
        }
    }

    tempInterceptors.clear();
    for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.negativeOrderInterceptors) {
        String[] patterns = globalChannelInterceptorWrapper.getPatterns();
        patterns = StringUtils.trimArrayElements(patterns);
        if (PatternMatchUtils.simpleMatch(patterns, beanName)) {
            tempInterceptors.add(globalChannelInterceptorWrapper);
        }
    }
    Collections.sort(tempInterceptors, this.comparator);
    if (!tempInterceptors.isEmpty()) {
        for (int i = tempInterceptors.size() - 1; i >= 0; i--) {
            ChannelInterceptor channelInterceptor = tempInterceptors.get(i).getChannelInterceptor();
            if (!(channelInterceptor instanceof VetoCapableInterceptor)
                    || ((VetoCapableInterceptor) channelInterceptor).shouldIntercept(beanName, channel)) {
                channel.addInterceptor(0, channelInterceptor);
            }
        }
    }
}