当前位置: 首页>>代码示例>>Java>>正文


Java BeanWrapperImpl类代码示例

本文整理汇总了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();
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:17,代码来源:BindingPreparationTests.java

示例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()));
		}
	}
}
 
开发者ID:rvillars,项目名称:edoras-one-initializr,代码行数:19,代码来源:AbstractInitializrController.java

示例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;
}
 
开发者ID:Azanx,项目名称:Smart-Shopping,代码行数:17,代码来源:FieldsVerificationValidator.java

示例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();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:TaskExecutorFactoryBean.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:AbstractAutowireCapableBeanFactory.java

示例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;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:AbstractAutowireCapableBeanFactory.java

示例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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:AbstractAutowireCapableBeanFactory.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:GroovyBeanDefinitionWrapper.java

示例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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:BeanInfoTests.java

示例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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:CustomEditorTests.java

示例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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:CustomEditorTests.java

示例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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:CustomEditorTests.java

示例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;
  }
 
开发者ID:DISID,项目名称:springlets,代码行数:21,代码来源:ConvertedDatatablesData.java

示例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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:CustomEditorTests.java

示例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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:CustomEditorTests.java


注:本文中的org.springframework.beans.BeanWrapperImpl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。