예제 #1
0
 private boolean isMatch(Metric<?> metric) {
   String[] includes = MetricCopyExporter.this.includes;
   String[] excludes = MetricCopyExporter.this.excludes;
   String name = metric.getName();
   if (ObjectUtils.isEmpty(includes) || PatternMatchUtils.simpleMatch(includes, name)) {
     return !PatternMatchUtils.simpleMatch(excludes, name);
   }
   return false;
 }
 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;
       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);
     }
   }
 }
 protected Transformer buildTransformer(Message<?> message) throws TransformerException {
   // process  individual mappings
   Transformer transformer = this.templates.newTransformer();
   context.setRootObject(message);
   context.addPropertyAccessor(new MapAccessor());
   if (xslParameterMappings != null) {
     for (String parameterName : xslParameterMappings.keySet()) {
       Expression expression = xslParameterMappings.get(parameterName);
       Object value = null;
       try {
         value = expression.getValue(context);
         transformer.setParameter(parameterName, value);
       } catch (Exception e) {
         logger.warn(
             "Header expression '"
                 + expression.getExpressionString()
                 + "' can not resolve within current message and will not be mapped to XSLT parameter");
       }
     }
   }
   // process xslt-parameter-headers
   MessageHeaders headers = message.getHeaders();
   if (xsltParamHeaders != null) {
     for (String headerName : headers.keySet()) {
       if (PatternMatchUtils.simpleMatch(xsltParamHeaders, headerName)) {
         transformer.setParameter(headerName, headers.get(headerName));
       }
     }
   }
   return transformer;
 }
 /**
  * Apply further settings to the given bean definition, beyond the contents retrieved from
  * scanning the component class.
  *
  * @param beanDefinition the scanned bean definition
  * @param beanName the generated bean name for the given bean
  */
 protected void postProcessBeanDefinition(AbstractBeanDefinition beanDefinition, String beanName) {
   beanDefinition.applyDefaults(this.beanDefinitionDefaults);
   if (this.autowireCandidatePatterns != null) {
     beanDefinition.setAutowireCandidate(
         PatternMatchUtils.simpleMatch(this.autowireCandidatePatterns, beanName));
   }
 }
 private List<String> getMatchingHeaderNames(String pattern, Map<String, Object> headers) {
   List<String> matchingHeaderNames = new ArrayList<String>();
   if (headers != null) {
     for (String key : headers.keySet()) {
       if (PatternMatchUtils.simpleMatch(pattern, key)) {
         matchingHeaderNames.add(key);
       }
     }
   }
   return matchingHeaderNames;
 }
 /**
  * Simple pattern match against the supplied patterns; also supports negated ('!') patterns. First
  * match wins (positive or negative).
  *
  * @param patterns the patterns.
  * @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
 }
 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;
     }
     // 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));
       }
     }
   }
 }
 private void registerChannels() {
   for (DirectChannelMetrics monitor : channels) {
     String name = monitor.getName();
     this.allChannelsByName.put(name, monitor);
     if (!PatternMatchUtils.simpleMatch(this.componentNamePatterns, name)) {
       continue;
     }
     // 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));
       }
     }
   }
 }
예제 #9
0
 /**
  * Return if the given field is allowed for binding. Invoked for each passed-in property value.
  *
  * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches, as well as direct
  * equality, in the specified lists of allowed fields and disallowed fields. A field matching a
  * disallowed pattern will not be accepted even if it also happens to match a pattern in the
  * allowed list.
  *
  * <p>Can be overridden in subclasses.
  *
  * @param field the field to check
  * @return if the field is allowed
  * @see #setAllowedFields
  * @see #setDisallowedFields
  * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
  */
 protected boolean isAllowed(String field) {
   String[] allowed = getAllowedFields();
   String[] disallowed = getDisallowedFields();
   return ((ObjectUtils.isEmpty(allowed) || PatternMatchUtils.simpleMatch(allowed, field))
       && (ObjectUtils.isEmpty(disallowed) || !PatternMatchUtils.simpleMatch(disallowed, field)));
 }
 /**
  * Return if the given bean name matches the mapped name.
  *
  * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches, as well as direct
  * equality. Can be overridden in subclasses.
  *
  * @param beanName the bean name to check
  * @param mappedName the name in the configured list of names
  * @return if the names match
  * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
  */
 protected boolean isMatch(String beanName, String mappedName) {
   return PatternMatchUtils.simpleMatch(mappedName, beanName);
 }