當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。