Author: tchemit Date: 2014-09-09 17:45:37 +0200 (Tue, 09 Sep 2014) New Revision: 2683 Url: http://forge.nuiton.org/projects/nuiton-utils/repository/revisions/2683 Log: fixes #3500: Add org.nuiton.util.beans.BeanUtil#getMutator method Modified: trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java Modified: trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java =================================================================== --- trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java 2014-09-09 12:43:03 UTC (rev 2682) +++ trunk/src/main/java/org/nuiton/util/beans/BeanUtil.java 2014-09-09 15:45:37 UTC (rev 2683) @@ -32,6 +32,7 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -314,6 +315,27 @@ return new HashSet<PropertyDescriptor>(result.values()); } + public static Method getMutator(Object bean, String property) { + Method mutator = null; + if (bean == null) { + throw new NullPointerException("could not find bean"); + } + if (property == null) { + throw new NullPointerException("could not find property"); + } + + try { + PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(bean, property); + if (descriptor != null) { + mutator = descriptor.getWriteMethod(); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + + return mutator; + } + protected static void getDescriptors(Class<?> beanType, Predicate<PropertyDescriptor> predicate, Map<String, PropertyDescriptor> result,