class RegistrationDateAdapter extends XmlAdapter<String, XMLGregorianCalendar> {

    @Override
    public XMLGregorianCalendar unmarshal(String datetime) throws Exception
    {
        try
        {
            final DateTimeParser[] parsers =
                {
                    DateTimeFormat.forPattern("yyyy-MM-dd").getParser(),
                    DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm").getParser(),
                    DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mmZ").getParser(),
                    DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").getParser(),
                    DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").getParser(),
                    DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").getParser(),
                    DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ssZ").getParser()
                };

            DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();

            DateTime dateTime = dateTimeFormatter.withZoneUTC().parseDateTime(datetime.trim());

            return DatatypeFactory.newInstance().newXMLGregorianCalendar(dateTime.toGregorianCalendar());
        }
        catch (IllegalArgumentException e)
        {
            // Since the original exception carries an error message which gives away 'too much information', we are having it
            // swallowed and instead returning a generic error message.
            throw new IllegalArgumentException("Valid date or date and time format must be used when specifying values for start/end registration dates.");
        }
    }

}