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