本文整理汇总了Java中org.springframework.beans.BeanWrapper.setPropertyValue方法的典型用法代码示例。如果您正苦于以下问题:Java BeanWrapper.setPropertyValue方法的具体用法?Java BeanWrapper.setPropertyValue怎么用?Java BeanWrapper.setPropertyValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.beans.BeanWrapper
的用法示例。
在下文中一共展示了BeanWrapper.setPropertyValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Override
public Object add(Object object) {
SqlModel<Object> sqlModel = sqlBuilder.insertSelectiveSql(object);
checkSqlModel(sqlModel);
SqlParameterSource paramSource = new BeanPropertySqlParameterSource(object);
KeyHolder generatedKeyHolder = new GeneratedKeyHolder();
namedPjdbcTemplate.update(sqlModel.getSql(), paramSource, generatedKeyHolder);
Number num = generatedKeyHolder.getKey();
String[] primaryKeys = sqlModel.getPrimaryKeys();
if(primaryKeys != null && primaryKeys.length > 0){
BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(object);
beanWrapper.setPropertyValue(primaryKeys[0], num);
}
return object;
}
示例2: applyMapOntoInstance
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
* Injects the properties from the given Map to the given object. Additionally, a bean factory can be passed in for
* copying property editors inside the injector.
*
* @param instance bean instance to configure
* @param properties
* @param beanFactory
*/
public static void applyMapOntoInstance(Object instance, Map<String, ?> properties, AbstractBeanFactory beanFactory) {
if (properties != null && !properties.isEmpty()) {
BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(instance);
beanWrapper.setAutoGrowNestedPaths(true);
// configure bean wrapper (using method from Spring 2.5.6)
if (beanFactory != null) {
beanFactory.copyRegisteredEditorsTo(beanWrapper);
}
for (Iterator<?> iterator = properties.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<String, ?> entry = (Map.Entry<String, ?>) iterator.next();
String propertyName = entry.getKey();
if (beanWrapper.isWritableProperty(propertyName)) {
beanWrapper.setPropertyValue(propertyName, entry.getValue());
}
}
}
}
示例3: afterPropertiesSet
import org.springframework.beans.BeanWrapper; //导入方法依赖的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();
}
}
示例4: copyPropertiesToBean
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
* Copy the properties of the supplied {@link Annotation} to the supplied target bean.
* Any properties defined in {@code excludedProperties} will not be copied.
* <p>A specified value resolver may resolve placeholders in property values, for example.
* @param ann the annotation to copy from
* @param bean the bean instance to copy to
* @param valueResolver a resolve to post-process String property values (may be {@code null})
* @param excludedProperties the names of excluded properties, if any
* @see org.springframework.beans.BeanWrapper
*/
public static void copyPropertiesToBean(Annotation ann, Object bean, StringValueResolver valueResolver, String... excludedProperties) {
Set<String> excluded = new HashSet<String>(Arrays.asList(excludedProperties));
Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
for (Method annotationProperty : annotationProperties) {
String propertyName = annotationProperty.getName();
if ((!excluded.contains(propertyName)) && bw.isWritableProperty(propertyName)) {
Object value = ReflectionUtils.invokeMethod(annotationProperty, ann);
if (valueResolver != null && value instanceof String) {
value = valueResolver.resolveStringValue((String) value);
}
bw.setPropertyValue(propertyName, value);
}
}
}
示例5: applyConfigurationToConfigurationClass
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
private void applyConfigurationToConfigurationClass(PrismContainerValue<?> configurationContainer) throws ConfigurationException {
BeanWrapper connectorBean = new BeanWrapperImpl(this);
PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorBean, ManagedConnectorConfiguration.class);
if (connectorConfigurationProp == null) {
return;
}
Class<?> configurationClass = connectorConfigurationProp.getPropertyType();
Object configurationObject;
try {
configurationObject = configurationClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new ConfigurationException("Cannot instantiate configuration "+configurationClass);
}
BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationObject);
for (Item<?, ?> configurationItem: configurationContainer.getItems()) {
if (! (configurationItem instanceof PrismProperty<?>)) {
throw new ConfigurationException("Only properties are supported for now");
}
PrismProperty<?> configurationProperty = (PrismProperty<?>)configurationItem;
Object realValue = configurationProperty.getRealValue();
configurationClassBean.setPropertyValue(configurationProperty.getElementName().getLocalPart(), realValue);
}
connectorBean.setPropertyValue(connectorConfigurationProp.getName(), configurationObject);
}
示例6: createDefinitionsFactory
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Override
protected DefinitionsFactory createDefinitionsFactory(ApplicationContext applicationContext,
LocaleResolver resolver) {
if (definitionsFactoryClass != null) {
DefinitionsFactory factory = BeanUtils.instantiate(definitionsFactoryClass);
if (factory instanceof ApplicationContextAware) {
((ApplicationContextAware) factory).setApplicationContext(applicationContext);
}
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(factory);
if (bw.isWritableProperty("localeResolver")) {
bw.setPropertyValue("localeResolver", resolver);
}
if (bw.isWritableProperty("definitionDAO")) {
bw.setPropertyValue("definitionDAO", createLocaleDefinitionDao(applicationContext, resolver));
}
return factory;
}
else {
return super.createDefinitionsFactory(applicationContext, resolver);
}
}
示例7: copyPropertiesToBean
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
* Copy the properties of the supplied {@link Annotation} to the supplied target bean.
* Any properties defined in {@code excludedProperties} will not be copied.
* <p>A specified value resolver may resolve placeholders in property values, for example.
* @param ann the annotation to copy from
* @param bean the bean instance to copy to
* @param valueResolver a resolve to post-process String property values (may be {@code null})
* @param excludedProperties the names of excluded properties, if any
* @see org.springframework.beans.BeanWrapper
*/
public static void copyPropertiesToBean(Annotation ann, Object bean, StringValueResolver valueResolver, String... excludedProperties) {
Set<String> excluded = new HashSet<String>(Arrays.asList(excludedProperties));
Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
for (Method annotationProperty : annotationProperties) {
String propertyName = annotationProperty.getName();
if (!excluded.contains(propertyName) && bw.isWritableProperty(propertyName)) {
Object value = ReflectionUtils.invokeMethod(annotationProperty, ann);
if (valueResolver != null && value instanceof String) {
value = valueResolver.resolveStringValue((String) value);
}
bw.setPropertyValue(propertyName, value);
}
}
}
示例8: testCustomEditorForAllNestedStringProperties
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Test
public void testCustomEditorForAllNestedStringProperties() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(String.class, 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("prefixvalue", bw.getPropertyValue("touchy"));
assertEquals("prefixvalue", tb.getTouchy());
}
示例9: testIndexedPropertiesWithListPropertyEditor
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Test
public void testIndexedPropertiesWithListPropertyEditor() {
IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.registerCustomEditor(List.class, "list", new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
List<TestBean> result = new ArrayList<TestBean>();
result.add(new TestBean("list" + text, 99));
setValue(result);
}
});
bw.setPropertyValue("list", "1");
assertEquals("list1", ((TestBean) bean.getList().get(0)).getName());
bw.setPropertyValue("list[0]", "test");
assertEquals("test", bean.getList().get(0));
}
示例10: testCharacterEditorWithAllowEmpty
import org.springframework.beans.BeanWrapper; //导入方法依赖的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());
}
示例11: testBeanWrapper
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Test
public void testBeanWrapper(){
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
bw.setPropertyValue("name", "haoc");
Object value = bw.getPropertyValue("name");
System.out.println(value);
}
示例12: testArrayToArrayConversion
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Test
public void testArrayToArrayConversion() throws PropertyVetoException {
IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(new TestBean(text, 99));
}
});
bw.setPropertyValue("array", new String[] {"a", "b"});
assertEquals(2, tb.getArray().length);
assertEquals("a", tb.getArray()[0].getName());
assertEquals("b", tb.getArray()[1].getName());
}
示例13: rowFromResponse
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
private Object rowFromResponse(Object responseItem) {
BeanWrapper responseWrapper = new BeanWrapperImpl(responseItem);
BeanWrapper resultWrapper = new BeanWrapperImpl(proxyType);
for (Map.Entry<Field, Field> fieldEntry : fieldsMapping.entrySet()) {
Object valueFromResponse = responseWrapper.getPropertyValue(fieldEntry.getValue().getName());
Object resultProperty = converter.convertIfDifferentTypes(valueFromResponse, fieldEntry.getKey().getType());
resultWrapper.setPropertyValue(fieldEntry.getKey().getName(), resultProperty);
}
return resultWrapper.getWrappedInstance();
}
示例14: applyAcknowledgeMode
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
* This implementation maps {@code SESSION_TRANSACTED} onto an
* ActivationSpec property named "useRAManagedTransaction", if available
* (following ActiveMQ's naming conventions).
*/
@Override
protected void applyAcknowledgeMode(BeanWrapper bw, int ackMode) {
if (ackMode == Session.SESSION_TRANSACTED && bw.isWritableProperty("useRAManagedTransaction")) {
// ActiveMQ
bw.setPropertyValue("useRAManagedTransaction", "true");
}
else {
super.applyAcknowledgeMode(bw, ackMode);
}
}
示例15: createRequestObject
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Override
public Object createRequestObject(Object[] args) {
BeanWrapper requestWrapper = new BeanWrapperImpl(requestType);
BeanWrapper argumentWrapper = new BeanWrapperImpl(args[0]);
for (Map.Entry<Field, Field> fieldEntry : fieldsMapping.entrySet()) {
Object valueFromResponse = argumentWrapper.getPropertyValue(fieldEntry.getKey().getName());
Object resultProperty = converter.convertIfDifferentTypes(valueFromResponse, fieldEntry.getValue().getType());
requestWrapper.setPropertyValue(fieldEntry.getValue().getName(), resultProperty);
}
return requestWrapper.getWrappedInstance();
}