Coverage Report - org.mule.util.properties.PayloadPropertyExtractor
 
Classes in this File Line Coverage Branch Coverage Complexity
PayloadPropertyExtractor
0%
0/17
0%
0/6
7
 
 1  
 /*
 2  
  * $Id: PayloadPropertyExtractor.java 9431 2007-10-29 13:04:36Z aperepel $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.util.properties;
 12  
 
 13  
 import org.mule.umo.UMOMessage;
 14  
 import org.mule.util.StringUtils;
 15  
 
 16  
 import java.lang.reflect.InvocationTargetException;
 17  
 
 18  
 import org.apache.commons.beanutils.PropertyUtils;
 19  
 import org.apache.commons.logging.Log;
 20  
 import org.apache.commons.logging.LogFactory;
 21  
 
 22  
 /**
 23  
  * Checks the payload object for a bean property matching the property name
 24  
  */
 25  0
 public class PayloadPropertyExtractor implements PropertyExtractor
 26  
 {
 27  
     /**
 28  
      * logger used by this class
 29  
      */
 30  0
     protected transient Log logger = LogFactory.getLog(getClass());
 31  
 
 32  
     public Object getProperty(String name, Object message)
 33  
     {
 34  0
         Object payload = message;
 35  0
         if (message instanceof UMOMessage)
 36  
         {
 37  0
             payload = ((UMOMessage) message).getPayload();
 38  
         }
 39  0
         Object value = null;
 40  
         try
 41  
         {
 42  0
             if ((PropertyUtils.getPropertyDescriptor(payload, name) != null))
 43  
             {
 44  0
                 value = PropertyUtils.getProperty(payload, name);
 45  0
                 if (value == null)
 46  
                 {
 47  0
                     value = StringUtils.EMPTY;
 48  
                 }
 49  
             }
 50  
         }
 51  0
         catch (IllegalAccessException e)
 52  
         {
 53  0
             logger.warn("Failed to read property: " + name, e);
 54  
         }
 55  0
         catch (InvocationTargetException e)
 56  
         {
 57  0
             logger.warn("Failed to read property: " + name, e.getCause());
 58  
         }
 59  0
         catch (NoSuchMethodException e)
 60  
         {
 61  
             // will never happen
 62  0
         }
 63  0
         return value;
 64  
     }
 65  
 }