Java Code Examples for javax.xml.datatype.DatatypeConfigurationException

The following are top voted examples for showing how to use javax.xml.datatype.DatatypeConfigurationException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: oscm   File: ResellerShareResultAssembler.java   View source code 10 votes vote down vote up
private Period preparePeriod(long periodStartTime, long periodEndTime)
        throws DatatypeConfigurationException {

    Period period = new Period();

    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gc = new GregorianCalendar();

    // start date
    period.setStartDate(BigInteger.valueOf(periodStartTime));
    gc.setTimeInMillis(periodStartTime);
    period.setStartDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    // end date
    period.setEndDate(BigInteger.valueOf(periodEndTime));
    gc.setTimeInMillis(periodEndTime);
    period.setEndDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    return period;
}
 
Example 2
Project: FHIR-CQL-ODM-service   File: FhirService.java   View source code 7 votes vote down vote up
private XMLGregorianCalendar getXMLGregorianCalendarNow()
		throws DatatypeConfigurationException {
	GregorianCalendar gregorianCalendar = new GregorianCalendar();
	DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
	XMLGregorianCalendar now = datatypeFactory
			.newXMLGregorianCalendar(gregorianCalendar);
	return now;
}
 
Example 3
Project: FHIR-CQL-ODM-service   File: FhirService.java   View source code 6 votes vote down vote up
private ODM createODM(Map<String, Object> results, Integer project_id,
		Integer event_id, String instrument, String patientId)
		throws JAXBException, DatatypeConfigurationException {
	// List<ODMcomplexTypeDefinitionItemData> items =
	// OdmUtil.getOdmItems(studyODM);

	ODM studyODM = createOdmTemplate(project_id, event_id, instrument,
			patientId);
	List<ODMcomplexTypeDefinitionItemData> items = OdmUtil
			.getOdmGroupData(studyODM);
	for (String key : results.keySet()) {
		if (results.get(key) != null) { // do not add to response if null
			ODMcomplexTypeDefinitionItemData item = new ODMcomplexTypeDefinitionItemData();
			item.setItemOID(key);
			item.setValue(results.get(key).toString());
			items.add(item);
		}
	}

	return studyODM;
}
 
