Example usage for org.springframework.util PatternMatchUtils simpleMatch

List of usage examples for org.springframework.util PatternMatchUtils simpleMatch

Introduction

In this page you can find the example usage for org.springframework.util PatternMatchUtils simpleMatch.

Prototype

public static boolean simpleMatch(@Nullable String[] patterns, String str) 

Source Link

Document

Match a String against the given patterns, supporting the following simple pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an arbitrary number of pattern parts), as well as direct equality.

Usage

From source file:org.springframework.integration.history.MessageHistoryConfigurer.java

public void start() {
    synchronized (this.lifecycleMonitor) {
        if (!this.running && this.beanFactory instanceof ListableBeanFactory) {
            for (TrackableComponent component : getTrackableComponents((ListableBeanFactory) beanFactory)) {
                String componentName = component.getComponentName();
                boolean shouldTrack = PatternMatchUtils.simpleMatch(this.componentNamePatterns, componentName);
                component.setShouldTrack(shouldTrack);
                if (shouldTrack) {
                    this.currentlyTrackedComponentNames.add(componentName);
                    if (this.logger.isInfoEnabled()) {
                        this.logger
                                .info("Enabling MessageHistory tracking for component '" + componentName + "'");
                    }/*from  w w w .j av a  2 s  .  c  o  m*/
                }
            }
            this.running = true;
        }
    }
}

From source file:org.springframework.integration.http.support.DefaultHttpHeaderMapper.java

