use of org.springframework.beans.PropertyValue in project spring-framework by spring-projects.
the class PropertyOverrideConfigurer method applyPropertyValue.
/**
* Apply the given property value to the corresponding bean.
*/
protected void applyPropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property, String value) {
BeanDefinition bd = factory.getBeanDefinition(beanName);
while (bd.getOriginatingBeanDefinition() != null) {
bd = bd.getOriginatingBeanDefinition();
}
PropertyValue pv = new PropertyValue(property, value);
pv.setOptional(this.ignoreInvalidKeys);
bd.getPropertyValues().addPropertyValue(pv);
}
use of org.springframework.beans.PropertyValue in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testExtensiveCircularReference.
@Test
public void testExtensiveCircularReference() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
for (int i = 0; i < 1000; i++) {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("spouse", new RuntimeBeanReference("bean" + (i < 99 ? i + 1 : 0))));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("bean" + i, bd);
}
lbf.preInstantiateSingletons();
for (int i = 0; i < 1000; i++) {
TestBean bean = (TestBean) lbf.getBean("bean" + i);
TestBean otherBean = (TestBean) lbf.getBean("bean" + (i < 99 ? i + 1 : 0));
assertTrue(bean.getSpouse() == otherBean);
}
}
use of org.springframework.beans.PropertyValue in project spring-framework by spring-projects.
the class ScriptFactoryPostProcessor method createConfigInterface.
/**
* Create a config interface for the given bean definition, defining setter
* methods for the defined property values as well as an init method and
* a destroy method (if defined).
* <p>This implementation creates the interface via CGLIB's InterfaceMaker,
* determining the property types from the given interfaces (as far as possible).
* @param bd the bean definition (property values etc) to create a
* config interface for
* @param interfaces the interfaces to check against (might define
* getters corresponding to the setters we're supposed to generate)
* @return the config interface
* @see org.springframework.cglib.proxy.InterfaceMaker
* @see org.springframework.beans.BeanUtils#findPropertyType
*/
protected Class<?> createConfigInterface(BeanDefinition bd, Class<?>[] interfaces) {
InterfaceMaker maker = new InterfaceMaker();
PropertyValue[] pvs = bd.getPropertyValues().getPropertyValues();
for (PropertyValue pv : pvs) {
String propertyName = pv.getName();
Class<?> propertyType = BeanUtils.findPropertyType(propertyName, interfaces);
String setterName = "set" + StringUtils.capitalize(propertyName);
Signature signature = new Signature(setterName, Type.VOID_TYPE, new Type[] { Type.getType(propertyType) });
maker.add(signature, new Type[0]);
}
if (bd instanceof AbstractBeanDefinition) {
AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
if (abd.getInitMethodName() != null) {
Signature signature = new Signature(abd.getInitMethodName(), Type.VOID_TYPE, new Type[0]);
maker.add(signature, new Type[0]);
}
if (StringUtils.hasText(abd.getDestroyMethodName())) {
Signature signature = new Signature(abd.getDestroyMethodName(), Type.VOID_TYPE, new Type[0]);
maker.add(signature, new Type[0]);
}
}
return maker.create();
}
use of org.springframework.beans.PropertyValue in project spring-framework by spring-projects.
the class MetadataAttachmentTests method propertyMetadata.
@Test
public void propertyMetadata() throws Exception {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("testBean3");
PropertyValue pv = beanDefinition.getPropertyValues().getPropertyValue("name");
assertEquals("Harrop", pv.getAttribute("surname"));
}
use of org.springframework.beans.PropertyValue in project spring-framework by spring-projects.
the class DataBinderFieldAccessTests method nestedBindingWithDefaultConversionNoErrors.
@Test
public void nestedBindingWithDefaultConversionNoErrors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
assertTrue(binder.isIgnoreUnknownFields());
binder.initDirectFieldAccess();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("spouse.name", "Kerry"));
pvs.addPropertyValue(new PropertyValue("spouse.jedi", "on"));
binder.bind(pvs);
binder.close();
assertEquals("Kerry", rod.getSpouse().getName());
assertTrue((rod.getSpouse()).isJedi());
}
Aggregations