Example usage for javax.xml.datatype DatatypeConfigurationException toString

List of usage examples for javax.xml.datatype DatatypeConfigurationException toString

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeConfigurationException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:ca.phon.session.io.xml.v12.XMLSessionWriter_v12.java

/**
 * copy participant info// w w w  .  jav  a 2  s .  c o  m
 */
private ParticipantType copyParticipant(ObjectFactory factory, Participant part) {
    final ParticipantType retVal = factory.createParticipantType();

    if (part.getId() != null)
        retVal.setId(part.getId());

    retVal.setName(part.getName());

    final LocalDate bday = part.getBirthDate();
    if (bday != null) {
        try {
            final DatatypeFactory df = DatatypeFactory.newInstance();
            final XMLGregorianCalendar cal = df
                    .newXMLGregorianCalendar(GregorianCalendar.from(bday.atStartOfDay(ZoneId.systemDefault())));
            cal.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
            retVal.setBirthday(cal);
        } catch (DatatypeConfigurationException e) {
            LOGGER.log(Level.WARNING, e.toString(), e);
        }
    }

    final Period age = part.getAge(null);
    if (age != null) {
        try {
            final DatatypeFactory df = DatatypeFactory.newInstance();
            final Duration ageDuration = df.newDuration(true, age.getYears(), age.getMonths(), age.getDays(), 0,
                    0, 0);
            retVal.setAge(ageDuration);
        } catch (DatatypeConfigurationException e) {
            LOGGER.log(Level.WARNING, e.toString(), e);
        }
    }

    retVal.setEducation(part.getEducation());
    retVal.setGroup(part.getGroup());

    final String lang = part.getLanguage();
    final String langs[] = (lang != null ? lang.split(",") : new String[0]);
    for (String l : langs) {
        retVal.getLanguage().add(StringUtils.strip(l));
    }

    if (part.getSex() == Sex.MALE)
        retVal.setSex(SexType.MALE);
    else if (part.getSex() == Sex.FEMALE)
        retVal.setSex(SexType.FEMALE);

    ParticipantRole prole = part.getRole();
    if (prole == null)
        prole = ParticipantRole.TARGET_CHILD;
    retVal.setRole(prole.toString());

    // create ID based on role if possible
    if (retVal.getId() == null && prole != null) {
        if (prole == ParticipantRole.TARGET_CHILD) {
            retVal.setId("CHI");
        } else if (prole == ParticipantRole.MOTHER) {
            retVal.setId("MOT");
        } else if (prole == ParticipantRole.FATHER) {
            retVal.setId("FAT");
        } else if (prole == ParticipantRole.INTERVIEWER) {
            retVal.setId("INT");
        } else {
            retVal.setId("p" + (++pIdx));
        }
    }

    retVal.setSES(part.getSES());

    return retVal;
}

From source file:com.ccserver.digital.service.LOSService.java

private CommonType getCommonType(String messageId) {
    CommonType commonType = new CommonType();
    commonType.setServiceVersion(getConfiguration("LOS_SERVICE_VERSION", "1"));
    commonType.setMessageId(messageId);/*from ww w. j av a2  s.  co m*/
    commonType.setTransactionId(java.util.UUID.randomUUID().toString());

    try {
        GregorianCalendar gregory = new GregorianCalendar();
        gregory.setTime(new Date());
        XMLGregorianCalendar dealCloseDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregory);
        commonType.setMessageTimestamp(dealCloseDate);
    } catch (DatatypeConfigurationException e) {
        logger.error(Utils.getErrorFormatLog("LOSService", "getCommonType", "", e.toString()));
    }

    return commonType;
}

From source file:com.ccserver.digital.service.LOSService.java

private XMLGregorianCalendar dateToXMLGregorianCalendar(Date date) {
    if (date == null) {
        return null;
    }/*from   ww w  .  j  a v  a 2 s. co  m*/
    try {
        GregorianCalendar gregory = new GregorianCalendar();
        gregory.setTime(date);
        return DatatypeFactory.newInstance()
                .newXMLGregorianCalendarDate(gregory.get(Calendar.YEAR), gregory.get(Calendar.MONTH) + 1,
                        gregory.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED)
                .normalize();

    } catch (DatatypeConfigurationException e) {
        logger.error(Utils.getErrorFormatLog("LOSService", "dateToXMLGregorianCalendar", "",
                "Can not convert from LocalDateTime to XMLGregorianCalenda", e.toString()));

    }
    return null;
}