Example usage for org.apache.commons.beanutils.converters DateConverter DateConverter

List of usage examples for org.apache.commons.beanutils.converters DateConverter DateConverter

Introduction

In this page you can find the example usage for org.apache.commons.beanutils.converters DateConverter DateConverter.

Prototype

public DateConverter(Object defaultValue) 

Source Link

Document

Construct a java.util.Date Converter that returns a default value if an error occurs.

Usage

From source file:com.base2.kagura.rest.helpers.ParameterUtils.java

public static void SetupDateConverters() {
    DateTimeConverter dtConverter = new DateConverter(null);
    dtConverter.setPatterns(new String[] { "yyyy-MM-dd", "yyyy-MM-dd hh:mm:ss" });
    ConvertUtils.register(dtConverter, Date.class);
}

From source file:com.xidu.framework.common.util.Utils.java

public static List<?> convertDomainListToDtoList(List<?> origDomainList, Class<?> dtoClass) {
    if (null == origDomainList) {
        return null;
    }//ww  w.j  a  va 2 s. co m
    List<Object> convertedList = new ArrayList<Object>();
    for (Object orig : origDomainList) {
        Object dest;
        try {
            dest = dtoClass.newInstance();
            ConvertUtils.register(new DateConverter(null), Date.class);
            BeanUtils.copyProperties(dest, orig);
            convertedList.add(dest);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    return convertedList;
}

From source file:com.xidu.framework.common.util.Utils.java

public static List<?> convertDtoListToDomainList(List<?> origDtoList, Class<?> domainClass) {
    if (null == origDtoList) {
        return null;
    }//from w  ww  .  ja  v a2  s.com
    List<Object> convertedList = new ArrayList<Object>();
    for (Object orig : origDtoList) {
        Object dest;
        try {
            dest = domainClass.newInstance();
            ConvertUtils.register(new DateConverter(null), Date.class);
            BeanUtils.copyProperties(dest, orig);
            convertedList.add(dest);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    return convertedList;
}

From source file:com.xidu.framework.common.util.Utils.java

public static Object convertDomainToDto(Object origDomain, Class<?> dtoClass) {
    if (null == origDomain) {
        return null;
    }//w  ww.  java  2 s.  c  o  m
    Object dest = null;
    try {
        dest = dtoClass.newInstance();
        ConvertUtils.register(new DateConverter(null), Date.class);
        BeanUtils.copyProperties(dest, origDomain);

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return dest;
}

From source file:me.yyam.mongodbutils.MongoDbOperater.java

public <T> T findOneObj(String dbName, String sql, Class<T> clazz)
        throws JSQLParserException, InstantiationException, IllegalAccessException, InvocationTargetException {
    Map map = findOne(dbName, sql);
    if (map == null) {
        return null;
    }//w  ww .j a v  a2 s  . c  o m
    T obj = clazz.newInstance();
    ConvertUtils.register(new DateConverter(null), Date.class);
    BeanUtils.populate(obj, map);
    return obj;
}

From source file:com.xidu.framework.common.util.Utils.java

public static Object convertDtoToDomain(Object origDto, Class<?> domainClass) {
    if (null == origDto) {
        return null;
    }/*from   ww w .  j a  v  a  2s .  c  o  m*/
    Object dest = null;
    try {
        dest = domainClass.newInstance();
        ConvertUtils.register(new DateConverter(null), Date.class);
        BeanUtils.copyProperties(dest, origDto);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return dest;
}

From source file:com.xidu.framework.common.util.Utils.java

public static Object copyDomain(Object origDomain, Class<?> domainClass) {
    if (null == origDomain) {
        return null;
    }/*from w w w  . j  a  v a  2 s  .c  o  m*/
    Object dest = null;
    try {
        dest = domainClass.newInstance();
        ConvertUtils.register(new DateConverter(null), Date.class);
        BeanUtils.copyProperties(dest, origDomain);
    } catch (Exception e) {
        return null;
    }
    return dest;
}

From source file:me.yyam.mongodbutils.MongoDbOperater.java

public <T> T findOneObj(String dbName, String collName, Map queryMap, Class<T> clazz)
        throws InstantiationException, IllegalAccessException, InvocationTargetException {
    DB db = mongoClient.getDB(dbName);//from  ww w  . j  a  v a2s. c  om
    DBCollection coll = db.getCollection(collName);
    BasicDBObject query = new BasicDBObject(queryMap);
    DBObject map = coll.findOne(query);
    if (map == null) {
        return null;
    }
    T obj = clazz.newInstance();
    ConvertUtils.register(new DateConverter(null), Date.class);
    BeanUtils.populate(obj, map.toMap());
    return obj;
}

From source file:com.mmj.app.lucene.solr.client.SolrClient.java

public static Object toBean(SolrDocument record, Class<?> clazz) {

    Object o = null;/* ww w .ja  v  a2 s .co  m*/
    try {
        o = clazz.newInstance();
    } catch (InstantiationException e1) {
        e1.printStackTrace();
    } catch (IllegalAccessException e1) {
        e1.printStackTrace();
    }
    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        Object value = record.get(field.getName());
        ConvertUtils.register(new DateConverter(null), java.util.Date.class);
        try {
            BeanUtils.setProperty(o, field.getName(), value);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
    return o;
}

From source file:com.wineaccess.winepermit.WinePermitHelper.java

/**
 * @param wineModel/*from  w w  w  .  j ava  2 s  .c  o m*/
 */
private static void copyFulfilModelFromWinery(WineModel wineModel) {

    WineryLicenseFullfillAltStates wineryLicenseFullfillAltStates = WineryPermitRepository
            .findFulfilModelByWineryId(wineModel.getWineryId().getId());
    if (wineryLicenseFullfillAltStates != null) {
        WineLicenseFullfillAltStates wineLicenseFullfillAltStates = new WineLicenseFullfillAltStates();
        try {
            ConvertUtils.register(new DateConverter(null), Date.class);
            BeanUtils.copyProperties(wineLicenseFullfillAltStates, wineryLicenseFullfillAltStates);
            wineLicenseFullfillAltStates.setWineId(wineModel);
            WinePermitRepository.saveWineFulfilModel(wineLicenseFullfillAltStates);
        } catch (IllegalAccessException | InvocationTargetException e) {
            logger.info("Fulfill kodel couldn't be copied from winery");
            logger.error(e);
        }
    }

}