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