use of org.opennms.netmgt.provision.persist.StringXmlCalendarPropertyEditor in project opennms by OpenNMS.
the class RestUtils method setBeanProperties.
/**
* <p>Use Spring's {@link PropertyAccessorFactory} to set values on the specified bean.
* This call registers several {@link PropertyEditor} classes to properly convert
* values.</p>
*
* <ul>
* <li>{@link StringXmlCalendarPropertyEditor}</li>
* <li>{@link ISO8601DateEditor}</li>
* <li>{@link InetAddressTypeEditor}</li>
* <li>{@link OnmsSeverityEditor}</li>
* <li>{@link PrimaryTypeEditor}</li>
* </ul>
*
* @param bean
* @param properties
*/
public static void setBeanProperties(final Object bean, final MultivaluedMap<String, String> properties) {
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean);
wrapper.registerCustomEditor(XMLGregorianCalendar.class, new StringXmlCalendarPropertyEditor());
wrapper.registerCustomEditor(Date.class, new ISO8601DateEditor());
wrapper.registerCustomEditor(InetAddress.class, new InetAddressTypeEditor());
wrapper.registerCustomEditor(OnmsSeverity.class, new OnmsSeverityEditor());
wrapper.registerCustomEditor(PrimaryType.class, new PrimaryTypeEditor());
for (final String key : properties.keySet()) {
final String propertyName = convertNameToPropertyName(key);
if (wrapper.isWritableProperty(propertyName)) {
final String stringValue = properties.getFirst(key);
Object value = convertIfNecessary(wrapper, propertyName, stringValue);
wrapper.setPropertyValue(propertyName, value);
}
}
}
use of org.opennms.netmgt.provision.persist.StringXmlCalendarPropertyEditor in project opennms by OpenNMS.
the class OnmsRestService method getBeanWrapperForClass.
protected static BeanWrapper getBeanWrapperForClass(final Class<?> criteriaClass) {
final BeanWrapper wrapper = new BeanWrapperImpl(criteriaClass);
wrapper.registerCustomEditor(XMLGregorianCalendar.class, new StringXmlCalendarPropertyEditor());
wrapper.registerCustomEditor(java.util.Date.class, new ISO8601DateEditor());
wrapper.registerCustomEditor(java.net.InetAddress.class, new InetAddressTypeEditor());
wrapper.registerCustomEditor(OnmsSeverity.class, new OnmsSeverityEditor());
wrapper.registerCustomEditor(PrimaryType.class, new PrimaryTypeEditor());
return wrapper;
}
Aggregations