use of org.opennms.netmgt.model.OnmsSeverityEditor 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.model.OnmsSeverityEditor 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;
}
use of org.opennms.netmgt.model.OnmsSeverityEditor in project opennms by OpenNMS.
the class PropertyUtils method getPathValue.
/**
* <p>getPathValue</p>
*
* @param bean a {@link java.lang.Object} object.
* @param path a {@link java.lang.String} object.
* @param expectedClass a {@link java.lang.Class} object.
* @param <T> a T object.
* @return a T object.
*/
@SuppressWarnings("unchecked")
public static <T> T getPathValue(final Object bean, final String path, final Class<T> expectedClass) {
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean);
wrapper.registerCustomEditor(java.net.InetAddress.class, new InetAddressTypeEditor());
wrapper.registerCustomEditor(OnmsSeverity.class, new OnmsSeverityEditor());
wrapper.registerCustomEditor(PrimaryType.class, new PrimaryTypeEditor());
final Class<?> propType = wrapper.getPropertyType(path);
if (propType == null) {
// we were unable to find the property
// for debug purposes
Assert.notNull(propType, "propType in BeanUtils is null path: " + path);
return null;
}
if (!expectedClass.isAssignableFrom(propType)) {
throw new IllegalArgumentException("Could not retrieve property of type " + propType + " as type " + expectedClass);
}
return (T) wrapper.getPropertyValue(path);
}
Aggregations