|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
   package org.kuali.rice.kns.uif.util;  | 
  |  17 |     | 
     | 
  |  18 |     | 
   import java.beans.PropertyDescriptor;  | 
  |  19 |     | 
   import java.util.Map;  | 
  |  20 |     | 
     | 
  |  21 |     | 
   import org.springframework.beans.BeanWrapper;  | 
  |  22 |     | 
   import org.springframework.beans.BeanWrapperImpl;  | 
  |  23 |     | 
   import org.springframework.beans.BeansException;  | 
  |  24 |     | 
     | 
  |  25 |     | 
     | 
  |  26 |     | 
     | 
  |  27 |     | 
     | 
  |  28 |     | 
     | 
  |  29 |     | 
     | 
  |  30 |     | 
     | 
  |  31 |    0 |    public class ObjectPropertyUtils { | 
  |  32 |    0 |            private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ObjectPropertyUtils.class);  | 
  |  33 |     | 
     | 
  |  34 |     | 
           public static void copyPropertiesToObject(Map<String, String> properties, Object object) { | 
  |  35 |    0 |                    for (Map.Entry<String, String> property : properties.entrySet()) { | 
  |  36 |    0 |                            setPropertyValue(object, property.getKey(), property.getValue());  | 
  |  37 |     | 
                   }  | 
  |  38 |    0 |            }  | 
  |  39 |     | 
     | 
  |  40 |     | 
           public static PropertyDescriptor[] getPropertyDescriptors(Object object) { | 
  |  41 |    0 |                    return wrapObject(object).getPropertyDescriptors();  | 
  |  42 |     | 
           }  | 
  |  43 |     | 
     | 
  |  44 |     | 
           public static Class<?> getPropertyType(Class<?> object, String propertyPath) { | 
  |  45 |    0 |                    return new BeanWrapperImpl(object).getPropertyType(propertyPath);  | 
  |  46 |     | 
           }  | 
  |  47 |     | 
     | 
  |  48 |     | 
           public static Class<?> getPropertyType(Object object, String propertyPath) { | 
  |  49 |    0 |                    return wrapObject(object).getPropertyType(propertyPath);  | 
  |  50 |     | 
           }  | 
  |  51 |     | 
     | 
  |  52 |     | 
           @SuppressWarnings("unchecked") | 
  |  53 |     | 
           public static <T extends Object> T getPropertyValue(Object object, String propertyPath) { | 
  |  54 |    0 |                    return (T) wrapObject(object).getPropertyValue(propertyPath);  | 
  |  55 |     | 
           }  | 
  |  56 |     | 
     | 
  |  57 |     | 
           public static void initializeProperty(Object object, String propertyPath) { | 
  |  58 |    0 |                    Class<?> propertyType = getPropertyType(object, propertyPath);  | 
  |  59 |     | 
                   try { | 
  |  60 |    0 |                            setPropertyValue(object, propertyPath, propertyType.newInstance());  | 
  |  61 |     | 
                   }  | 
  |  62 |    0 |                    catch (Exception e) { | 
  |  63 |    0 |                            throw new RuntimeException("Unable to set new instance for property: " + propertyPath, e); | 
  |  64 |    0 |                    }  | 
  |  65 |    0 |            }  | 
  |  66 |     | 
     | 
  |  67 |     | 
           public static void setPropertyValue(Object object, String propertyPath, Object propertyValue) { | 
  |  68 |    0 |                    wrapObject(object).setPropertyValue(propertyPath, propertyValue);  | 
  |  69 |    0 |            }  | 
  |  70 |     | 
     | 
  |  71 |     | 
           public static void setPropertyValue(Object object, String propertyPath, Object propertyValue, boolean ignoreUnknown) { | 
  |  72 |     | 
                   try { | 
  |  73 |    0 |                            wrapObject(object).setPropertyValue(propertyPath, propertyValue);  | 
  |  74 |     | 
                   }  | 
  |  75 |    0 |                    catch (BeansException e) { | 
  |  76 |     | 
                             | 
  |  77 |    0 |                            if (!ignoreUnknown) { | 
  |  78 |    0 |                                    throw new RuntimeException(e);  | 
  |  79 |     | 
                           }  | 
  |  80 |    0 |                            if (LOG.isTraceEnabled()) { | 
  |  81 |    0 |                                    LOG.trace("Ignoring exception thrown during setting of property '" + propertyPath + "': " | 
  |  82 |     | 
                                                   + e.getLocalizedMessage());  | 
  |  83 |     | 
                           }  | 
  |  84 |    0 |                    }  | 
  |  85 |    0 |            }  | 
  |  86 |     | 
             | 
  |  87 |     | 
       public static boolean isReadableProperty(Object object, String propertyPath) { | 
  |  88 |    0 |            return wrapObject(object).isReadableProperty(propertyPath);  | 
  |  89 |     | 
       }  | 
  |  90 |     | 
     | 
  |  91 |     | 
       public static boolean isWritableProperty(Object object, String propertyPath) { | 
  |  92 |    0 |            return wrapObject(object).isWritableProperty(propertyPath);  | 
  |  93 |     | 
       }  | 
  |  94 |     | 
     | 
  |  95 |     | 
           public static BeanWrapper wrapObject(Object object) { | 
  |  96 |    0 |                    BeanWrapper beanWrapper = new BeanWrapperImpl(object);  | 
  |  97 |    0 |                    beanWrapper.setAutoGrowNestedPaths(true);  | 
  |  98 |     | 
                     | 
  |  99 |    0 |                    return beanWrapper;  | 
  |  100 |     | 
           }  | 
  |  101 |     | 
     | 
  |  102 |     | 
   }  |