Coverage Report - org.mule.util.BeanUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
BeanUtils
47%
8/17
42%
5/12
7
 
 1  
 /*
 2  
  * $Id: BeanUtils.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 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;
 12  
 
 13  
 import java.util.Iterator;
 14  
 import java.util.Map;
 15  
 
 16  
 import org.apache.commons.logging.Log;
 17  
 import org.apache.commons.logging.LogFactory;
 18  
 
 19  
 /**
 20  
  * <code>BeanUtils</code> provides functions for altering the way commons BeanUtils
 21  
  * works
 22  
  */
 23  
 // @ThreadSafe
 24  0
 public class BeanUtils extends org.apache.commons.beanutils.BeanUtils
 25  
 {
 26  
     public static final String SET_PROPERTIES_METHOD = "setProperties";
 27  
 
 28  
     /**
 29  
      * logger used by this class
 30  
      */
 31  6
     private static final Log logger = LogFactory.getLog(BeanUtils.class);
 32  
 
 33  
     /**
 34  
      * Exception safe version of BeanUtils.populateWithoutFail
 35  
      */
 36  
     public static void populateWithoutFail(Object object, Map props, boolean logWarnings)
 37  
     {
 38  
         // Check to see if our object has a setProperties method where the properties
 39  
         // map should be set
 40  456
         if (ClassUtils.getMethod(object.getClass(), SET_PROPERTIES_METHOD, new Class[]{Map.class}) != null)
 41  
         {
 42  
             try
 43  
             {
 44  0
                 BeanUtils.setProperty(object, "properties", props);
 45  
             }
 46  0
             catch (Exception e)
 47  
             {
 48  
                 // this should never happen since we explicitly check for the method
 49  
                 // above
 50  0
                 if (logWarnings)
 51  
                 {
 52  0
                     logger.warn("Property: " + SET_PROPERTIES_METHOD + "=" + Map.class.getName()
 53  
                                 + " not found on object: " + object.getClass().getName());
 54  
                 }
 55  0
             }
 56  
         }
 57  
         else
 58  
         {
 59  456
             for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();)
 60  
             {
 61  498
                 Map.Entry entry = (Map.Entry) iterator.next();
 62  
 
 63  
                 try
 64  
                 {
 65  498
                     BeanUtils.setProperty(object, entry.getKey().toString(), entry.getValue());
 66  
                 }
 67  0
                 catch (Exception e)
 68  
                 {
 69  0
                     if (logWarnings)
 70  
                     {
 71  0
                         logger.warn("Property: " + entry.getKey() + "=" + entry.getValue()
 72  
                                     + " not found on object: " + object.getClass().getName());
 73  
                     }
 74  498
                 }
 75  498
             }
 76  
         }
 77  456
     }
 78  
 
 79  
 }