Coverage Report - org.mule.config.spring.parsers.processors.AttributeConcatenation
 
Classes in this File Line Coverage Branch Coverage Complexity
AttributeConcatenation
0%
0/16
0%
0/6
2.5
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.config.spring.parsers.processors;
 8  
 
 9  
 import org.mule.config.spring.parsers.PreProcessor;
 10  
 import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration;
 11  
 import org.mule.util.StringUtils;
 12  
 
 13  
 import org.w3c.dom.Element;
 14  
 
 15  
 public class AttributeConcatenation implements PreProcessor
 16  
 {
 17  
 
 18  
     private String target;
 19  
     private String separator;
 20  
     private String[] sources;
 21  
 
 22  
     public AttributeConcatenation(String target, String separator, String[] sources)
 23  0
     {
 24  0
         this.target = target;
 25  0
         this.separator = separator;
 26  0
         this.sources = sources;
 27  0
     }
 28  
 
 29  
     public void preProcess(PropertyConfiguration config, Element element)
 30  
     {
 31  0
         StringBuffer concat = new StringBuffer();
 32  0
         boolean first = true;
 33  0
         for (int i = 0; i < sources.length; ++i)
 34  
         {
 35  0
             String value = config.translateValue(sources[i], element.getAttribute(sources[i])).toString();
 36  0
             if (StringUtils.isNotEmpty(value))
 37  
             {
 38  0
                 if (first)
 39  
                 {
 40  0
                     first = false;
 41  
                 }
 42  
                 else
 43  
                 {
 44  0
                     concat.append(separator);
 45  
                 }
 46  0
                 concat.append(value);
 47  
             }
 48  
         }
 49  0
         element.setAttribute(target, concat.toString());
 50  0
     }
 51  
 
 52  
 }