Example 4
Project: openjdk-jdk10   File: DurationTest.java   View source code 6 votes vote down vote up
@Test
public void testDurationMultiply() {
    int num = 5000; // millisends. 5 seconds
    int factor = 2;
    try {
        Duration dur = DatatypeFactory.newInstance().newDuration(num);
        if (dur.multiply(factor).getSeconds() != 10) {
            Assert.fail("duration.multiply() return wrong value");
        }
        // factor is 2*10^(-1)
        if (dur.multiply(new BigDecimal(new BigInteger("2"), 1)).getSeconds() != 1) {
            Assert.fail("duration.multiply() return wrong value");
        }
        if (dur.subtract(DatatypeFactory.newInstance().newDuration(1000)).multiply(new BigDecimal(new BigInteger("2"), 1)).getSeconds() != 0) {
            Assert.fail("duration.multiply() return wrong value");
        }
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 5
Project: stroom-stats   File: TestValueStatToAggregateFlatMapper.java   View source code 6 votes vote down vote up
private Statistics.Statistic buildStatistic() throws DatatypeConfigurationException {

        //use system time as class under test has logic based on system time
        ZonedDateTime time = ZonedDateTime.now(ZoneOffset.UTC);

        Statistics.Statistic statistic = StatisticsHelper.buildValueStatistic(
                time,
                10.5,
                StatisticsHelper.buildTagType(tag1, tag1val1),
                StatisticsHelper.buildTagType(tag2, tag2val1)
        );
        StatisticsHelper.addIdentifier(statistic, id1part1, id1part2);
        StatisticsHelper.addIdentifier(statistic, id2part1, id2part2);

        return statistic;
    }
 
Example 6
Project: stroom-stats   File: TestCountStatToAggregateFlatMapper.java   View source code 6 votes vote down vote up
private Statistics.Statistic buildStatistic() throws DatatypeConfigurationException {

        //use system time as class under test has logic based on system time
        ZonedDateTime time = ZonedDateTime.now(ZoneOffset.UTC);

        Statistics.Statistic statistic = StatisticsHelper.buildCountStatistic(
                time,
                10L,
                StatisticsHelper.buildTagType(tag1, tag1val1),
                StatisticsHelper.buildTagType(tag2, tag2val1)
        );
        StatisticsHelper.addIdentifier(statistic, id1part1, id1part2);
        StatisticsHelper.addIdentifier(statistic, id2part1, id2part2);

        return statistic;
    }
 
Example 7
Project: openjdk-jdk10   File: DurationTest.java   View source code 6 votes vote down vote up
@Test
public void testDurationAndCalendar3() {
    try {
        Calendar cal = new GregorianCalendar();
        cal.set(Calendar.SECOND, 59);
        DatatypeFactory.newInstance().newDuration(10000).addTo(cal);
        AssertJUnit.assertTrue("sec will be 9", cal.get(Calendar.SECOND) == 9);

        Date date = new Date();
        date.setSeconds(59);
        DatatypeFactory.newInstance().newDuration(10000).addTo(date);
        AssertJUnit.assertTrue("sec will be 9", date.getSeconds() == 9);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 8
Project: oscm   File: GregorianCalendars.java   View source code 6 votes vote down vote up
/**
 * 
 * @return An object of type XMLGregorianCalendar containing the current
 *         system time and date
 * @throws DatatypeConfigurationException
 *             If the instantiation of the DatatypeFactory fails
 */
public static XMLGregorianCalendar newXMLGregorianCalendarSystemTime()
        throws DatatypeConfigurationException {
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    XMLGregorianCalendar now = datatypeFactory
            .newXMLGregorianCalendar(gregorianCalendar);
    return now;
}
 
Example 9
Project: openjdk-jdk10   File: Bug6925410Test.java   View source code 6 votes vote down vote up
@Test
public void test() throws DatatypeConfigurationException {
    try {
        int times = 100;
        long start = System.currentTimeMillis();
        for (int i = 0; i < times; i++) {
            XMLReaderFactory.createXMLReader();
        }
        long end = System.currentTimeMillis();
        double speed = ((end - start));
        System.out.println(speed + "ms");
    } catch (Throwable e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }

}
 
Example 10
Project: oscm   File: BrokerShareResultAssembler.java   View source code 6 votes vote down vote up
void setPeriod(long periodStartTime, long periodEndTime)
        throws DatatypeConfigurationException {
    this.periodEndTime = periodEndTime;

    Period period = new Period();

    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gc = new GregorianCalendar();

    // start date
    period.setStartDate(BigInteger.valueOf(periodStartTime));
    gc.setTimeInMillis(periodStartTime);
    period.setStartDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    // end date
    period.setEndDate(BigInteger.valueOf(periodEndTime));
    gc.setTimeInMillis(periodEndTime);
    period.setEndDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    result.setPeriod(period);
}
 
Example 11
Project: oscm   File: ResellerShareResultAssembler.java   View source code 6 votes vote down vote up
public ResellerRevenueShareResult build(Long resellerKey,
        long periodStartTime, long periodEndTime)
        throws DatatypeConfigurationException {
    Invariants.assertNotNull(resellerKey);

    result = new ResellerRevenueShareResult();
    setOrganizationData(resellerKey);
    setResellerData(resellerKey);
    setPeriod(periodStartTime, periodEndTime);

    List<BillingResult> billingResults = sharesRetrievalService
            .loadBillingResultsForReseller(resellerKey, periodStartTime,
                    periodEndTime);
    for (BillingResult billingResult : billingResults) {
        currentBillingResult = billingResult;
        xmlSearch = newXmlSearch(currentBillingResult);
        addCurrency();
    }
    return result;
}
 
Example 12
Project: oscm   File: ResellerShareResultAssembler.java   View source code 6 votes vote down vote up
private void addService(Supplier supplier, long subscriptionKey)
        throws DatatypeConfigurationException {
    Set<Long> priceModelKeys = xmlSearch.findPriceModelKeys();
    for (Iterator<Long> iterator = priceModelKeys.iterator(); iterator
            .hasNext();) {
        pmKey = iterator.next();

        ProductHistory productHistory = sharesRetrievalService
                .loadProductOfVendor(subscriptionKey, pmKey, periodEndTime);
        Service service = supplier.getServiceByKey(productHistory
                .getObjKey());
        if (service == null) {
            service = buildService(productHistory);
            supplier.addService(service);
        }

        addSubscription(service, subscriptionKey);
        setServiceRevenue(service.getServiceRevenue());
        addServiceCustomerRevenue(service, subscriptionKey);
    }
}
 
Example 13
Project: oscm   File: ResellerShareResultAssembler.java   View source code 6 votes vote down vote up
private Subscription buildSubscription(long subscriptionKey)
        throws DatatypeConfigurationException {
    SubscriptionHistory subscriptionHistory = sharesRetrievalService
            .loadSubscriptionHistoryWithinPeriod(subscriptionKey,
                    periodEndTime);

    Subscription subscription = new Subscription();
    subscription.setKey(BigInteger.valueOf(subscriptionKey));
    subscription.setId(subscriptionHistory.getDataContainer()
            .getSubscriptionId());
    subscription.setBillingKey(BigInteger.valueOf(currentBillingResult
            .getKey()));
    subscription.setRevenue(currentBillingResult.getNetAmount());
    Period period = preparePeriod(
            this.currentBillingResult.getPeriodStartTime(),
            this.currentBillingResult.getPeriodEndTime());
    subscription.setPeriod(period);
    return subscription;
}
 
Example 14
Project: oscm   File: MpOwnerShareResultAssembler.java   View source code 6 votes vote down vote up
void setPeriod(long periodStartTime, long periodEndTime)
        throws DatatypeConfigurationException {

    this.periodStartTime = periodStartTime;
    this.periodEndTime = periodEndTime;

    Period period = new Period();

    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gc = new GregorianCalendar();

    // start date
    period.setStartDate(BigInteger.valueOf(periodStartTime));
    gc.setTimeInMillis(periodStartTime);
    period.setStartDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    // end date
    period.setEndDate(BigInteger.valueOf(periodEndTime));
    gc.setTimeInMillis(periodEndTime);
    period.setEndDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    result.setPeriod(period);
}
 
Example 15
Project: oscm   File: SupplierShareResultAssembler.java   View source code 6 votes vote down vote up
/**
 * Iterates over all billing results.<br />
 * 
 * Shares are extracted price model by price model and are based on net
 * values.
 * 
 * @param supplierKey
 *            valid key of a supplier organization
 * @param periodStartTime
 *            start of a calendar month is expected
 * @param periodEndTime
 *            end of a calendar month is expected
 */
public SupplierRevenueShareResult build(Long supplierKey,
        long periodStartTime, long periodEndTime)
        throws DatatypeConfigurationException {

    Invariants.assertNotNull(supplierKey);

    result = new SupplierRevenueShareResult();
    OrganizationHistory org = billingRetrievalService
            .loadLastOrganizationHistory(supplierKey);
    result.setOrganizationData(buildOrganizationData(org));
    setSupplierData(supplierKey);
    setPeriod(periodStartTime, periodEndTime);

    List<BillingResult> billingResults = billingRetrievalService
            .loadBillingResultsForSupplier(supplierKey, periodStartTime,
                    periodEndTime);
    for (BillingResult billingResult : billingResults) {
        currentBillingResult = billingResult;
        xmlSearch = newXmlSearch(currentBillingResult);
        addCurrency();
    }
    return result;
}
 
Example 16
Project: oscm   File: SupplierShareResultAssembler.java   View source code 6 votes vote down vote up
private Period preparePeriod(long periodStartTime, long periodEndTime)
        throws DatatypeConfigurationException {

    Period period = new Period();

    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gc = new GregorianCalendar();

    period.setStartDate(BigInteger.valueOf(periodStartTime));
    gc.setTimeInMillis(periodStartTime);
    period.setStartDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    period.setEndDate(BigInteger.valueOf(periodEndTime));
    gc.setTimeInMillis(periodEndTime);
    period.setEndDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    return period;
}
 
Example 17
Project: oscm   File: SupplierShareResultAssembler.java   View source code 6 votes vote down vote up
private void addMarketplace(Currency currency)
        throws DatatypeConfigurationException {
    long subscriptionKey = currentBillingResult.getSubscriptionKey()
            .longValue();
    MarketplaceHistory marketplaceHistory = billingRetrievalService
            .loadMarketplaceHistoryBySubscriptionKey(subscriptionKey,
                    periodEndTime);
    Marketplace marketplace = currency.getMarketplace(marketplaceHistory
            .getObjKey());
    if (marketplace == null) {
        marketplace = buildMarketplace(marketplaceHistory);
        currency.addMarketplace(marketplace);
    }

    addService(marketplace, subscriptionKey);
}
 
Example 18
Project: oscm   File: SupplierShareResultAssembler.java   View source code 6 votes vote down vote up
private void addService(Marketplace marketplace, long subscriptionKey)
        throws DatatypeConfigurationException {

    Set<Long> priceModelKeys = xmlSearch.findPriceModelKeys();
    for (Iterator<Long> iterator = priceModelKeys.iterator(); iterator
            .hasNext();) {
        pmKey = iterator.next();
        ProductHistory prd = billingRetrievalService.loadProductOfVendor(
                subscriptionKey, pmKey, periodEndTime);
        Service service = marketplace.getServiceByKey(prd.getObjKey());
        if (service == null) {
            service = buildService(marketplace, prd);
            marketplace.addService(service);
        }
        addSubscription(service, subscriptionKey);
        addServiceCustomerRevenue(service, subscriptionKey);
    }
}
 
Example 19
Project: oscm   File: SupplierShareResultAssembler.java   View source code 6 votes vote down vote up
private void addSubscription(Service service, long subscriptionKey)
        throws DatatypeConfigurationException {
    BigDecimal serviceRevenue = DiscountCalculator.calculateServiceRevenue(
            xmlSearch, pmKey);
    if (service.getModel().equals(OfferingType.RESELLER.name())) {
        SubscriptionsRevenue revenue = service
                .retrieveSubscriptionsRevenue();
        revenue.sumUp(serviceRevenue);
    } else {
        Subscription subscription = service
                .getSubscriptionByKey(subscriptionKey);
        if (subscription != null) {
            // Billing result contains multiple price models for the same
            // service.This may occur if a subscription is upgraded to a new
            // service and downgraded again to the original service in the
            // same billing period.
            subscription.sumUpRevenue(serviceRevenue);
        } else {
            subscription = buildSubscription(subscriptionKey,
                    serviceRevenue);
            service.addSubscription(subscription);
        }
    }
}
 
Example 20
Project: oscm   File: SupplierShareResultAssembler.java   View source code 6 votes vote down vote up
private Subscription buildSubscription(long subscriptionKey,
        BigDecimal serviceRevenue) throws DatatypeConfigurationException {

    SubscriptionHistory subscriptionHistory = billingRetrievalService
            .loadSubscriptionHistoryWithinPeriod(subscriptionKey,
                    periodEndTime);

    Subscription subscription = new Subscription();
    subscription.setKey(BigInteger.valueOf(subscriptionKey));
    subscription.setId(subscriptionHistory.getDataContainer()
            .getSubscriptionId());
    subscription.setBillingKey(BigInteger.valueOf(currentBillingResult
            .getKey()));
    subscription.setRevenue(serviceRevenue);
    Period period = preparePeriod(
            this.currentBillingResult.getPeriodStartTime(),
            this.currentBillingResult.getPeriodEndTime());
    subscription.setPeriod(period);
    return subscription;
}
 
Example 21
Project: oscm   File: AuthnRequestGenerator.java   View source code 6 votes vote down vote up
public JAXBElement<AuthnRequestType> generateAuthnRequest()
        throws DatatypeConfigurationException {

    org.oscm.saml2.api.model.protocol.ObjectFactory protocolObjFactory;
    protocolObjFactory = new org.oscm.saml2.api.model.protocol.ObjectFactory();
    org.oscm.saml2.api.model.assertion.ObjectFactory assertionObjFactory;
    assertionObjFactory = new org.oscm.saml2.api.model.assertion.ObjectFactory();

    NameIDType issuer = assertionObjFactory.createNameIDType();
    issuer.setValue(this.issuer);

    AuthnRequestType authnRequest = protocolObjFactory
            .createAuthnRequestType();
    authnRequest.setID(requestId);
    authnRequest.setVersion("2.0");
    authnRequest.setIssueInstant(GregorianCalendars
            .newXMLGregorianCalendarSystemTime());
    Integer acsIndex = isHttps.booleanValue() ? HTTPS_INDEX : HTTP_INDEX;
    authnRequest.setAssertionConsumerServiceIndex(acsIndex);
    authnRequest.setIssuer(issuer);

    JAXBElement<AuthnRequestType> authnRequestJAXB = protocolObjFactory
            .createAuthnRequest(authnRequest);

    return authnRequestJAXB;
}
 
Example 22
Project: OpenJSharp   File: DatatypeConverterImpl.java   View source code 6 votes vote down vote up
public static DatatypeFactory getDatatypeFactory() {
    ClassLoader tccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        public ClassLoader run() {
            return Thread.currentThread().getContextClassLoader();
        }
    });
    DatatypeFactory df = DF_CACHE.get(tccl);
    if (df == null) {
        synchronized (DatatypeConverterImpl.class) {
            df = DF_CACHE.get(tccl);
            if (df == null) { // to prevent multiple initialization
                try {
                    df = DatatypeFactory.newInstance();
                } catch (DatatypeConfigurationException e) {
                    throw new Error(Messages.FAILED_TO_INITIALE_DATATYPE_FACTORY.format(),e);
                }
                DF_CACHE.put(tccl, df);
            }
        }
    }
    return df;
}
 
Example 23
Project: OperatieBRP   File: VrijBerichtClientServiceImpl.java   View source code 6 votes vote down vote up
private void vulStuurgegevens(final VrijBericht vrijBericht, final VrijBerichtStuurVrijBericht verzoek, final PartijCode zendendePartij)
        throws DatatypeConfigurationException {
    final GroepBerichtStuurgegevens stuurgegevens = objectFactory.createGroepBerichtStuurgegevens();
    stuurgegevens.setCommunicatieID(UUID.randomUUID().toString());
    final SysteemNaam zendendeSysteem = new SysteemNaam();
    final Referentienummer referentieNummer = new Referentienummer();
    final DatumTijd tijdstipVerzending = new DatumTijd();
    zendendeSysteem.setValue("BRP");
    referentieNummer.setValue(UUID.randomUUID().toString());
    final GregorianCalendar c = new GregorianCalendar();
    final XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    c.setTime(vrijBericht.getTijdstipRegistratie());
    tijdstipVerzending.setValue(xmlDate);
    stuurgegevens.setZendendePartij(objectFactory.createGroepBerichtStuurgegevensZendendePartij(zendendePartij));
    stuurgegevens.setZendendeSysteem(objectFactory.createGroepBerichtStuurgegevensZendendeSysteem(zendendeSysteem));
    stuurgegevens.setReferentienummer(objectFactory.createGroepBerichtStuurgegevensReferentienummer(referentieNummer));
    stuurgegevens.setTijdstipVerzending(objectFactory.createGroepBerichtStuurgegevensTijdstipVerzending(tijdstipVerzending));
    verzoek.setStuurgegevens(objectFactory.createObjecttypeBerichtStuurgegevens(stuurgegevens));
}
 
Example 24
Project: jdk8u-jdk   File: TestXMLGregorianCalendarTimeZone.java   View source code 6 votes vote down vote up
private static void test(int offsetMinutes)
        throws DatatypeConfigurationException {
    XMLGregorianCalendar calendar = DatatypeFactory.newInstance().
            newXMLGregorianCalendar();
    calendar.setTimezone(60 + offsetMinutes);
    TimeZone timeZone = calendar.getTimeZone(DatatypeConstants.FIELD_UNDEFINED);
    String expected = (offsetMinutes < 10 ? "GMT+01:0" : "GMT+01:")
            + offsetMinutes;
    if (!timeZone.getID().equals(expected)) {
        throw new RuntimeException("Test failed: expected timezone: " +
                expected + " Actual: " + timeZone.getID());
    }
}
 
Example 25
Project: openjdk-jdk10   File: CalendarDuration1243Test.java   View source code 6 votes vote down vote up
/**
 * main method.
 *
 * @param args Standard args.
 */
public static void main(String[] args) {
    try {
        String dateTimeString = "2006-11-22T00:00:00.0+01:02";
        DatatypeFactory dtf = DatatypeFactory.newInstance();
        XMLGregorianCalendar cal = dtf.newXMLGregorianCalendar( dateTimeString );
        System.out.println( "XMLGregCal:" + cal.toString() );
        System.out.println( "GregCal:" + cal.toGregorianCalendar() );
        String toGCal = cal.toGregorianCalendar().toString();
        if (toGCal.indexOf("GMT+12:00") > -1) {
            throw new RuntimeException("Expected GMT+01:02");
        }
    } catch (DatatypeConfigurationException ex) {
        throw new RuntimeException(ex.getMessage());
    }
}
 
Example 26
Project: openjdk-jdk10   File: CalendarDuration1097Test.java   View source code 6 votes vote down vote up
/**
 * main method.
 *
 * @param args Standard args.
 */
public static void main(String[] args) {
    try {
        String dateTimeString = "0001-01-01T00:00:00.0000000-05:00";
        DatatypeFactory dtf = DatatypeFactory.newInstance();
        XMLGregorianCalendar cal = dtf.newXMLGregorianCalendar( dateTimeString );
        System.out.println( "Expected: 0001-01-01T00:00:00.0000000-05:00");
        System.out.println( "Actual:" + cal.toString() );
        System.out.println( "toXMLFormat:" + cal.toXMLFormat() );
        String test = cal.toString();
        if (test.indexOf("E-7") > -1) {
            throw new RuntimeException("Expected: 0001-01-01T00:00:00.0000000-05:00");
        }
    } catch (DatatypeConfigurationException ex) {
        throw new RuntimeException(ex.getMessage());
    }
}
 
Example 27
Project: openjdk-jdk10   File: DatatypeConverterImpl.java   View source code 6 votes vote down vote up
public static DatatypeFactory getDatatypeFactory() {
    ClassLoader tccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        public ClassLoader run() {
            return Thread.currentThread().getContextClassLoader();
        }
    });
    DatatypeFactory df = DF_CACHE.get(tccl);
    if (df == null) {
        synchronized (DatatypeConverterImpl.class) {
            df = DF_CACHE.get(tccl);
            if (df == null) { // to prevent multiple initialization
                try {
                    df = DatatypeFactory.newInstance();
                } catch (DatatypeConfigurationException e) {
                    throw new Error(Messages.FAILED_TO_INITIALE_DATATYPE_FACTORY.format(),e);
                }
                DF_CACHE.put(tccl, df);
            }
        }
    }
    return df;
}
 
