本文整理匯總了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());
}