/** * Class-level synchronization to avoid potential thread-safety issues * with statically shared DatatypeFactory. */ @Mapping(from = Date.class, to = XMLGregorianCalendar.class) public static synchronized XMLGregorianCalendar map(Date date, XMLGregorianCalendar template) { GregorianCalendar calendar = template != null ? template.toGregorianCalendar() : new GregorianCalendar(); calendar.setTime(date); DatatypeFactory factory = getDatatypeFactory(); return factory != null ? factory.newXMLGregorianCalendar(calendar) : null; }
@Mapping(from = Integer.class, to = XMLGregorianCalendar.class) public static synchronized XMLGregorianCalendar map(BigDecimal secondsAgo, XMLGregorianCalendar template) { GregorianCalendar calendar = template != null ? template.toGregorianCalendar() : new GregorianCalendar(TimeZone.getTimeZone("UTC")); DatatypeFactory factory = getDatatypeFactory(); XMLGregorianCalendar ret = null; if (factory != null) { ret = factory.newXMLGregorianCalendar(calendar); ret.add(factory.newDuration(false, 0, 0, 0, 0, 0, secondsAgo.intValue())); } return ret; }