Search in sources :

Example 81 with BeanWrapper

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;
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper)

Example 82 with BeanWrapper

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;
}
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)

Example 83 with BeanWrapper

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();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsGroup(org.opennms.netmgt.model.OnmsGroup) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 84 with BeanWrapper

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);
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) HashSet(java.util.HashSet)

Example 85 with BeanWrapper

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;
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper)

Aggregations

BeanWrapper (org.springframework.beans.BeanWrapper)144 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)79 Test (org.junit.jupiter.api.Test)31 NumberTestBean (org.springframework.beans.testfixture.beans.NumberTestBean)21 BooleanTestBean (org.springframework.beans.testfixture.beans.BooleanTestBean)20 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)19 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)18 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)18 TestBean (org.springframework.beans.testfixture.beans.TestBean)18 Consumes (javax.ws.rs.Consumes)16 PUT (javax.ws.rs.PUT)16 Path (javax.ws.rs.Path)16 PropertyEditorSupport (java.beans.PropertyEditorSupport)14 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)14 HashSet (java.util.HashSet)12 BeansException (org.springframework.beans.BeansException)12 PropertyDescriptor (java.beans.PropertyDescriptor)11 OnmsNode (org.opennms.netmgt.model.OnmsNode)9 Test (org.junit.Test)6 BigDecimal (java.math.BigDecimal)5