Search in sources :

Example 36 with BeanWrapperImpl

use of org.springframework.beans.BeanWrapperImpl in project spring-framework by spring-projects.

the class CustomEditorTests method testCustomEditorForAllNestedStringProperties.

@Test
public void testCustomEditorForAllNestedStringProperties() {
    TestBean tb = new TestBean();
    tb.setSpouse(new TestBean());
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(String.class, new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            setValue("prefix" + text);
        }
    });
    bw.setPropertyValue("spouse.name", "value");
    bw.setPropertyValue("touchy", "value");
    assertEquals("prefixvalue", bw.getPropertyValue("spouse.name"));
    assertEquals("prefixvalue", tb.getSpouse().getName());
    assertEquals("prefixvalue", bw.getPropertyValue("touchy"));
    assertEquals("prefixvalue", tb.getTouchy());
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) BooleanTestBean(org.springframework.tests.sample.beans.BooleanTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NumberTestBean(org.springframework.tests.sample.beans.NumberTestBean) PropertyEditorSupport(java.beans.PropertyEditorSupport) Test(org.junit.Test)

Example 37 with BeanWrapperImpl

use of org.springframework.beans.BeanWrapperImpl in project spring-framework by spring-projects.

the class CustomEditorTests method testCharacterEditorWithAllowEmpty.

@Test
public void testCharacterEditorWithAllowEmpty() {
    CharBean cb = new CharBean();
    BeanWrapper bw = new BeanWrapperImpl(cb);
    bw.registerCustomEditor(Character.class, new CharacterEditor(true));
    bw.setPropertyValue("myCharacter", new Character('c'));
    assertEquals(new Character('c'), cb.getMyCharacter());
    bw.setPropertyValue("myCharacter", "c");
    assertEquals(new Character('c'), cb.getMyCharacter());
    bw.setPropertyValue("myCharacter", "A");
    assertEquals(new Character('A'), cb.getMyCharacter());
    bw.setPropertyValue("myCharacter", " ");
    assertEquals(new Character(' '), cb.getMyCharacter());
    bw.setPropertyValue("myCharacter", "");
    assertNull(cb.getMyCharacter());
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Test(org.junit.Test)

Example 38 with BeanWrapperImpl

use of org.springframework.beans.BeanWrapperImpl in project spring-framework by spring-projects.

the class CustomEditorTests method testArrayToArrayConversion.

@Test
public void testArrayToArrayConversion() throws PropertyVetoException {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            setValue(new TestBean(text, 99));
        }
    });
    bw.setPropertyValue("array", new String[] { "a", "b" });
    assertEquals(2, tb.getArray().length);
    assertEquals("a", tb.getArray()[0].getName());
    assertEquals("b", tb.getArray()[1].getName());
}
Also used : IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) BooleanTestBean(org.springframework.tests.sample.beans.BooleanTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NumberTestBean(org.springframework.tests.sample.beans.NumberTestBean) PropertyEditorSupport(java.beans.PropertyEditorSupport) Test(org.junit.Test)

Example 39 with BeanWrapperImpl

use of org.springframework.beans.BeanWrapperImpl in project spring-framework by spring-projects.

the class CustomEditorTests method testArrayToStringConversion.

@Test
public void testArrayToStringConversion() throws PropertyVetoException {
    TestBean tb = new TestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(String.class, new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            setValue("-" + text + "-");
        }
    });
    bw.setPropertyValue("name", new String[] { "a", "b" });
    assertEquals("-a,b-", tb.getName());
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) BooleanTestBean(org.springframework.tests.sample.beans.BooleanTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NumberTestBean(org.springframework.tests.sample.beans.NumberTestBean) PropertyEditorSupport(java.beans.PropertyEditorSupport) Test(org.junit.Test)

Example 40 with BeanWrapperImpl

use of org.springframework.beans.BeanWrapperImpl in project midpoint by Evolveum.

the class ConnectorFactoryBuiltinImpl method generateConnectorConfigurationSchema.

private PrismSchema generateConnectorConfigurationSchema(ConnectorStruct struct) {
    Class<? extends ConnectorInstance> connectorClass = struct.connectorClass;
    PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorClass, ManagedConnectorConfiguration.class);
    PrismSchema connectorSchema = new PrismSchemaImpl(struct.connectorObject.getNamespace(), prismContext);
    // Create configuration type - the type used by the "configuration" element
    PrismContainerDefinitionImpl<?> configurationContainerDef = ((PrismSchemaImpl) connectorSchema).createPropertyContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart(), SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_TYPE_LOCAL_NAME);
    Class<?> configurationClass = connectorConfigurationProp.getPropertyType();
    BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationClass);
    for (PropertyDescriptor prop : configurationClassBean.getPropertyDescriptors()) {
        if (!UcfUtil.hasAnnotation(prop, ConfigurationProperty.class)) {
            continue;
        }
        ItemDefinition<?> itemDef = createPropertyDefinition(configurationContainerDef, prop);
        LOGGER.trace("Configuration item definition for {}: {}", prop.getName(), itemDef);
    }
    return connectorSchema;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ConfigurationProperty(com.evolveum.midpoint.provisioning.ucf.api.ConfigurationProperty) PrismSchemaImpl(com.evolveum.midpoint.prism.schema.PrismSchemaImpl) BeanWrapper(org.springframework.beans.BeanWrapper) PropertyDescriptor(java.beans.PropertyDescriptor) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl)

Aggregations

BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)85 BeanWrapper (org.springframework.beans.BeanWrapper)57 Test (org.junit.Test)47 NumberTestBean (org.springframework.tests.sample.beans.NumberTestBean)21 BooleanTestBean (org.springframework.tests.sample.beans.BooleanTestBean)20 ITestBean (org.springframework.tests.sample.beans.ITestBean)17 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)17 TestBean (org.springframework.tests.sample.beans.TestBean)17 PropertyEditorSupport (java.beans.PropertyEditorSupport)14 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)11 PropertyDescriptor (java.beans.PropertyDescriptor)7 BeansException (org.springframework.beans.BeansException)7 ArrayList (java.util.ArrayList)5 BeanCreationException (org.springframework.beans.factory.BeanCreationException)5 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)5 GrailsDomainClassProperty (grails.core.GrailsDomainClassProperty)4 BigDecimal (java.math.BigDecimal)4 BigInteger (java.math.BigInteger)4 PrivilegedAction (java.security.PrivilegedAction)4 Map (java.util.Map)4