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  
  * $Id: StringToBoolean.java 20320 2010-11-24 15:03:31Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transformer.simple;
 12  
 
 13  
 import org.mule.api.transformer.DataType;
 14  
 import org.mule.api.transformer.DiscoverableTransformer;
 15  
 import org.mule.api.transformer.TransformerException;
 16  
 import org.mule.config.i18n.CoreMessages;
 17  
 import org.mule.transformer.AbstractTransformer;
 18  
 import org.mule.transformer.types.DataTypeFactory;
 19  
 import org.mule.transformer.types.SimpleDataType;
 20  
 
 21  
 /**
 22  
  * <code>ByteArrayToSerializable</code> converts a serialized object to its object
 23  
  * representation
 24  
  */
 25  
 public class StringToBoolean extends AbstractTransformer implements DiscoverableTransformer
 26  
 {
 27  
 
 28  
     /**
 29  
      * Give core transformers a slighty higher priority
 30  
      */
 31  0
     private int priorityWeighting = DiscoverableTransformer.DEFAULT_PRIORITY_WEIGHTING + 1;
 32  
 
 33  
     public StringToBoolean()
 34  0
     {
 35  0
         registerSourceType(new SimpleDataType<Object>(String.class));
 36  0
         setReturnDataType(DataTypeFactory.create(Boolean.class));
 37  0
     }
 38  
 
 39  
     @Override
 40  
     public Object doTransform(Object src, String encoding) throws TransformerException
 41  
     {
 42  0
         if (src == null)
 43  
         {
 44  0
             if (isAllowNullReturn())
 45  
             {
 46  0
                 return null;
 47  
             }
 48  
             else
 49  
             {
 50  0
                 throw new TransformerException(
 51  
                     CoreMessages.createStaticMessage("Unable to transform null to a primitive"));
 52  
             }
 53  
         }
 54  
         else
 55  
         {
 56  0
             return Boolean.valueOf((String) src);
 57  
         }
 58  
     }
 59  
 
 60  
     @Override
 61  
     public void setReturnDataType(DataType<?> type)
 62  
     {
 63  0
         if (!Boolean.class.isAssignableFrom(type.getType()))
 64  
         {
 65  0
             throw new IllegalArgumentException("This transformer only supports Boolean return types.");
 66  
         }
 67  
         else
 68  
         {
 69  0
             super.setReturnDataType(type);
 70  
         }
 71  0
     }
 72  
 
 73  
     public int getPriorityWeighting()
 74  
     {
 75  0
         return priorityWeighting;
 76  
     }
 77  
 
 78  
     public void setPriorityWeighting(int priorityWeighting)
 79  
     {
 80  0
         this.priorityWeighting = priorityWeighting;
 81  0
     }
 82  
 
 83  
 }