/** * Gets the property descriptor for the named property on the given class. * @param clazz Class to which property belongs. * @param propertyName Name of property. * @return Property descriptor for given property or null if no property with given * name exists in given class. */ public static PropertyDescriptor getPropertyDescriptor(final Class<?> clazz, final String propertyName) { try { return getPropertyDescriptor(Introspector.getBeanInfo(clazz), propertyName); } catch (final IntrospectionException e) { throw new RuntimeException("Failed getting bean info for " + clazz, e); } }
/** * Gets the property descriptor for the named property on the given class. * @param clazz Class to which property belongs. * @param propertyName Name of property. * @return Property descriptor for given property or null if no property with given * name exists in given class. */ public static PropertyDescriptor getPropertyDescriptor(final Class clazz, final String propertyName) { try { return getPropertyDescriptor(Introspector.getBeanInfo(clazz), propertyName); } catch (final IntrospectionException e) { throw new RuntimeException("Failed getting bean info for " + clazz, e); } }
/** * Sets the given property on the target JavaBean using bean instrospection. * @param propertyName Property to set. * @param value Property value to set. * @param target Target JavaBean on which to set property. * @param info BeanInfo describing the target JavaBean. */ public static void setProperty(final String propertyName, final Object value, final Object target, final BeanInfo info) { try { final PropertyDescriptor pd = getPropertyDescriptor(info, propertyName); pd.getWriteMethod().invoke(target, value); } catch (final InvocationTargetException e) { throw new RuntimeException("Error setting property " + propertyName, e.getCause()); } catch (final Exception e) { throw new RuntimeException("Error setting property " + propertyName, e); } }
/** * Sets the given property on the target javabean using bean instrospection. * @param propertyName Property to set. * @param value Property value to set. * @param target Target javabean on which to set property. * @param info BeanInfo describing the target javabean. */ public static void setProperty(final String propertyName, final Object value, final Object target, final BeanInfo info) { try { final PropertyDescriptor pd = getPropertyDescriptor(info, propertyName); pd.getWriteMethod().invoke(target, new Object[] { value }); } catch (final InvocationTargetException e) { throw new RuntimeException("Error setting property " + propertyName, e.getCause()); } catch (final Exception e) { throw new RuntimeException("Error setting property " + propertyName, e); } } }
log.debug("Attempting to set TicketValidator property " + property); final String value = (String) propertyMap.get(property); final PropertyDescriptor pd = ReflectUtils.getPropertyDescriptor(info, property); if (pd != null) { ReflectUtils.setProperty(property, convertIfNecessary(pd, value), validator, info);
logger.debug("Attempting to set TicketValidator property {}", property); final String value = (String) propertyMap.get(property); final PropertyDescriptor pd = ReflectUtils.getPropertyDescriptor(info, property); if (pd != null) { ReflectUtils.setProperty(property, convertIfNecessary(pd, value), validator, info);