Coverage Report - org.mule.transformer.simple.StringToBoolean
 
Classes in this File Line Coverage Branch Coverage Complexity
StringToBoolean
0%
0/17
0%
0/6
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.DataType;
 10  
 import org.mule.api.transformer.DiscoverableTransformer;
 11  
 import org.mule.api.transformer.TransformerException;
 12  
 import org.mule.config.i18n.CoreMessages;
 13  
 import org.mule.transformer.AbstractTransformer;
 14  
 import org.mule.transformer.types.DataTypeFactory;
 15  
 import org.mule.transformer.types.SimpleDataType;
 16  
 
 17  
 /**
 18  
  * <code>ByteArrayToSerializable</code> converts a serialized object to its object
 19  
  * representation
 20  
  */
 21  
 public class StringToBoolean extends AbstractTransformer implements DiscoverableTransformer
 22  
 {
 23  
 
 24  
     /**
 25  
      * Give core transformers a slighty higher priority
 26  
      */
 27  0
     private int priorityWeighting = DiscoverableTransformer.DEFAULT_PRIORITY_WEIGHTING + 1;
 28  
 
 29  
     public StringToBoolean()
 30  0
     {
 31  0
         registerSourceType(new SimpleDataType<Object>(String.class));
 32  0
         setReturnDataType(DataTypeFactory.create(Boolean.class));
 33  0
     }
 34  
 
 35  
     @Override
 36  
     public Object doTransform(Object src, String encoding) throws TransformerException
 37  
     {
 38  0
         if (src == null)
 39  
         {
 40  0
             if (isAllowNullReturn())
 41  
             {
 42  0
                 return null;
 43  
             }
 44  
             else
 45  
             {
 46  0
                 throw new TransformerException(
 47  
                     CoreMessages.createStaticMessage("Unable to transform null to a primitive"));
 48  
             }
 49  
         }
 50  
         else
 51  
         {
 52  0
             return Boolean.valueOf((String) src);
 53  
         }
 54  
     }
 55  
 
 56  
     @Override
 57  
     public void setReturnDataType(DataType<?> type)
 58  
     {
 59  0
         if (!Boolean.class.isAssignableFrom(type.getType()))
 60  
         {
 61  0
             throw new IllegalArgumentException("This transformer only supports Boolean return types.");
 62  
         }
 63  
         else
 64  
         {
 65  0
             super.setReturnDataType(type);
 66  
         }
 67  0
     }
 68  
 
 69  
     public int getPriorityWeighting()
 70  
     {
 71  0
         return priorityWeighting;
 72  
     }
 73  
 
 74  
     public void setPriorityWeighting(int priorityWeighting)
 75  
     {
 76  0
         this.priorityWeighting = priorityWeighting;
 77  0
     }
 78  
 
 79  
 }