Example usage for org.apache.commons.beanutils.converters DateTimeConverter convert

List of usage examples for org.apache.commons.beanutils.converters DateTimeConverter convert

Introduction

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

Prototype

public Object convert(Class type, Object value) 

Source Link

Document

Convert the input object into an output object of the specified type.

Usage

From source file:com.xpfriend.fixture.cast.temp.TypeConverter.java

private static Object convert(DateTimeConverter converter, String format, String value, Class<?> type) {
    try {/*from   w  w  w.j  a  v  a2 s .co  m*/
        return converter.convert(type, value);
    } catch (ConversionException e) {
        converter.setPattern(format);
        return converter.convert(type, value);
    }
}

From source file:br.com.transport.report.ManagerReportBean.java

/**
 * //from ww  w  .  j a v  a  2  s  .c o m
 * @param mapReport
 * @return
 */
@SuppressWarnings("unchecked")
private List<ReportVO> executeQuery(Map<Long, List<Calendar>> mapReport) {

    List<ReportVO> handlerList = new LinkedList<ReportVO>();

    Query query = entityManager.createNativeQuery("SELECT F.DEPARTURE_DATE,F.DELIVERY_DATE,F.STATUS, "
            + "C.ID,C.CAPACITY,C.LICENSE_PLATE, C.MODEL " + "FROM CARRIER C " + "INNER JOIN FREIGHT F "
            + "ON C.ID = F.CARRIER_ID " + "WHERE F.STATUS IN ('ACCEPTED' ,'IN_PROGRESS') "
            + "AND F.DEPARTURE_DATE " + "BETWEEN :initialDate " + "AND :lastDate " + "ORDER BY C.ID ASC");

    query.setParameter("initialDate", dateFormat.format(getInitCalendar().getTime()));
    query.setParameter("lastDate", dateFormat.format(getLastCalendar().getTime()));

    List<Object[]> resultQuery = query.getResultList();

    /**
     * departureDate   [0]
     * deliveryDate     [1]
     * status           [2]
     * carrierId       [3]
     * capacity          [4]
     * licensePlate       [5]
     * model          [6]
     */

    DateTimeConverter timeConverter = new CalendarConverter();

    List<Calendar> calendars = createDayOfTheWeek();

    for (Object[] array : resultQuery) {

        mapReport.put(new Long(array[3].toString()), new LinkedList<Calendar>(calendars));

        Calendar deliveryDate = (Calendar) timeConverter.convert(Calendar.class, array[1]);
        Calendar departureDate = (Calendar) timeConverter.convert(Calendar.class, array[0]);

        handlerList.add(new ReportVO(departureDate.getTime(), deliveryDate.getTime(), array[2].toString(),
                new Long(array[3].toString()), new Double(array[4].toString()), array[5].toString(),
                array[6].toString(), null));
    }

    return handlerList;
}