javax.xml.datatype.XMLGregorianCalendar Java Examples

The following examples show how to use javax.xml.datatype.XMLGregorianCalendar. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AssertionUtil.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Verify whether the assertion has expired. You can add in a clock skew to adapt to conditions where in the IDP and
 * SP are
 * out of sync.
 *
 * @param assertion
 * @param clockSkewInMilis in miliseconds
 *
 * @return
 *
 * @throws ConfigurationException
 */
public static boolean hasExpired(SAML11AssertionType assertion, long clockSkewInMilis) throws ConfigurationException {
    boolean expiry = false;

    // Check for validity of assertion
    SAML11ConditionsType conditionsType = assertion.getConditions();
    if (conditionsType != null) {
        XMLGregorianCalendar now = XMLTimeUtil.getIssueInstant();
        XMLGregorianCalendar notBefore = conditionsType.getNotBefore();
        XMLGregorianCalendar updatedNotBefore = XMLTimeUtil.subtract(notBefore, clockSkewInMilis);
        XMLGregorianCalendar notOnOrAfter = conditionsType.getNotOnOrAfter();
        XMLGregorianCalendar updatedOnOrAfter = XMLTimeUtil.add(notOnOrAfter, clockSkewInMilis);

        logger.trace("Now=" + now.toXMLFormat() + " ::notBefore=" + notBefore.toXMLFormat() + " ::notOnOrAfter=" + notOnOrAfter);

        expiry = !XMLTimeUtil.isValid(now, updatedNotBefore, updatedOnOrAfter);
        if (expiry) {
            logger.samlAssertionExpired(assertion.getID());
        }
    }

    // TODO: if conditions do not exist, assume the assertion to be everlasting?
    return expiry;
}
 
Example #2
Source File: SqlTimestampMarshall.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public Literal serialize(Timestamp object) {
	GregorianCalendar gc = new GregorianCalendar(0, 0, 0);
	gc.setTime(object);
	XMLGregorianCalendar xgc = factory.newXMLGregorianCalendar(gc);
	BigDecimal fraction = BigDecimal.valueOf(object.getNanos(), 9);
	xgc.setFractionalSecond(fraction);
	String label = xgc.toXMLFormat();
	return vf.createLiteral(label, datatype);
}
 
Example #3
Source File: SimpleCaptureDemo.java    From fosstrak-epcis with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns an XMLGregorianCalendar representing the current date and time
 */
protected static XMLGregorianCalendar getCurrentDateTime() {
	XMLGregorianCalendar now = null;
	try {
		DatatypeFactory dataFactory = DatatypeFactory.newInstance();
		now = dataFactory.newXMLGregorianCalendar(new GregorianCalendar());
	} catch (DatatypeConfigurationException e) {
		System.err.println("unable to construct the date/time object");
		e.printStackTrace();
	}
	return now;
}
 
Example #4
Source File: FoxmlUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
public static XMLGregorianCalendar createXmlDate(Date d) {
    try {
        DatatypeFactory xmlDataFactory = DatatypeFactory.newInstance();
        GregorianCalendar gcNow = new GregorianCalendar();
        gcNow.setTime(d);
        return xmlDataFactory.newXMLGregorianCalendar(gcNow);
    } catch (DatatypeConfigurationException ex) {
        throw new IllegalStateException(ex);
    }
}
 
Example #5
Source File: CalendarUtilTest.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
/**
 * Test AddMonths into winterTime.
 * Result should be moths +2 and a one hour shift to the left.
 *
 */
@Test
public void testAddMonthsIntoWinterTime() {
    XMLGregorianCalendar cal = calendarUtil.buildXMLGregorianCalendar();
    cal.setMonth(10);
    cal.setDay(1);
    cal.setHour(0);
    cal.setMinute(0);
    cal.setSecond(0);
    cal.setMillisecond(0);
    XMLGregorianCalendar result = calendarUtil.addMonths(cal, 2);
    assertEquals(12, result.getMonth());
}
 
Example #6
Source File: XMLGregorianCalendarImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Indicates whether parameter <code>obj</code> is "equal to" this one.</p>
 *
 * @param obj to compare.
 *
 * @return <code>true</code> when <code>compare(this,(XMLGregorianCalendar)obj) == EQUAL.</code>.
 */
public boolean equals(Object obj) {

    if (obj == null || !(obj instanceof XMLGregorianCalendar)) {
        return false;
    }
    return compare((XMLGregorianCalendar) obj) == DatatypeConstants.EQUAL;
}
 
Example #7
Source File: ConfigUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static XMLGregorianCalendar getSystemServicesVersionFromFile(File file) throws IntegrationModuleException {
   Object var1 = null;

   byte[] xml;
   try {
      xml = FileUtils.readFileToByteArray(file);
   } catch (IOException var3) {
      throw new IntegrationModuleException(I18nHelper.getLabel("error.get.system.services.failed"));
   }

   XMLGregorianCalendar version = null;
   version = getVersionNewXml(xml);
   return version;
}
 
