Example usage for org.apache.commons.beanutils PropertyUtils setProperty

List of usage examples for org.apache.commons.beanutils PropertyUtils setProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils setProperty.

Prototype

public static void setProperty(Object bean, String name, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

For more details see PropertyUtilsBean.

Usage

From source file:com.mycollab.db.persistence.service.DefaultCrudService.java

public Integer updateSelectiveWithSession(@CacheKey T record, String username) {
    try {//w  ww . j av a  2  s . com
        PropertyUtils.setProperty(record, "lastupdatedtime", new GregorianCalendar().getTime());
    } catch (Exception e) {
    }
    return getCrudMapper().updateByPrimaryKeySelective(record);
}

From source file:de.iritgo.aktario.jdbc.JDBCManager.java

/**
 * Initialize the <code>JDBCManager</code>.
 *
 * This method creates the data sources specified in the server
 * configuration.//from  www  .j  a v  a  2 s  . c  om
 */
public void init() {
    dataSources = new HashMap();

    try {
        Configuration config = Engine.instance().getConfiguration();

        for (DatasourceConfig datasourceConfig : config.getDataSources()) {
            DataSource ds = (DataSource) Class.forName(datasourceConfig.getDataSourceClass()).newInstance();

            if (PropertyUtils.isWriteable(ds, "driverClassName")) {
                PropertyUtils.setProperty(ds, "driverClassName", datasourceConfig.getDriverClass());
            }

            if (PropertyUtils.isWriteable(ds, "username")) {
                PropertyUtils.setProperty(ds, "username", datasourceConfig.getUser());
            }

            if (PropertyUtils.isWriteable(ds, "password")) {
                PropertyUtils.setProperty(ds, "password", datasourceConfig.getPassword());
            }

            if (PropertyUtils.isWriteable(ds, "url")) {
                PropertyUtils.setProperty(ds, "url", datasourceConfig.getUrl());
            }

            dataSources.put(datasourceConfig.getId(), ds);

            if (defaultDataSource == null) {
                defaultDataSource = ds;
            }

            Log.logInfo("persist", "JDBCManager", "Created datasource '" + datasourceConfig.getId() + "'");
        }

        JDBCIDGenerator persistentIdGenerator = new JDBCIDGenerator(2, 2, 1000);

        persistentIdGenerator.load();
        Engine.instance().installPersistentIDGenerator(persistentIdGenerator);

        DefaultIDGenerator transientIdGenerator = new DefaultIDGenerator((long) 1, (long) 2);

        Engine.instance().installTransientIDGenerator(transientIdGenerator);
    } catch (Exception x) {
        Log.logError("persist", "JDBCManager", "Error while creating the datasources: " + x);
    }

    Engine.instance().getEventRegistry().addListener("objectcreated", this);
    Engine.instance().getEventRegistry().addListener("objectmodified", this);
    Engine.instance().getEventRegistry().addListener("objectrequested", this);
    Engine.instance().getEventRegistry().addListener("objectremoved", this);
}

From source file:io.neocdtv.eclipselink.entitygraph.CopyPartialEntities.java

private void handleCollectionNode(final Object property, final Object newProperty,
        final Map<Class, Subgraph> subgraphs, final Object copyTo, final String attributeName)
        throws InvocationTargetException, IllegalAccessException, InstantiationException,
        NoSuchMethodException {//from   w  w  w. ja va2  s . c  o  m
    final Collection propertyAsCollection = (Collection) property;
    final Collection newPropertyAsCollection = (Collection) newProperty;
    for (Object elementFromCollection : propertyAsCollection) {
        final EntityGraphImpl subgraph = (EntityGraphImpl) subgraphs.get(elementFromCollection.getClass());
        final Object newElementForCollection = subgraph.getClassType().newInstance();
        newPropertyAsCollection.add(newElementForCollection);
        copyRecursive(elementFromCollection, newElementForCollection, subgraph);
    }
    PropertyUtils.setProperty(copyTo, attributeName, newPropertyAsCollection);
}

From source file:com.esofthead.mycollab.core.persistence.service.DefaultCrudService.java

public int updateSelectiveWithSession(@CacheKey T record, String username) {
    try {//from w  w w  .  ja  v a2  s . c  o  m
        PropertyUtils.setProperty(record, "lastupdatedtime", new GregorianCalendar().getTime());
    } catch (Exception e) {
    }
    return getCrudMapper().updateByPrimaryKeySelective(record);
}

From source file:hermes.browser.model.BeanTableModel.java

public void updateBean() throws InvocationTargetException, IllegalAccessException, IllegalAccessException,
        NoSuchMethodException {/*from   w  ww  .ja  v a 2 s  .c om*/
    for (Iterator iter = changes.keySet().iterator(); iter.hasNext();) {
        String key = (String) iter.next();
        Object value = changes.get(key);

        cat.debug("setting property=" + key + " value=" + value);

        PropertyUtils.setProperty(bean, key, value);
    }

    changes.clear();
}

From source file:fr.eoit.db.AbstractDTOPopulator.java

protected void initFieldProperty(E bean, Object obj, FieldDefinition fieldDefinition)
        throws PopulatorException {
    try {// www  . j  a  v  a 2 s.c  o m
        PropertyUtils.setProperty(bean, fieldDefinition.fieldName, obj);
    } catch (IllegalAccessException e) {
        throw new PopulatorException(e);
    } catch (InvocationTargetException e) {
        throw new PopulatorException(e);
    } catch (NoSuchMethodException e) {
        throw new PopulatorException(e);
    }
}

From source file:com.npower.dm.setup.task.ModelFamilyManager.java

/**
 * Copy family information into modelItem.
 * srcdestEmpty./*w  ww .  j av  a2  s  .c  o m*/
 * @param modelItem
 * @param familyItem
 * 
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 */
@SuppressWarnings("unchecked")
private void copy(Object src, Object dest)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    Map<String, ?> props = PropertyUtils.describe(dest);
    for (String name : props.keySet()) {
        Object value = PropertyUtils.getProperty(dest, name);
        try {
            if (value == null) {
                Object valueOfFamily = PropertyUtils.getProperty(src, name);
                PropertyUtils.setProperty(dest, name, valueOfFamily);
            } else if (value instanceof List) {
                if (((List<?>) value).size() == 0) {
                    Object valueOfFamily = PropertyUtils.getProperty(src, name);
                    PropertyUtils.setProperty(dest, name, valueOfFamily);
                }
            }
        } catch (NoSuchMethodException e) {

        }
    }
}

