Coverage Report - org.mule.transformer.simple.GetBeanProperty
 
Classes in this File Line Coverage Branch Coverage Complexity
GetBeanProperty
0%
0/10
N/A
0
 
 1  
 /*
 2  
  * $Id: GetBeanProperty.java 19250 2010-08-30 16:53:14Z dirk.olmes $
 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.TransformerException;
 14  
 import org.mule.transformer.AbstractTransformer;
 15  
 import org.mule.transformer.types.DataTypeFactory;
 16  
 
 17  
 import org.apache.commons.beanutils.PropertyUtils;
 18  
 
 19  
 /**
 20  
  * Looks up a property from a JavaBean using PropertyUtils.getProperty().
 21  
  * Nested properties are valid, assuming they follow JavaBean conventions.
 22  
  * 
 23  
  *   <transformer name="ExtractCustomer" className="org.mule.transformer.simple.GetBeanProperty">
 24  
  *       <properties>
 25  
  *           <property name="propertyName" value="customerRequest.customer" />
 26  
  *       </properties>
 27  
  *   </transformer>
 28  
  */
 29  
 public class GetBeanProperty extends AbstractTransformer
 30  
 {
 31  
     private String propertyName;
 32  
     
 33  
     public GetBeanProperty()
 34  
     {
 35  0
         super();
 36  0
         registerSourceType(DataTypeFactory.OBJECT);
 37  0
         setReturnDataType(DataTypeFactory.OBJECT);
 38  0
     }
 39  
 
 40  
     @Override
 41  
     public Object doTransform(Object src, String encoding) throws TransformerException
 42  
     {
 43  
         try
 44  
         {
 45  0
             return PropertyUtils.getProperty(src, this.propertyName);
 46  
         }
 47  0
         catch (Exception e)
 48  
         {
 49  0
             throw new TransformerException(this, e);
 50  
         }
 51  
     }
 52  
 
 53  
     public String getPropertyName()
 54  
     {
 55  0
         return propertyName;
 56  
     }
 57  
 
 58  
     public void setPropertyName(String propertyName)
 59  
     {
 60  0
         this.propertyName = propertyName;
 61  0
     }
 62  
 
 63  
 }