本文整理汇总了Java中org.springframework.beans.BeanWrapperImpl类的典型用法代码示例。如果您正苦于以下问题:Java BeanWrapperImpl类的具体用法?Java BeanWrapperImpl怎么用?Java BeanWrapperImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BeanWrapperImpl类属于org.springframework.beans包,在下文中一共展示了BeanWrapperImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBeanWrapperCreatesNewNestedMaps
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
@Test
public void testBeanWrapperCreatesNewNestedMaps() throws Exception {
TargetWithNestedMap target = new TargetWithNestedMap();
BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
wrapper.setAutoGrowNestedPaths(true);
// For a nested map, you only have to get an element of it for it to be created
wrapper.getPropertyValue("nested[foo]");
// To decide what type to create for nested[foo] we need to look ahead and see
// what the user is trying to bind it to, e.g. if nested[foo][bar] then it's a map
wrapper.setPropertyValue("nested[foo]", new LinkedHashMap<String, Object>());
// But it might equally well be a collection, if nested[foo][0]
wrapper.setPropertyValue("nested[foo]", new ArrayList<Object>());
// Then it would have to be actually bound to get the list to auto-grow
wrapper.setPropertyValue("nested[foo][0]", "bar");
assertThat(wrapper.getPropertyValue("nested[foo][0]")).isNotNull();
}
示例2: renderHome
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
/**
* Render the home page with the specified template.
*/
protected void renderHome(Map<String, Object> model) {
InitializrMetadata metadata = metadataProvider.get();
model.put("serviceUrl", generateAppUrl());
BeanWrapperImpl wrapper = new BeanWrapperImpl(metadata);
for (PropertyDescriptor descriptor : wrapper.getPropertyDescriptors()) {
if ("types".equals(descriptor.getName())) {
model.put("types", removeTypes(metadata.getTypes()));
}
else {
model.put(descriptor.getName(),
wrapper.getPropertyValue(descriptor.getName()));
}
}
}
示例3: isValid
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
Object fieldValue = new BeanWrapperImpl(value).getPropertyValue(field);
Object fieldMatchValue = new BeanWrapperImpl(value).getPropertyValue(fieldMatch);
boolean result = false;
if(fieldValue != null)
{
//Passwords are kept as char arrays, other values mostly as Strings
if(fieldValue instanceof char[])
result = Arrays.equals((char[])fieldValue, (char[])fieldMatchValue);
else result = fieldValue.equals(fieldMatchValue);
} else
result = fieldMatchValue == null;
return result;
}
示例4: afterPropertiesSet
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
BeanWrapper bw = new BeanWrapperImpl(ThreadPoolTaskExecutor.class);
determinePoolSizeRange(bw);
if (this.queueCapacity != null) {
bw.setPropertyValue("queueCapacity", this.queueCapacity);
}
if (this.keepAliveSeconds != null) {
bw.setPropertyValue("keepAliveSeconds", this.keepAliveSeconds);
}
if (this.rejectedExecutionHandler != null) {
bw.setPropertyValue("rejectedExecutionHandler", this.rejectedExecutionHandler);
}
if (this.beanName != null) {
bw.setPropertyValue("threadNamePrefix", this.beanName + "-");
}
this.target = (TaskExecutor) bw.getWrappedInstance();
if (this.target instanceof InitializingBean) {
((InitializingBean) this.target).afterPropertiesSet();
}
}
示例5: configureBean
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
@Override
public Object configureBean(Object existingBean, String beanName) throws BeansException {
markBeanAsCreated(beanName);
BeanDefinition mbd = getMergedBeanDefinition(beanName);
RootBeanDefinition bd = null;
if (mbd instanceof RootBeanDefinition) {
RootBeanDefinition rbd = (RootBeanDefinition) mbd;
bd = (rbd.isPrototype() ? rbd : rbd.cloneBeanDefinition());
}
if (!mbd.isPrototype()) {
if (bd == null) {
bd = new RootBeanDefinition(mbd);
}
bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bd.allowCaching = ClassUtils.isCacheSafe(ClassUtils.getUserClass(existingBean), getBeanClassLoader());
}
BeanWrapper bw = new BeanWrapperImpl(existingBean);
initBeanWrapper(bw);
populateBean(beanName, bd, bw);
return initializeBean(beanName, existingBean, bd);
}
示例6: autowire
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
@Override
public Object autowire(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException {
// Use non-singleton bean definition, to avoid registering bean as dependent bean.
final RootBeanDefinition bd = new RootBeanDefinition(beanClass, autowireMode, dependencyCheck);
bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
if (bd.getResolvedAutowireMode() == AUTOWIRE_CONSTRUCTOR) {
return autowireConstructor(beanClass.getName(), bd, null, null).getWrappedInstance();
}
else {
Object bean;
final BeanFactory parent = this;
if (System.getSecurityManager() != null) {
bean = AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
return getInstantiationStrategy().instantiate(bd, null, parent);
}
}, getAccessControlContext());
}
else {
bean = getInstantiationStrategy().instantiate(bd, null, parent);
}
populateBean(beanClass.getName(), bd, new BeanWrapperImpl(bean));
return bean;
}
}
示例7: instantiateBean
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
/**
* Instantiate the given bean using its default constructor.
* @param beanName the name of the bean
* @param mbd the bean definition for the bean
* @return BeanWrapper for the new instance
*/
protected BeanWrapper instantiateBean(final String beanName, final RootBeanDefinition mbd) {
try {
Object beanInstance;
final BeanFactory parent = this;
if (System.getSecurityManager() != null) {
beanInstance = AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
return getInstantiationStrategy().instantiate(mbd, beanName, parent);
}
}, getAccessControlContext());
}
else {
beanInstance = getInstantiationStrategy().instantiate(mbd, beanName, parent);
}
BeanWrapper bw = new BeanWrapperImpl(beanInstance);
initBeanWrapper(bw);
return bw;
}
catch (Throwable ex) {
throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Instantiation of bean failed", ex);
}
}
示例8: createBeanDefinition
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
protected AbstractBeanDefinition createBeanDefinition() {
AbstractBeanDefinition bd = new GenericBeanDefinition();
bd.setBeanClass(this.clazz);
if (!CollectionUtils.isEmpty(this.constructorArgs)) {
ConstructorArgumentValues cav = new ConstructorArgumentValues();
for (Object constructorArg : this.constructorArgs) {
cav.addGenericArgumentValue(constructorArg);
}
bd.setConstructorArgumentValues(cav);
}
if (this.parentName != null) {
bd.setParentName(this.parentName);
}
this.definitionWrapper = new BeanWrapperImpl(bd);
return bd;
}
示例9: testComplexObject
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
@Test
public void testComplexObject() {
ValueBean bean = new ValueBean();
BeanWrapper bw = new BeanWrapperImpl(bean);
Integer value = new Integer(1);
bw.setPropertyValue("value", value);
assertEquals("value not set correctly", bean.getValue(), value);
value = new Integer(2);
bw.setPropertyValue("value", value.toString());
assertEquals("value not converted", bean.getValue(), value);
bw.setPropertyValue("value", null);
assertNull("value not null", bean.getValue());
bw.setPropertyValue("value", "");
assertNull("value not converted to null", bean.getValue());
}
示例10: testComplexObject
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
@Test
public void testComplexObject() {
TestBean tb = new TestBean();
String newName = "Rod";
String tbString = "Kerry_34";
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(ITestBean.class, new TestBeanEditor());
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("age", new Integer(55)));
pvs.addPropertyValue(new PropertyValue("name", newName));
pvs.addPropertyValue(new PropertyValue("touchy", "valid"));
pvs.addPropertyValue(new PropertyValue("spouse", tbString));
bw.setPropertyValues(pvs);
assertTrue("spouse is non-null", tb.getSpouse() != null);
assertTrue("spouse name is Kerry and age is 34",
tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34);
}
示例11: testCustomEditorForSingleProperty
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
@Test
public void testCustomEditorForSingleProperty() {
TestBean tb = new TestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(String.class, "name", new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue("prefix" + text);
}
});
bw.setPropertyValue("name", "value");
bw.setPropertyValue("touchy", "value");
assertEquals("prefixvalue", bw.getPropertyValue("name"));
assertEquals("prefixvalue", tb.getName());
assertEquals("value", bw.getPropertyValue("touchy"));
assertEquals("value", tb.getTouchy());
}
示例12: testCustomEditorForSingleNestedProperty
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
@Test
public void testCustomEditorForSingleNestedProperty() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(String.class, "spouse.name", 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("value", bw.getPropertyValue("touchy"));
assertEquals("value", tb.getTouchy());
}
示例13: convert
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
private static Map<String, Object> convert(Object value, ConversionService conversionService) {
BeanWrapper bean = new BeanWrapperImpl(value);
PropertyDescriptor[] properties = bean.getPropertyDescriptors();
Map<String, Object> convertedValue = new HashMap<>(properties.length);
for (int i = 0; i < properties.length; i++) {
String name = properties[i].getName();
Object propertyValue = bean.getPropertyValue(name);
if (propertyValue != null
&& conversionService.canConvert(propertyValue.getClass(), String.class)) {
TypeDescriptor source = bean.getPropertyTypeDescriptor(name);
String convertedPropertyValue =
(String) conversionService.convert(propertyValue, source, TYPE_STRING);
convertedValue.put(name, convertedPropertyValue);
}
}
return convertedValue;
}
示例14: testCharacterEditor
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
@Test
public void testCharacterEditor() {
CharBean cb = new CharBean();
BeanWrapper bw = new BeanWrapperImpl(cb);
bw.setPropertyValue("myChar", new Character('c'));
assertEquals('c', cb.getMyChar());
bw.setPropertyValue("myChar", "c");
assertEquals('c', cb.getMyChar());
bw.setPropertyValue("myChar", "\u0041");
assertEquals('A', cb.getMyChar());
bw.setPropertyValue("myChar", "\\u0022");
assertEquals('"', cb.getMyChar());
CharacterEditor editor = new CharacterEditor(false);
editor.setAsText("M");
assertEquals("M", editor.getAsText());
}
示例15: testCharacterEditorWithAllowEmpty
import org.springframework.beans.BeanWrapperImpl; //导入依赖的package包/类
@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", "\u0041");
assertEquals(new Character('A'), cb.getMyCharacter());
bw.setPropertyValue("myCharacter", " ");
assertEquals(new Character(' '), cb.getMyCharacter());
bw.setPropertyValue("myCharacter", "");
assertNull(cb.getMyCharacter());
}