Example 28
Project: weixinpay   File: DateUtil.java   View source code 6 votes vote down vote up
public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(Date date) {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(date);
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);

    XMLGregorianCalendar xt = null;
    try {
        xt = DatatypeFactory.newInstance().newXMLGregorianCalendar(year, month + 1, day, 0, 0, 0, 0, 0);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }

    return xt;
}
 
Example 29
Project: openjdk-jdk10   File: DurationTest.java   View source code 6 votes vote down vote up
@Test
public void testDurationSubtract() {
    try {
        Duration bigDur = DatatypeFactory.newInstance().newDuration(20000);
        Duration smallDur = DatatypeFactory.newInstance().newDuration(10000);
        if (smallDur.subtract(bigDur).getSign() != -1) {
            Assert.fail("smallDur.subtract(bigDur).getSign() is not -1");
        }
        if (bigDur.subtract(smallDur).getSign() != 1) {
            Assert.fail("bigDur.subtract(smallDur).getSign() is not 1");
        }
        if (smallDur.subtract(smallDur).getSign() != 0) {
            Assert.fail("smallDur.subtract(smallDur).getSign() is not 0");
        }
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 30
Project: openjdk-jdk10   File: DurationTest.java   View source code 5 votes vote down vote up
private void newDurationDayTimeTester(boolean isPositive, boolean normalizedIsPositive, BigInteger years, BigInteger normalizedYears, BigInteger months,
        BigInteger normalizedMonths, BigInteger days, BigInteger normalizedDays, BigInteger hours, BigInteger normalizedHours, BigInteger minutes,
        BigInteger normalizedMinutes, BigDecimal seconds, BigDecimal normalizedSeconds, long durationInMilliSeconds, long normalizedDurationInMilliSeconds,
        String lexicalRepresentation, String normalizedLexicalRepresentation) {

    DatatypeFactory datatypeFactory = null;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        ex.printStackTrace();
        Assert.fail(ex.toString());
    }

    // create 4 dayTime Durations using the 4 different constructors

    Duration durationDayTimeBigInteger = datatypeFactory.newDurationDayTime(isPositive, days, hours, minutes, seconds.toBigInteger());
    durationAssertEquals(durationDayTimeBigInteger, DatatypeConstants.DURATION_DAYTIME, normalizedIsPositive, normalizedYears.intValue(),
            normalizedMonths.intValue(), normalizedDays.intValue(), normalizedHours.intValue(), normalizedMinutes.intValue(), normalizedSeconds.intValue(),
            normalizedDurationInMilliSeconds, normalizedLexicalRepresentation);

    /*
     * Duration durationDayTimeInt = datatypeFactory.newDurationDayTime(
     * isPositive, days.intValue(), hours.intValue(), minutes.intValue(),
     * seconds.intValue()); Duration durationDayTimeMilliseconds =
     * datatypeFactory.newDurationDayTime( durationInMilliSeconds); Duration
     * durationDayTimeLexical = datatypeFactory.newDurationDayTime(
     * lexicalRepresentation);
     * Duration durationYearMonthBigInteger =
     * datatypeFactory.newDurationYearMonth( isPositive, years, months);
     * Duration durationYearMonthInt = datatypeFactory.newDurationYearMonth(
     * isPositive, years.intValue(), months.intValue()); Duration
     * durationYearMonthMilliseconds = datatypeFactory.newDurationYearMonth(
     * durationInMilliSeconds); Duration durationYearMonthLexical =
     * datatypeFactory.newDurationYearMonth( lexicalRepresentation) ;
     */

}
 
Example 31
Project: rapidminer   File: XMLTools.java   View source code 5 votes vote down vote up
public static XMLGregorianCalendar getXMLGregorianCalendar(Date date) {
	if (date == null) {
		return null;
	}
	// Calendar calendar = Calendar.getInstance();
	// calendar.setTimeInMillis(date.getTime());
	DatatypeFactory datatypeFactory;
	try {
		datatypeFactory = DatatypeFactory.newInstance();
	} catch (DatatypeConfigurationException e) {
		throw new RuntimeException("Failed to create XMLGregorianCalendar: " + e, e);
	}
	GregorianCalendar c = new GregorianCalendar();
	c.setTime(date);
	return datatypeFactory.newXMLGregorianCalendar(c);
	//
	// XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar();
	// xmlGregorianCalendar.setYear(calendar.get(Calendar.YEAR));
	// xmlGregorianCalendar.setMonth(calendar.get(Calendar.MONTH) + 1);
	// xmlGregorianCalendar.setDay(calendar.get(Calendar.DAY_OF_MONTH));
	// xmlGregorianCalendar.setHour(calendar.get(Calendar.HOUR_OF_DAY));
	// xmlGregorianCalendar.setMinute(calendar.get(Calendar.MINUTE));
	// xmlGregorianCalendar.setSecond(calendar.get(Calendar.SECOND));
	// xmlGregorianCalendar.setMillisecond(calendar.get(Calendar.MILLISECOND));
	// //
	// xmlGregorianCalendar.setTimezone(calendar.get(((Calendar.DST_OFFSET)+calendar.get(Calendar.ZONE_OFFSET))/(60*1000)));
	// return xmlGregorianCalendar;
}
 
Example 32
Project: cim-processor   File: ModelParser.java   View source code 5 votes vote down vote up
public AppliedOutages applyOutages(Calendar calendar, boolean assumeConnected) {
	appliedOutages = ModelParser.applyOutages(calendar, rdfModel, assumeConnected);
	GregorianCalendar gregorianCalendar = new GregorianCalendar();
	gregorianCalendar.setTime(appliedOutages.getEffectiveEnd().getTime());
	try {
		DatatypeFactory factory = DatatypeFactory.newInstance();
		endDate = factory.newXMLGregorianCalendar(gregorianCalendar);
		Duration oneSecond = factory.newDuration("PT1S");
		endDate.add(oneSecond);
	} catch (DatatypeConfigurationException e) {
		// do nothing
	}
	return appliedOutages;
}
 
Example 33
Project: FHIR-CQL-ODM-service   File: FhirService.java   View source code 5 votes vote down vote up
private ODM createOdmTemplate(Integer project_id, Integer event_id,
		String instrument, String patientId)
		throws DatatypeConfigurationException {
	ODM studyTemplate = new ODM();
	studyTemplate.setODMVersion("1.3.2");
	studyTemplate.setCreationDateTime(getXMLGregorianCalendarNow());

	ODMcomplexTypeDefinitionClinicalData clinicalData = new ODMcomplexTypeDefinitionClinicalData();
	studyTemplate.getClinicalData().add(clinicalData);
	clinicalData.setStudyOID(project_id.toString());
	ODMcomplexTypeDefinitionSubjectData subjectData = new ODMcomplexTypeDefinitionSubjectData();
	clinicalData.getSubjectData().add(subjectData);
	subjectData.setSubjectKey(patientId);
	ODMcomplexTypeDefinitionStudyEventData studyEventData = new ODMcomplexTypeDefinitionStudyEventData();
	subjectData.getStudyEventData().add(studyEventData);
	if (event_id != null) {
		studyEventData.setStudyEventOID(event_id.toString());
	}
	ODMcomplexTypeDefinitionFormData formData = new ODMcomplexTypeDefinitionFormData();
	studyEventData.getFormData().add(formData);
	formData.setFormOID(instrument);
	ODMcomplexTypeDefinitionItemGroupData itemGroupData = new ODMcomplexTypeDefinitionItemGroupData();
	formData.getItemGroupData().add(itemGroupData);
	itemGroupData.setItemGroupOID(instrument);

	return studyTemplate;
}
 
Example 34
Project: camunda-util-demo-data-generator   File: TimeAwareDemoGenerator.java   View source code 5 votes vote down vote up
public TimeAwareDemoGenerator(ProcessEngine engine, ProcessApplicationReference originalProcessApplicationReference,
    ProcessApplicationReference simulatingProcessApplicationReference) {
  this.engine = engine;
  this.originalProcessApplication = originalProcessApplicationReference;
  this.simulatingProcessApplication = simulatingProcessApplicationReference;
  try {
    datatypeFactory = DatatypeFactory.newInstance();
  } catch (DatatypeConfigurationException e) {
    throw new RuntimeException(e);
  }
}
 
Example 35
Project: stroom-stats   File: TestStatisticValidator.java   View source code 5 votes vote down vote up
private StatisticWrapper buildBasicStatWrapper() throws DatatypeConfigurationException {
    ZonedDateTime time = ZonedDateTime.of(
            LocalDateTime.of(2017, 2, 27, 10, 50, 30),
            ZoneOffset.UTC);
    String tag1 = "tag1";
    String tag2 = "tag2";
    EventStoreTimeIntervalEnum interval = EventStoreTimeIntervalEnum.MINUTE;
    StatisticType statisticType = StatisticType.COUNT;

    String statName = "MyStat";
    Statistics.Statistic statistic = StatisticsHelper.buildCountStatistic(
            time,
            1L,
            StatisticsHelper.buildTagType(tag1, tag1 + "val1"),
            StatisticsHelper.buildTagType(tag2, tag2 + "val1")
    );

    MockStatisticConfiguration statConfig = new MockStatisticConfiguration()
            .setUuid(statUuid)
            .setName(statName)
            .setStatisticType(statisticType)
            .setRollUpType(StatisticRollUpType.ALL)
            .addFieldName(tag1)
            .addFieldName(tag2)
            .setPrecision(interval);

    return new StatisticWrapper(statistic, Optional.of(statConfig));
}
 
Example 36
Project: stroom-stats   File: StatisticsHelper.java   View source code 5 votes vote down vote up
private static Statistics.Statistic buildStatistic(ZonedDateTime time, TagType... tagValues) {
    ObjectFactory objectFactory = new ObjectFactory();
    Statistics.Statistic statistic = objectFactory.createStatisticsStatistic();
    Statistics.Statistic.Tags tagsObj = new Statistics.Statistic.Tags();
    tagsObj.getTag().addAll(Arrays.asList(tagValues));
    statistic.setTags(tagsObj);
    GregorianCalendar gregorianCalendar = GregorianCalendar.from(time);
    try {
        statistic.setTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar));
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(String.format("Error converting time %s to a gregorian calendar", time), e);
    }
    return statistic;
}
 