Example #8
Source File: DefaultSignavioDateLib.java    From jdmn with Apache License 2.0 5 votes vote down vote up
public XMLGregorianCalendar dayAdd(XMLGregorianCalendar dateTime, BigDecimal daysToAdd) {
    XMLGregorianCalendar result = (XMLGregorianCalendar) dateTime.clone();
    int days = daysToAdd.intValue();
    boolean isPositive = days > 0;
    Duration duration;
    duration = DATA_TYPE_FACTORY.newDurationDayTime(
            isPositive, daysToAdd.abs().intValue(), 0, 0, 0);
    result.add(duration);
    return result;
}
 
Example #9
Source File: TestCloner.java    From jadira with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicWithPortable() throws DatatypeConfigurationException {

    GregorianCalendar cal = new GregorianCalendar();
    cal.add(Calendar.YEAR, 10);
    XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar((GregorianCalendar) cal);
    cal.add(Calendar.MONTH, 3);

    DeepCopyHolder source = new DeepCopyHolder();
    source.value = new IdHolder();
    source.value.setId("A Sample Value to Copy");
    source.timestamp = new Timestamp(System.currentTimeMillis() + 10000000);
    source.calendar = cal;
    source.xmlCalendar = xmlCal;

    BasicCloner cloner = new BasicCloner(new PortableCloneStrategy());
    cloner.initialiseFor(IdHolder.class);
    DeepCopyHolder dest = cloner.clone(source);
    
    Assert.assertEquals(source.value, dest.value);
    Assert.assertNotSame(source.value, dest.value);
    Assert.assertEquals(source.timestamp, dest.timestamp);
    Assert.assertNotSame(source.timestamp, dest.timestamp);
    Assert.assertEquals(source.calendar, dest.calendar);
    Assert.assertNotSame(source.calendar, dest.calendar);
    Assert.assertEquals(source.xmlCalendar, dest.xmlCalendar);
    Assert.assertNotSame(source.xmlCalendar, dest.xmlCalendar);
}
 
Example #10
Source File: AbstractIntegrationModule.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public XMLGregorianCalendar getCurrentXMLGregorianCalendar() {
    XMLGregorianCalendar xgcal = null;
    try {
        GregorianCalendar gcal = new GregorianCalendar();
        gcal.setTimeInMillis(System.currentTimeMillis());
        xgcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal);
    } catch (DatatypeConfigurationException ex) {
        LOG.error("Error creating a xml gregorian calendat!! ", ex);
    }
    return xgcal;
}
 
Example #11
Source File: MedicationSchemeTimestampsResponse.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public XMLGregorianCalendar getCurrentDateTime() {
   return this.currentDateTime;
}
 
