Coverage Report - org.mule.transformer.simple.PropertyEditorValueToTextTransformer
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyEditorValueToTextTransformer
0%
0/13
N/A
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.transformer.types.SimpleDataType;
 14  
 
 15  
 import java.beans.PropertyEditor;
 16  
 
 17  
 /**
 18  
  * <code>PropertyEditorValueToTextTransformer</code> adapts a {@link PropertyEditor}
 19  
  * instance allowing it to be used to transform from a specific type to a String.
 20  
  */
 21  
 public class PropertyEditorValueToTextTransformer extends AbstractTransformer implements DiscoverableTransformer
 22  
 {
 23  
 
 24  
     private PropertyEditor propertyEditor;
 25  
 
 26  
     /**
 27  
      * Give core transformers a slighty higher priority
 28  
      */
 29  0
     private int priorityWeighting = DiscoverableTransformer.DEFAULT_PRIORITY_WEIGHTING + 1;
 30  
 
 31  
     public PropertyEditorValueToTextTransformer(PropertyEditor propertyEditor, Class<?> clazz)
 32  0
     {
 33  0
         registerSourceType(new SimpleDataType<Object>(clazz));
 34  0
         setReturnDataType(DataTypeFactory.STRING);
 35  0
         this.propertyEditor = propertyEditor;
 36  0
     }
 37  
 
 38  
     @Override
 39  
     public Object doTransform(Object src, String encoding) throws TransformerException
 40  
     {
 41  0
         synchronized (propertyEditor)
 42  
         {
 43  0
             propertyEditor.setValue(src);
 44  0
             return propertyEditor.getAsText();
 45  0
         }
 46  
     }
 47  
 
 48  
     public int getPriorityWeighting()
 49  
     {
 50  0
         return priorityWeighting;
 51  
     }
 52  
 
 53  
     public void setPriorityWeighting(int priorityWeighting)
 54  
     {
 55  0
         this.priorityWeighting = priorityWeighting;
 56  0
     }
 57  
 
 58  
 }