/** * Return a calendar with the timezone field set, to be used for order comparison. If the original * calendar did not specify a timezone, set the local timezone (unadjusted for daylight savings). * The returned calendars will be totally ordered between themselves. We also set any missing * fields to ensure that normalization doesn't discard important data! (This is probably a bug in * the JAXP implementation, but the workaround doesn't hurt us, so it's faster to just fix it * here.) * * @return the calendar represented by this object, with the timezone field filled in with an * implicit value if necessary */ protected XMLGregorianCalendar getImplicitCalendar() { if (implicitCalendar == null) { implicitCalendar = (XMLGregorianCalendar) calendar.clone(); if (calendar.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) { implicitCalendar.setTimezone(TimeUtils.getInstance().getLocalTimezoneOffsetMinutes()); } // fill in fields from default reference; don't have to worry about weird combinations of // fields being set, since we control that on creation switch (getType()) { case Type.DATE: implicitCalendar.setTime(0, 0, 0); break; case Type.TIME: implicitCalendar.setYear(1972); implicitCalendar.setMonth(12); implicitCalendar.setDay(31); break; default: } implicitCalendar = implicitCalendar .normalize(); // the comparison routines will normalize it anyway, just do it once // here } return implicitCalendar; }
private static XMLGregorianCalendar stripCalendar(XMLGregorianCalendar calendar) { calendar = (XMLGregorianCalendar) calendar.clone(); calendar.setYear(DatatypeConstants.FIELD_UNDEFINED); calendar.setMonth(DatatypeConstants.FIELD_UNDEFINED); calendar.setHour(DatatypeConstants.FIELD_UNDEFINED); calendar.setMinute(DatatypeConstants.FIELD_UNDEFINED); calendar.setSecond(DatatypeConstants.FIELD_UNDEFINED); calendar.setMillisecond(DatatypeConstants.FIELD_UNDEFINED); return calendar; }
public static String createSamplePayload() throws Exception { JAXBContext jaxbContext = JAXBContext.newInstance("pl.edu.agh.security.delivery.pojos"); Marshaller marshaller = jaxbContext.createMarshaller(); ObjectFactory objectFactory = new ObjectFactory(); DeliveryRequest deliveryRequest = objectFactory.createDeliveryRequest(); XMLGregorianCalendar xgc = DatatypeFactory.newInstance().newXMLGregorianCalendar(); xgc.setYear(2013); xgc.setMonth(DatatypeConstants.JUNE); xgc.setDay(2); xgc.setTime(15, 10, 1); deliveryRequest.setCompletionDateTime(xgc); deliveryRequest.setPriority(Priority.TOP); deliveryRequest.setRecipientAddress("Springfield 123"); deliveryRequest.setRecipientName("Homer Simpson"); deliveryRequest.setSenderAddress("Southpark 456"); deliveryRequest.setSenderName("Eric Cartman"); deliveryRequest.setWeight(BigDecimal.TEN); StringWriter sw = new StringWriter(); marshaller.marshal(objectFactory.createDeliveryRequest(deliveryRequest), sw); return sw.toString(); }
public void setMonth(int month) { calendar.setMonth(month); }