private boolean shouldMapHeader(String headerName, String[] patterns) {
    if (patterns != null && patterns.length > 0) {
        for (String pattern : patterns) {
            if (PatternMatchUtils.simpleMatch(pattern.toLowerCase(), headerName.toLowerCase())) {
                if (logger.isDebugEnabled()) {
                    logger.debug(MessageFormat.format("headerName=[{0}] WILL be mapped, matched pattern={1}",
                            headerName, pattern));
                }/*from www . j  a v  a  2 s . c om*/
                return true;
            } else if (HTTP_REQUEST_HEADER_NAME_PATTERN.equals(pattern)
                    && this.containsElementIgnoreCase(HTTP_REQUEST_HEADER_NAMES, headerName)) {
                if (logger.isDebugEnabled()) {
                    logger.debug(MessageFormat.format("headerName=[{0}] WILL be mapped, matched pattern={1}",
                            headerName, pattern));
                }
                return true;
            } else if (HTTP_RESPONSE_HEADER_NAME_PATTERN.equals(pattern)
                    && this.containsElementIgnoreCase(HTTP_RESPONSE_HEADER_NAMES, headerName)) {
                if (logger.isDebugEnabled()) {
                    logger.debug(MessageFormat.format("headerName=[{0}] WILL be mapped, matched pattern={1}",
                            headerName, pattern));
                }
                return true;
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug(MessageFormat.format("headerName=[{0}] WILL NOT be mapped", headerName));
    }
    return false;
}

From source file:org.springframework.integration.mapping.AbstractHeaderMapper.java

private boolean shouldMapHeader(String headerName, List<String> patterns) {
    if (!StringUtils.hasText(headerName) || ObjectUtils.containsElement(TRANSIENT_HEADER_NAMES, headerName)) {
        return false;
    }//from w  w  w.  j  a v  a 2  s  .  c om
    if (patterns != null && patterns.size() > 0) {
        for (String pattern : patterns) {
            if (PatternMatchUtils.simpleMatch(pattern.toLowerCase(), headerName.toLowerCase())) {
                if (logger.isDebugEnabled()) {
                    logger.debug(MessageFormat.format("headerName=[{0}] WILL be mapped, matched pattern={1}",
                            headerName, pattern));
                }
                return true;
            } else if (STANDARD_REQUEST_HEADER_NAME_PATTERN.equals(pattern)
                    && this.containsElementIgnoreCase(this.getStandardRequestHeaderNames(), headerName)) {
                if (logger.isDebugEnabled()) {
                    logger.debug(MessageFormat.format("headerName=[{0}] WILL be mapped, matched pattern={1}",
                            headerName, pattern));
                }
                return true;
            } else if (STANDARD_REPLY_HEADER_NAME_PATTERN.equals(pattern)
                    && this.containsElementIgnoreCase(this.getStandardReplyHeaderNames(), headerName)) {
                if (logger.isDebugEnabled()) {
                    logger.debug(MessageFormat.format("headerName=[{0}] WILL be mapped, matched pattern={1}",
                            headerName, pattern));
                }
                return true;
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug(MessageFormat.format("headerName=[{0}] WILL NOT be mapped", headerName));
    }
    return false;
}

From source file:org.springframework.integration.monitor.IntegrationMBeanExporter.java

private void registerChannels() {
    for (DirectChannelMetrics monitor : channels) {
        String name = monitor.getName();
        this.allChannelsByName.put(name, monitor);
        if (!PatternMatchUtils.simpleMatch(this.componentNamePatterns, name)) {
            continue;
        }/* ww  w . ja va  2s . com*/
        // Only register once...
        if (!channelsByName.containsKey(name)) {
            String beanKey = getChannelBeanKey(name);
            logger.info("Registering MessageChannel " + name);
            if (name != null) {
                channelsByName.put(name, monitor);
            }
            registerBeanNameOrInstance(monitor, beanKey);
            // Expose the raw bean if it is managed
            MessageChannel bean = monitor.getMessageChannel();
            if (assembler.includeBean(bean.getClass(), monitor.getName())) {
                registerBeanInstance(bean, this.getMonitoredIntegrationObjectBeanKey(bean, name));
            }
        }
    }
}

From source file:org.springframework.integration.monitor.IntegrationMBeanExporter.java

private void registerHandlers() {
    for (SimpleMessageHandlerMetrics source : handlers) {
        MessageHandlerMetrics monitor = enhanceHandlerMonitor(source);
        String name = monitor.getName();
        this.allHandlersByName.put(name, monitor);
        if (!PatternMatchUtils.simpleMatch(this.componentNamePatterns, name)) {
            continue;
        }//ww w .j  av a2 s  .  co m
        // Only register once...
        if (!handlersByName.containsKey(name)) {
            String beanKey = getHandlerBeanKey(monitor);
            if (name != null) {
                handlersByName.put(name, monitor);
            }
            registerBeanNameOrInstance(monitor, beanKey);
            // Expose the raw bean if it is managed
            MessageHandler bean = source.getMessageHandler();
            if (assembler.includeBean(bean.getClass(), source.getName())) {
                registerBeanInstance(bean, this.getMonitoredIntegrationObjectBeanKey(bean, name));
            }
        }
    }
}

From source file:org.springframework.integration.monitor.IntegrationMBeanExporter.java

private void registerSources() {
    for (SimpleMessageSourceMetrics source : sources) {
        MessageSourceMetrics monitor = enhanceSourceMonitor(source);
        String name = monitor.getName();
        this.allSourcesByName.put(name, monitor);
        if (!PatternMatchUtils.simpleMatch(this.componentNamePatterns, name)) {
            continue;
        }//from  ww w .j a va2s.  c  o  m
        // Only register once...
        if (!sourcesByName.containsKey(name)) {
            String beanKey = getSourceBeanKey(monitor);
            if (name != null) {
                sourcesByName.put(name, monitor);
            }
            registerBeanNameOrInstance(monitor, beanKey);
            // Expose the raw bean if it is managed
            MessageSource<?> bean = source.getMessageSource();
            if (assembler.includeBean(bean.getClass(), source.getName())) {
                registerBeanInstance(bean, this.getMonitoredIntegrationObjectBeanKey(bean, name));
            }
        }
    }
}

From source file:org.springframework.integration.monitor.IntegrationMBeanExporter.java

private void registerEndpoints() {
    String[] names = beanFactory.getBeanNamesForType(AbstractEndpoint.class);
    Set<String> endpointNames = new HashSet<String>();
    for (String name : names) {
        if (!beansByEndpointName.values().contains(name)) {
            AbstractEndpoint endpoint = beanFactory.getBean(name, AbstractEndpoint.class);
            String beanKey;// w w w.java  2s  .com
            name = endpoint.getComponentName();
            String source;
            if (name.startsWith("_org.springframework.integration")) {
                name = getInternalComponentName(name);
                source = "internal";
            } else {
                name = endpoint.getComponentName();
                source = "endpoint";
            }
            if (!PatternMatchUtils.simpleMatch(this.componentNamePatterns, name)) {
                continue;
            }
            if (endpointNames.contains(name)) {
                int count = 0;
                String unique = name + "#" + count;
                while (endpointNames.contains(unique)) {
                    unique = name + "#" + (++count);
                }
                name = unique;
            }
            endpointNames.add(name);
            beanKey = getEndpointBeanKey(endpoint, name, source);
            ObjectName objectName = registerBeanInstance(new ManagedEndpoint(endpoint), beanKey);
            logger.info("Registered endpoint without MessageSource: " + objectName);
        }
    }
}

From source file:org.springframework.integration.stomp.support.StompHeaderMapper.java

private boolean shouldMapHeader(String headerName, String[] patterns) {
    if (patterns != null && patterns.length > 0) {
        for (String pattern : patterns) {
            if (PatternMatchUtils.simpleMatch(pattern, headerName)) {
                if (logger.isDebugEnabled()) {
                    logger.debug(MessageFormat.format("headerName=[{0}] WILL be mapped, matched pattern={1}",
                            headerName, pattern));
                }//from   w ww  . j  a  va  2 s .c om
                return true;
            } else if (STOMP_INBOUND_HEADER_NAME_PATTERN.equals(pattern)
                    && STOMP_INBOUND_HEADER_NAMES_LIST.contains(headerName)) {
                if (logger.isDebugEnabled()) {
                    logger.debug(MessageFormat.format("headerName=[{0}] WILL be mapped, matched pattern={1}",
                            headerName, pattern));
                }
                return true;
            } else if (STOMP_OUTBOUND_HEADER_NAME_PATTERN.equals(pattern)
                    && (STOMP_OUTBOUND_HEADER_NAMES_LIST.contains(headerName)
                            || MessageHeaders.CONTENT_TYPE.equals(headerName))) {
                if (logger.isDebugEnabled()) {
                    logger.debug(MessageFormat.format("headerName=[{0}] WILL be mapped, matched pattern={1}",
                            headerName, pattern));
                }
                return true;
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug(MessageFormat.format("headerName=[{0}] WILL NOT be mapped", headerName));
    }
    return false;
}

From source file:org.springframework.integration.support.management.IntegrationManagementConfigurer.java

/**
 * Simple pattern match against the supplied patterns; also supports negated ('!')
 * patterns. First match wins (positive or negative).
 * @param patterns the patterns.//from   w  w  w.jav  a2 s . c o m
 * @param name the name to match.
 * @return null if no match; true for positive match; false for negative match.
 */
private Boolean smartMatch(String[] patterns, String name) {
    if (patterns != null) {
        for (String pattern : patterns) {
            boolean reverse = false;
            String patternToUse = pattern;
            if (pattern.startsWith("!")) {
                reverse = true;
                patternToUse = pattern.substring(1);
            } else if (pattern.startsWith("\\")) {
                patternToUse = pattern.substring(1);
            }
            if (PatternMatchUtils.simpleMatch(patternToUse, name)) {
                return !reverse;
            }
        }
    }
    return null; //NOSONAR - intentional null return
}

From source file:org.springframework.integration.xml.transformer.XsltPayloadTransformer.java

private Transformer buildTransformer(Message<?> message) throws TransformerException {
    // process individual mappings
    Transformer transformer = this.templates.newTransformer();
    if (this.xslParameterMappings != null) {
        for (String parameterName : this.xslParameterMappings.keySet()) {
            Expression expression = this.xslParameterMappings.get(parameterName);
            try {
                Object value = expression.getValue(this.evaluationContext, message);
                transformer.setParameter(parameterName, value);
            } catch (Exception e) {
                if (logger.isWarnEnabled()) {
                    logger.warn("Evaluation of header expression '" + expression.getExpressionString()
                            + "' failed. The XSLT parameter '" + parameterName + "' will be skipped.");
                }/*from  w  w  w .  j  a  va2 s  . c  o  m*/
            }
        }
    }
    // process xslt-parameter-headers
    MessageHeaders headers = message.getHeaders();
    if (!ObjectUtils.isEmpty(this.xsltParamHeaders)) {
        for (String headerName : headers.keySet()) {
            if (PatternMatchUtils.simpleMatch(this.xsltParamHeaders, headerName)) {
                transformer.setParameter(headerName, headers.get(headerName));
            }
        }
    }
    return transformer;
}