From source file:io.github.benas.easyproperties.PropertyInjector.java

private <A extends Annotation> void doInjectProperty(Field field, Object object, A annotation,
        AnnotationProcessor<A> annotationProcessor) throws PropertyInjectionException {
    try {//from   w w w.  j ava  2  s .c o m
        Object value = annotationProcessor.processAnnotation(annotation, field);
        if (value != null) {
            Object typedValue = ConvertUtils.convert(value, field.getType());
            PropertyUtils.setProperty(object, field.getName(), typedValue);
        }
    } catch (Exception e) {
        throw new PropertyInjectionException(
                format("Unable to inject value from annotation '%s' in field '%s' of object '%s'", annotation,
                        field.getName(), object),
                e);
    }
}

From source file:com.fengduo.bee.commons.util.StringFormatter.java

public static Object objectFieldEscape(Object ob) {
    Field[] fields = BeanUtils.getAllFields(null, ob.getClass());
    for (Field field : fields) {
        if (field == null || field.getName() == null || field.getType() == null) {
            continue;
        }/*  w  w w.  java2s.co  m*/
        if (StringUtils.equals("serialVersionUID", field.getName())) {
            continue;
        }
        if (!StringUtils.equals(field.getType().getSimpleName(), "String")) {
            continue;
        }
        try {
            Object fieldVal = PropertyUtils.getProperty(ob, field.getName());
            if (null == fieldVal) {
                continue;
            }
            field.setAccessible(true);
            String value = (String) fieldVal;
            PropertyUtils.setProperty(ob, field.getName(), StringEscapeUtils.escapeXml(value));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return ob;
}

From source file:com.github.richardwilly98.esdms.services.ParameterProvider.java

@Override
public Parameter setParameterValue(Parameter parameter, String name, Object value) throws ServiceException {
    checkNotNull(parameter);/*from   ww  w  .j  a  v  a  2  s. c o m*/
    checkNotNull(name);
    try {
        PropertyUtils.setProperty(parameter, name, value);
        return update(parameter);
    } catch (Exception ex) {
        log.error(String.format("setParameterValue %s - %s failed", parameter, name), ex);
        throw new ServiceException(ex.getLocalizedMessage());
    }
}