Coverage Report - org.mule.transformer.simple.ObjectArrayToString
 
Classes in this File Line Coverage Branch Coverage Complexity
ObjectArrayToString
0%
0/19
0%
0/4
0
 
 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.transformer.simple;
 8  
 
 9  
 import org.mule.api.transformer.DiscoverableTransformer;
 10  
 import org.mule.api.transformer.TransformerException;
 11  
 import org.mule.transformer.AbstractTransformer;
 12  
 import org.mule.transformer.types.DataTypeFactory;
 13  
 import org.mule.util.StringUtils;
 14  
 
 15  
 /**
 16  
  * <code>ObjectArrayToString</code> transformer is the opposite of
 17  
  * StringToObjectArray - it simply converts Object[] to a String in which each
 18  
  * element is separated by a configurable delimiter (default is a space).
 19  
  */
 20  
 
 21  
 public class ObjectArrayToString extends AbstractTransformer implements DiscoverableTransformer
 22  
 {
 23  
     /** Give core transformers a slighty higher priority */
 24  0
     private int priorityWeighting = DiscoverableTransformer.DEFAULT_PRIORITY_WEIGHTING + 1;
 25  
 
 26  
     private static final String DEFAULT_DELIMITER = " ";
 27  
 
 28  0
     private String delimiter = null;
 29  
 
 30  
     public ObjectArrayToString()
 31  0
     {
 32  0
         registerSourceType(DataTypeFactory.create(Object[].class));
 33  0
         setReturnDataType(DataTypeFactory.TEXT_STRING);
 34  0
     }
 35  
 
 36  
     @Override
 37  
     public Object doTransform(Object src, String encoding) throws TransformerException
 38  
     {
 39  0
         if (src == null)
 40  
         {
 41  0
             return src;
 42  
         }
 43  
 
 44  0
         Object[] in = (Object[]) src;
 45  0
         String out = StringUtils.join(in, getDelimiter());
 46  
 
 47  
         /*
 48  
         for (int i = 0; i < in.length; i++)
 49  
         {
 50  
             if (in[i] != null)
 51  
             {
 52  
                 if (i > 0) out += getDelimiter();
 53  
                 out += in[i].toString();
 54  
             }
 55  
         }
 56  
         */
 57  
 
 58  0
         return out;
 59  
     }
 60  
 
 61  
     public String getDelimiter()
 62  
     {
 63  0
         if (delimiter == null)
 64  
         {
 65  0
             return DEFAULT_DELIMITER;
 66  
         }
 67  
         else
 68  
         {
 69  0
             return delimiter;
 70  
         }
 71  
     }
 72  
 
 73  
     public void setDelimiter(String delimiter)
 74  
     {
 75  0
         this.delimiter = delimiter;
 76  0
     }
 77  
 
 78  
     public int getPriorityWeighting()
 79  
     {
 80  0
         return priorityWeighting;
 81  
     }
 82  
 
 83  
     public void setPriorityWeighting(int priorityWeighting)
 84  
     {
 85  0
         this.priorityWeighting = priorityWeighting;
 86  0
     }
 87  
 }