Example usage for org.springframework.beans BeanWrapper setPropertyValue

List of usage examples for org.springframework.beans BeanWrapper setPropertyValue

Introduction

In this page you can find the example usage for org.springframework.beans BeanWrapper setPropertyValue.

Prototype

void setPropertyValue(PropertyValue pv) throws BeansException;

Source Link

Document

Set the specified value as current property value.

Usage

From source file:org.jdal.util.BeanUtils.java

/**
 * Set property, without trowing exceptions on errors
 * @param bean bean name/*from  ww  w  . java2s . c  om*/
 * @param name name
 * @param value value
 */
public static void setProperty(Object bean, String name, Object value) {
    try {
        BeanWrapper wrapper = new BeanWrapperImpl(bean);
        wrapper.setPropertyValue(new PropertyValue(name, value));
    } catch (InvalidPropertyException ipe) {
        log.debug("Bean has no property: " + name);
    } catch (PropertyAccessException pae) {
        log.debug("Access Error on property: " + name);
    }
}

From source file:org.jdal.util.BeanUtils.java

/**
 * Copy a property, avoid Execeptions/*from  www.jav a2s.  c  o m*/
 * @param source source bean
 * @param dest destination bean
 * @param propertyName the propertyName
 * 
 */
public static void copyProperty(Object source, Object dest, String propertyName) {
    BeanWrapper wrapper = new BeanWrapperImpl(source);
    PropertyValue pv = new PropertyValue(propertyName, wrapper.getPropertyValue(propertyName));

    wrapper.setPropertyValue(pv);
}

From source file:org.jdbcluster.dao.Dao.java

/**
 * creates new instance of a Dao using given Dao class
 * @param daoClass class of Object to create
 * @return created dao instance//from   w  ww . j ava 2s  . com
 */
public static Object newInstance(Class<?> daoClass) {
    Object dao = JDBClusterUtil.createClassObject(daoClass);
    //get property of DAO and initial value from jdbcluster.dao.conf.xml
    HashMap<String, String> hm;
    synchronized (classToPropsMap) {
        hm = classToPropsMap.get(daoClass);
        if (hm == null)
            hm = putCacheMap(daoClass);
    }

    BeanWrapper beanWrapper = new BeanWrapperImpl();
    beanWrapper.setWrappedInstance(dao);

    for (String prop : hm.keySet()) {
        String value = hm.get(prop);
        //get property of DAO
        Class<?> propClass = beanWrapper.getPropertyType(prop);
        //convert to Type if necessary
        Object o = beanWrapper.convertIfNecessary(value, propClass);
        //set the value of the predefined property read from jdbcluster.dao.conf.xml
        beanWrapper.setPropertyValue(new PropertyValue(prop, o));
    }
    return dao;
}

From source file:org.brekka.stillingar.spring.pc.BeanPropertyChangeListener.java

/**
 * Handle the change by using reflection to change the bean property.
 *///from  w  ww  . j  a  va2s. c  o  m
@Override
public void onChange(String newValue) {
    BeanFactory beanFactory = beanFactoryRef.get();
    if (beanFactory == null) {
        return;
    }
    Object bean = beanFactory.getBean(beanName);
    BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean);
    beanWrapper.setPropertyValue(new PropertyValue(property, newValue));
}

From source file:de.extra.client.core.builder.impl.ExtraRequestBuilder.java

/**
 * Set Fields./* www .  j  av  a  2 s. c o m*/
 * 
 * @param parentXMLElement
 * @param childXmlElement
 * @param propertyName
 */
private void processField(final Object parentXMLElement, final Object childXmlElement,
        final String propertyName) {
    final BeanWrapper beanWrapper = new BeanWrapperImpl(parentXMLElement);
    final PropertyValue propertyValue = new PropertyValue(propertyName, childXmlElement);
    beanWrapper.setPropertyValue(propertyValue);
    LOG.debug("{}", parentXMLElement);
}