Example #12
Source File: XMLGregorianCalendarImpl.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 *
 *  <p>Implements Step B from http://www.w3.org/TR/xmlschema-2/#dateTime-order </p>
 * @param P calendar instance with normalized timezone offset or
 *          having same timezone as Q
 * @param Q calendar instance with normalized timezone offset or
 *          having same timezone as P
 *
 * @return result of comparing P and Q, value of
 *   {@link DatatypeConstants#EQUAL},
 *   {@link DatatypeConstants#LESSER},
 *   {@link DatatypeConstants#GREATER} or
 *   {@link DatatypeConstants#INDETERMINATE}.
 */
private static int internalCompare(XMLGregorianCalendar P,
                                   XMLGregorianCalendar Q) {

    int result;

    // compare Year.
    if (P.getEon() == Q.getEon()) {

        // Eon field is only equal when null.
        // optimized case for comparing year not requiring eon field.
        result = compareField(P.getYear(), Q.getYear());
        if (result != DatatypeConstants.EQUAL) {
            return result;
        }
    } else {
        result = compareField(P.getEonAndYear(), Q.getEonAndYear());
        if (result != DatatypeConstants.EQUAL) {
            return result;
        }
    }

    result = compareField(P.getMonth(), Q.getMonth());
    if (result != DatatypeConstants.EQUAL) {
        return result;
    }

    result = compareField(P.getDay(), Q.getDay());
    if (result != DatatypeConstants.EQUAL) {
        return result;
    }

    result = compareField(P.getHour(), Q.getHour());
    if (result != DatatypeConstants.EQUAL) {
        return result;
    }

    result = compareField(P.getMinute(), Q.getMinute());
    if (result != DatatypeConstants.EQUAL) {
        return result;
    }
    result = compareField(P.getSecond(), Q.getSecond());
    if (result != DatatypeConstants.EQUAL) {
        return result;
    }

    result = compareField(P.getFractionalSecond(), Q.getFractionalSecond());
    return result;
}
 
Example #13
Source File: DateTimeDV.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) {
    return datatypeFactory.newXMLGregorianCalendar(BigInteger.valueOf(date.unNormYear), date.unNormMonth,
            date.unNormDay, date.unNormHour, date.unNormMinute,
            (int)date.unNormSecond, date.unNormSecond != 0 ? getFractionalSecondsAsBigDecimal(date) : null,
            date.hasTimeZone() ? (date.timezoneHr * 60 + date.timezoneMin) : DatatypeConstants.FIELD_UNDEFINED);
}
 
Example #14
Source File: ObjectUtilTest.java    From ldp4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testXMLGregorianCalendarSupport() throws Exception {
	verifyTypeSupport(javax.xml.datatype.XMLGregorianCalendar.class);
}
 
Example #15
Source File: SimpleFeatureVersionFilter.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
public XMLGregorianCalendar getStartDate() {
    return startDate;
}
 
Example #16
Source File: AbstractXMLGregorianCalendarAdapter.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setMinute(Calendar source, XMLGregorianCalendar target) {
	target.setMinute(source.get(Calendar.MINUTE));
}
 
Example #17
Source File: DateDV.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) {
    return datatypeFactory.newXMLGregorianCalendar(date.unNormYear, date.unNormMonth,
            date.unNormDay, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED,
            DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED,
            date.hasTimeZone() ? (date.timezoneHr * 60 + date.timezoneMin) : DatatypeConstants.FIELD_UNDEFINED);
}
 
Example #18
Source File: XMLGregorianCalendarMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public Literal serialize(XMLGregorianCalendar object) {
	return vf.createLiteral(object);
}
 
Example #19
Source File: MessageInformation.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setDateTime(XMLGregorianCalendar value) {
   this.dateTime = value;
}
 
Example #20
Source File: DeliveredMedicationHumanType.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setDeliveryDate(XMLGregorianCalendar value) {
   this.deliveryDate = value;
}
 
Example #21
Source File: ListTypes.java    From caravan with Apache License 2.0 4 votes vote down vote up
public void setDateTimeType(List<XMLGregorianCalendar> value) {
    this.dateTimeType = value;
}
 
Example #22
Source File: MedicationSchemeTimestampsResponse.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setLastUpdated(XMLGregorianCalendar value) {
   this.lastUpdated = value;
}
 
Example #23
Source File: CareReceiverType.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setDeceased(XMLGregorianCalendar value) {
   this.deceased = value;
}
 
Example #24
Source File: InsurabilityForPharmacistResponseType.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setRequested(XMLGregorianCalendar value) {
   this.requested = value;
}
 
Example #25
Source File: DefaultDateTimeType.java    From jdmn with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean dateTimeGreaterThan(XMLGregorianCalendar first, XMLGregorianCalendar second) {
    return xmlCalendarGreaterThan(first, second);
}
 
Example #26
Source File: MedicationSchemeTimestampsResponse.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public XMLGregorianCalendar getLastUpdated() {
   return this.lastUpdated;
}
 
Example #27
Source File: CalendarUtil.java    From hsac-fitnesse-fixtures with Apache License 2.0 3 votes vote down vote up
/**
 * Add Days to a Gregorian Calendar.
 * 
 * @param cal The XMLGregorianCalendar source
 * @param amount The amount of days. Can be a negative Integer to substract.
 * @return A XMLGregorianCalendar with the new Date
 */
public XMLGregorianCalendar addDays(final XMLGregorianCalendar cal, final int amount) {
    XMLGregorianCalendar to = buildXMLGregorianCalendarDate(cal);
    // Add amount of months
    to.add(addDays(amount));
    return to;
}
 
Example #28
Source File: DateToXMLGregorianCalendar.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void convert_date_to_XMLGregorianCalendar()
		throws DatatypeConfigurationException {

	GregorianCalendar gCalendar = new GregorianCalendar();

	XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory
			.newInstance().newXMLGregorianCalendar(gCalendar);

	logger.info(xmlGregorianCalendar);

	assertNotNull(xmlGregorianCalendar);
}
 
Example #29
Source File: InsuranceType.java    From icure-backend with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets the value of the enddate property.
 * 
 * @return
 *     possible object is
 *     {@link XMLGregorianCalendar }
 *     
 */
public XMLGregorianCalendar getEnddate() {
    return enddate;
}
 
Example #30
Source File: RemoveDmppType.java    From icure-backend with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets the value of the to property.
 *
 * @return
 *     possible object is
 *     {@link XMLGregorianCalendar }
 *
 */
public XMLGregorianCalendar getTo() {
    return to;
}