Example usage for javax.xml.datatype XMLGregorianCalendar setTime

List of usage examples for javax.xml.datatype XMLGregorianCalendar setTime

Introduction

In this page you can find the example usage for javax.xml.datatype XMLGregorianCalendar setTime.

Prototype

public void setTime(int hour, int minute, int second) 

Source Link

Document

Set time as one unit.

Usage

From source file:ebay.dts.client.BulkDataExchangeActions.java

private static XMLGregorianCalendar parseDateTime(String cal) throws DatatypeConfigurationException {

    DatatypeFactory factory1 = DatatypeFactory.newInstance();
    XMLGregorianCalendar calendar1 = factory1.newXMLGregorianCalendar();
    String[] dateItems;/*from ww w . j  a  va2 s .  co  m*/
    try {
        // df.parse(cal);
        if (cal.indexOf("_") == -1) {
            dateItems = cal.split("-");
            calendar1.setYear(Integer.parseInt(dateItems[0]));
            calendar1.setMonth(Integer.parseInt(dateItems[1]));
            calendar1.setDay(Integer.parseInt(dateItems[2]));
            // calendar1.setTime(00, 00, 00,000);
            calendar1.setTime(00, 00, 00);
        } else {
            String[] parts = cal.split("_");
            dateItems = parts[0].split("-");
            String[] timeItems = parts[1].split(":");
            calendar1.setYear(Integer.parseInt(dateItems[0]));
            calendar1.setMonth(Integer.parseInt(dateItems[1]));
            calendar1.setDay(Integer.parseInt(dateItems[2]));
            if (timeItems.length != 0) {
                switch (timeItems.length) {
                case 1: {
                    calendar1.setTime(Integer.parseInt(timeItems[0]), 00, 00, 000);
                    break;
                }
                case 2: {
                    calendar1.setTime(Integer.parseInt(timeItems[0]), Integer.parseInt(timeItems[1]), 00, 000);
                    break;
                }
                case 3: {
                    calendar1.setTime(Integer.parseInt(timeItems[0]), Integer.parseInt(timeItems[1]),
                            Integer.parseInt(timeItems[2]), 000);
                    break;
                }
                case 4: {
                    calendar1.setTime(Integer.parseInt(timeItems[0]), Integer.parseInt(timeItems[1]),
                            Integer.parseInt(timeItems[2]), Integer.parseInt(timeItems[3]));
                    break;
                }
                }

            }
        }

        // get here and we know the format is correct
    } catch (java.lang.NumberFormatException e) {
        logger.error("NumberFormatException caught when parse the DateTime string: " + cal);
        return null;
    }

    calendar1.setTimezone(0);
    logger.debug(calendar1.toXMLFormat());
    return calendar1;
}

From source file:ro.bmocanu.tests.ws.springws.server.ProductServiceMarshallingPayloadEndpoint.java

@SuppressWarnings("restriction")
protected Object invokeInternal(Object request) throws Exception {
    ObjectFactory objectFactory = new ObjectFactory();

    GetProductByIdRequest gpbiRequest = (GetProductByIdRequest) request;
    long productId = gpbiRequest.getProductId();
    Product product = ProductManager.singleInstance.getProductById(productId);

    XMLGregorianCalendar cal = new com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl();
    Calendar c = Calendar.getInstance();
    cal.setTime(c.get(Calendar.HOUR), c.get(Calendar.MINUTE), c.get(Calendar.SECOND));

    GetProductByIdResponse gpbiResponse = objectFactory.createGetProductByIdResponse();

    ProductType xmlProduct = objectFactory.createProductType();
    xmlProduct.setId(product.getId());//from  w w  w  .j  a v  a  2 s.c  o  m
    xmlProduct.setName(product.getName());
    xmlProduct.setDescription(product.getDescription());
    xmlProduct.setReceived(cal);

    gpbiResponse.setProduct(xmlProduct);

    return gpbiResponse;
}