Example 37
Project: alfresco-repository   File: CMISConnector.java   View source code 5 votes vote down vote up
private String convertAspectPropertyValue(Object value)
{
    if (value instanceof Date)
    {
        GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        cal.setTime((Date) value);
        value = cal;
    }

    if (value instanceof GregorianCalendar)
    {
        DatatypeFactory df;
        try
        {
            df = DatatypeFactory.newInstance();
        }
        catch (DatatypeConfigurationException e)
        {
            throw new IllegalArgumentException("Aspect conversation exception: " + e.getMessage(), e);
        }
        return df.newXMLGregorianCalendar((GregorianCalendar) value).toXMLFormat();
    }

    // MNT-12496 MNT-15044
    // Filter for AtomPub and Web services bindings only. Browser/json binding already encodes.
    if (AlfrescoCmisServiceCall.get() != null &&
            (CallContext.BINDING_ATOMPUB.equals(AlfrescoCmisServiceCall.get().getBinding()) ||
             CallContext.BINDING_WEBSERVICES.equals(AlfrescoCmisServiceCall.get().getBinding())))
    {
    	return filterXmlRestrictedCharacters(value.toString());
    }
    else
    {
    	return value.toString();
    }
}
 
Example 38
Project: the-vigilantes   File: Value.java   View source code 5 votes vote down vote up
public void setDateTime(GregorianCalendar value) throws DatatypeConfigurationException {
    if (this.dtf == null) {
        this.dtf = DatatypeFactory.newInstance();
    }
    this.objValue = this.dtf.newXMLGregorianCalendar(value);
    this.objType = TYPE_dateTime_iso8601;
}
 
Example 39
Project: the-vigilantes   File: Value.java   View source code 5 votes vote down vote up
public void setDateTime(String value) throws DatatypeConfigurationException {
    if (this.dtf == null) {
        this.dtf = DatatypeFactory.newInstance();
    }
    this.objValue = this.dtf.newXMLGregorianCalendar(value);
    this.objType = TYPE_dateTime_iso8601;
}
 
Example 40
Project: xitk   File: XmlUtil.java   View source code 5 votes vote down vote up
public static XMLGregorianCalendar getXmlDate(Date dateAndTime) {
    ParamUtil.requireNonNull("dateAndTime", dateAndTime);
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTimeZone(UTC);
    cal.setTime(dateAndTime);

    try {
        XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
        ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
        return ret;
    } catch (DatatypeConfigurationException ex) {
        return null;
    }
}