Search in sources :

Example 31 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project syncope by apache.

the class BooleanPropertyColumn method populateItem.

@Override
public void populateItem(final Item<ICellPopulator<T>> item, final String componentId, final IModel<T> rowModel) {
    BeanWrapper bwi = new BeanWrapperImpl(rowModel.getObject());
    Object obj = bwi.getPropertyValue(getPropertyExpression());
    item.add(new Label(componentId, StringUtils.EMPTY));
    if (Boolean.valueOf(obj.toString())) {
        item.add(new AttributeModifier("class", "glyphicon glyphicon-ok"));
        item.add(new AttributeModifier("style", "display: table-cell; text-align: center;"));
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Label(org.apache.wicket.markup.html.basic.Label) AttributeModifier(org.apache.wicket.AttributeModifier)

Example 32 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project syncope by apache.

the class AutowiringSpringBeanJobFactory method createJobInstance.

@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
    Object job = beanFactory.getBean(bundle.getJobDetail().getKey().getName());
    if (isEligibleForPropertyPopulation(job)) {
        BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
        MutablePropertyValues pvs = new MutablePropertyValues();
        if (this.schedulerContext != null) {
            pvs.addPropertyValues(this.schedulerContext);
        }
        pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
        pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
        if (this.ignoredUnknownProperties != null) {
            for (String propName : this.ignoredUnknownProperties) {
                if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
                    pvs.removePropertyValue(propName);
                }
            }
            bw.setPropertyValues(pvs);
        } else {
            bw.setPropertyValues(pvs, true);
        }
    }
    return job;
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) MutablePropertyValues(org.springframework.beans.MutablePropertyValues)

Example 33 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project walkmod-core by walkmod.

the class ConfigurationImpl method getBean.

@Override
public Object getBean(String name, Map<?, ?> parameters) {
    Object result = null;
    if (name == null || "".equals(name)) {
        return result;
    }
    if (name.equals("script")) {
        name = "walkmod:commons:scripting";
    } else if (name.equals("template")) {
        name = "walkmod:commons:template";
    }
    if (beanFactory != null && beanFactory.containsBean(name)) {
        result = beanFactory.getBean(name);
    }
    if (result == null) {
        String fullName = "org.walkmod:walkmod-" + name + "-plugin:" + name;
        if (!name.contains(":") && beanFactory.containsBean(fullName)) {
            result = beanFactory.getBean(fullName);
        } else {
            String[] parts = name.split(":");
            if (parts.length == 2) {
                String pluginId = parts[0].trim();
                String beanId = parts[1].trim();
                String compositeName = "org.walkmod:walkmod-" + pluginId + "-plugin:" + beanId;
                if (pluginId.length() > 0 && beanId.length() > 0 && beanFactory.containsBean(compositeName)) {
                    result = beanFactory.getBean(compositeName);
                }
            }
        }
    }
    if (result == null) {
        try {
            Class<?> clazz = getClassLoader().loadClass(name);
            result = clazz.newInstance();
        } catch (Exception e) {
            throw new WalkModException("Sorry, it is impossible to load the bean " + name + ". Please, assure that it is a valid class name and the library which contains it is in the classpath", e);
        }
    }
    if (result != null) {
        BeanWrapper bw = new BeanWrapperImpl(result);
        if (this.parameters != null) {
            MutablePropertyValues pvs = new MutablePropertyValues(this.parameters);
            bw.setPropertyValues(pvs, true, true);
        }
        if (parameters != null) {
            MutablePropertyValues pvs = new MutablePropertyValues(parameters);
            bw.setPropertyValues(pvs, true, true);
        }
    }
    return result;
}
Also used : WalkModException(org.walkmod.exceptions.WalkModException) BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) WalkModException(org.walkmod.exceptions.WalkModException)

Example 34 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project spring-data-commons by spring-projects.

the class DirectFieldAccessFallbackBeanWrapperUnitTests method throwsAppropriateExceptionIfNoFieldFoundForWrite.

// DATACMNS-452
@Test(expected = NotWritablePropertyException.class)
public void throwsAppropriateExceptionIfNoFieldFoundForWrite() {
    BeanWrapper wrapper = new DirectFieldAccessFallbackBeanWrapper(new Sample());
    wrapper.setPropertyValue("lastname", "Matthews");
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) Test(org.junit.Test)

Example 35 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project spring-data-commons by spring-projects.

the class DirectFieldAccessFallbackBeanWrapperUnitTests method usesFieldAccessForReadIfNoAccessorCanBeFound.

// DATACMNS-452
@Test
public void usesFieldAccessForReadIfNoAccessorCanBeFound() {
    Sample sample = new Sample();
    sample.firstname = "Dave";
    BeanWrapper wrapper = new DirectFieldAccessFallbackBeanWrapper(sample);
    assertThat(wrapper.getPropertyValue("firstname")).isEqualTo("Dave");
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) Test(org.junit.Test)

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