Search in sources :

Example 1 with StringXmlCalendarPropertyEditor

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);
        }
    }
}
Also used : InetAddressTypeEditor(org.opennms.netmgt.model.InetAddressTypeEditor) BeanWrapper(org.springframework.beans.BeanWrapper) PrimaryTypeEditor(org.opennms.netmgt.model.PrimaryTypeEditor) StringXmlCalendarPropertyEditor(org.opennms.netmgt.provision.persist.StringXmlCalendarPropertyEditor) OnmsSeverityEditor(org.opennms.netmgt.model.OnmsSeverityEditor)

Example 2 with StringXmlCalendarPropertyEditor

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;
}
Also used : InetAddressTypeEditor(org.opennms.netmgt.model.InetAddressTypeEditor) BeanWrapper(org.springframework.beans.BeanWrapper) ISO8601DateEditor(org.opennms.web.api.ISO8601DateEditor) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) PrimaryTypeEditor(org.opennms.netmgt.model.PrimaryTypeEditor) StringXmlCalendarPropertyEditor(org.opennms.netmgt.provision.persist.StringXmlCalendarPropertyEditor) OnmsSeverityEditor(org.opennms.netmgt.model.OnmsSeverityEditor)

Aggregations

InetAddressTypeEditor (org.opennms.netmgt.model.InetAddressTypeEditor)2 OnmsSeverityEditor (org.opennms.netmgt.model.OnmsSeverityEditor)2 PrimaryTypeEditor (org.opennms.netmgt.model.PrimaryTypeEditor)2 StringXmlCalendarPropertyEditor (org.opennms.netmgt.provision.persist.StringXmlCalendarPropertyEditor)2 BeanWrapper (org.springframework.beans.BeanWrapper)2 ISO8601DateEditor (org.opennms.web.api.ISO8601DateEditor)1 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)1