use of org.springframework.beans.BeanWrapper in project opennms by OpenNMS.
the class BasePolicy method matchAny.
private boolean matchAny(final T iface) {
final BeanWrapper bean = PropertyAccessorFactory.forBeanPropertyAccess(iface);
for (final Entry<String, String> term : getCriteria().entrySet()) {
final String val = getPropertyValueAsString(bean, term.getKey());
final String matchExpression = term.getValue();
if (match(val, matchExpression)) {
return true;
}
}
return false;
}
use of org.springframework.beans.BeanWrapper 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.springframework.beans.BeanWrapper in project opennms by OpenNMS.
the class GroupRestService method updateGroup.
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{groupName}")
public Response updateGroup(@PathParam("groupName") final String groupName, final MultivaluedMapImpl params) {
writeLock();
try {
OnmsGroup group = getOnmsGroup(groupName);
LOG.debug("updateGroup: updating group {}", group);
boolean modified = false;
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(group);
for (final String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
final String stringValue = params.getFirst(key);
final Object value = wrapper.convertIfNecessary(stringValue, wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateGroup: group {} updated", group);
m_groupService.saveGroup(group);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of org.springframework.beans.BeanWrapper in project MyPig by weifuchow.
the class BeanUtilsExt method getNullPropertyNames.
public static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<String>();
for (java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null)
emptyNames.add(pd.getName());
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
use of org.springframework.beans.BeanWrapper in project opennms by OpenNMS.
the class NxosAdapterFactory method createAdapter.
@Override
public Adapter createAdapter(Protocol protocol, Map<String, String> properties) {
final NxosGpbAdapter adapter = new NxosGpbAdapter();
adapter.setProtocol(protocol);
adapter.setCollectionAgentFactory(getCollectionAgentFactory());
adapter.setInterfaceToNodeCache(getInterfaceToNodeCache());
adapter.setNodeDao(getNodeDao());
adapter.setTransactionTemplate(getTransactionTemplate());
adapter.setFilterDao(getFilterDao());
adapter.setPersisterFactory(getPersisterFactory());
adapter.setBundleContext(getBundleContext());
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(adapter);
wrapper.setPropertyValues(properties);
return adapter;
}
Aggregations