Java Code Examples for javax.xml.datatype.DatatypeFactory

The following examples show how to use javax.xml.datatype.DatatypeFactory. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void setupSourceAndFlowType(ISource source,
        FramingFlowType framingFlowType) throws AdeException {
    m_source = source;
    synchronized (AnalyzedIntervalXmlStorer.class) {
        if (s_dataTypeFactory == null) {
            try {
                s_dataTypeFactory = DatatypeFactory.newInstance();
            } catch (DatatypeConfigurationException e) {
                throw new AdeInternalException("Failed to instantiate data factory for calendar", e);
            }
        }
    }
    // FIXME this is not thread safe

    m_gc = new GregorianCalendar(m_outputTimeZone);
    m_framingFlowType = framingFlowType;
}
 
Example 2
Source Project: rya   Source File: DateTimeWithinPeriodTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDays() throws DatatypeConfigurationException, ValueExprEvaluationException {
    DatatypeFactory dtf = DatatypeFactory.newInstance();

    ZonedDateTime zTime = testThisTimeDate;
    String time = zTime.format(DateTimeFormatter.ISO_INSTANT);

    ZonedDateTime zTime1 = zTime.minusDays(1);
    String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);

    Literal now = VF.createLiteral(dtf.newXMLGregorianCalendar(time));
    Literal nowMinusOne = VF.createLiteral(dtf.newXMLGregorianCalendar(time1));

    DateTimeWithinPeriod func = new DateTimeWithinPeriod();

    assertEquals(TRUE, func.evaluate(VF, now, now, VF.createLiteral(1), OWLTime.DAYS_URI));
    assertEquals(FALSE, func.evaluate(VF, now, nowMinusOne, VF.createLiteral(1), OWLTime.DAYS_URI));
    assertEquals(TRUE, func.evaluate(VF, now, nowMinusOne, VF.createLiteral(2), OWLTime.DAYS_URI));
}
 
Example 3
Source Project: development   Source File: MpOwnerShareResultAssembler.java    License: Apache License 2.0 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 4
Source Project: herd   Source File: AutoRefreshCredentialProviderTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * The getAwsCredential method should return the cached credential if the session hasn't expired. If the session expired, a new credential should be
 * generated.
 *
 * @throws Exception
 */
@Test
public void testAssertCredentialCachingBehavior() throws Exception
{
    AutoRefreshCredentialProvider autoRefreshCredentialProvider = new AutoRefreshCredentialProvider()
    {
        @Override
        public AwsCredential getNewAwsCredential() throws Exception
        {
            AwsCredential awsCredential = new AwsCredential();
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTimeInMillis(System.currentTimeMillis() + 1000);
            awsCredential.setAwsSessionExpirationTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal));
            return awsCredential;
        }
    };

    AwsCredential firstAwsCredential = autoRefreshCredentialProvider.getAwsCredential();
    AwsCredential secondAwsCredential = autoRefreshCredentialProvider.getAwsCredential();
    assertEquals(firstAwsCredential, secondAwsCredential);
    Thread.sleep(1000);
    secondAwsCredential = autoRefreshCredentialProvider.getAwsCredential();
    assertNotEquals(firstAwsCredential, secondAwsCredential);
}
 
Example 5
@Test
public void testGetServiceStatusGreenI() throws Exception {
    final String rawResponse = loadTestFile("GetServiceStatusResponseGreenI.xml");
    final ResponseData response = new ResponseData(HttpURLConnection.HTTP_OK, rawResponse);
    final GetServiceStatusResponseData res = Parser.getServiceStatus(response);

    Assert.assertEquals(res.getStatus(), ServiceStatus.GREEN_I);
    final XMLGregorianCalendar xgc = DatatypeFactory.newInstance().newXMLGregorianCalendar("2010-11-01T21:38:09.676Z");
    Assert.assertEquals(res.getTimestamp(), xgc);
    Assert.assertEquals(res.getMessageId(), "173964729I");

    final MessageList messages = res.getMessages();
    final List<Message> messageList = messages.getMessages();
    final Message message1 = messageList.get(0);
    final Message message2 = messageList.get(1);

    Assert.assertEquals(message1.getLocale(), "en_UK");
    Assert.assertEquals(message1.getText(), "We are experiencing high latency in UK because of heavy traffic.");
    Assert.assertEquals(message2.getLocale(), "en_US");
    Assert.assertEquals(message2.getText(), "Service is once again operating at normal capacity at 6:53 PST.");

    Assert.assertEquals(res.getRequestId(), "d80c6c7b-f7c7-4fa7-bdd7-854711cb3bcc");
    Assert.assertEquals(res.toXML(), rawResponse);
}
 
Example 6
@BeforeClass
public static void setup() throws Exception {
    SharesDataRetrievalServiceLocal sharesRetrievalService = mock(SharesDataRetrievalServiceLocal.class);
    BillingDataRetrievalServiceLocal billingRetrievalService = mock(BillingDataRetrievalServiceLocal.class);
    brokerShareAssembler = spy(new BrokerShareResultAssembler(
            sharesRetrievalService, billingRetrievalService));

    // create test data
    createBillingResults();

    // mock service methods
    mockGetBrokerData();
    mockGetBrokerRevenueSharePercentage();
    mockGetOrgData(NUMBER_SUPPLIERS);
    mockGetOrgData(NUMBER_CUSTOMER);
    mockGetSupplierKeyForSubscription();
    mockGetProductHistoryData();
    mockGetSubscriptionHistoryData();
    mockGetBillingResults();
    mockXmlSearch();
    datatypeFactory = DatatypeFactory.newInstance();
}
 
Example 7
@Override
public void setupSourceAndFlowType(ISource source,
        FramingFlowType framingFlowType) throws AdeException {
    m_source = source;
    if (s_dataTypeFactory == null) {
        try {
            s_dataTypeFactory = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new AdeInternalException("Failed to instantiate data factory for calendar", e);
        }
    }

    // FIXME this is not thread safe
    m_gc = new GregorianCalendar(m_outputTimeZone);
    m_framingFlowType = framingFlowType;
}
 
Example 8
Source Project: birt   Source File: BirtDuration.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected Object getValue( Object[] args ) throws BirtException
{
	Duration duration1, duration2;
	try
	{
		duration1 = DatatypeFactory.newInstance( )
				.newDuration( args[0].toString( ) );
		duration2 = DatatypeFactory.newInstance( )
				.newDuration( args[1].toString( ) );
	}
	catch ( DatatypeConfigurationException e )
	{
		throw new IllegalArgumentException( Messages.getFormattedString( "error.BirtDuration.literal.invalidArgument",
				args ) );
	}
	return duration1.subtract( duration2 ).toString( );
}
 
Example 9
Source Project: birt   Source File: BirtDuration.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected Object getValue( Object[] args ) throws BirtException
{
	Duration duration;
	try
	{
		duration = DatatypeFactory.newInstance( )
				.newDuration( args[0].toString( ) );
	}
	catch ( DatatypeConfigurationException e )
	{
		throw new IllegalArgumentException( Messages.getFormattedString( "error.BirtDuration.literal.invalidArgument",
				new Object[]{
					args[0].toString( )
				} ) );
	}
	return Long.valueOf( duration.getTimeInMillis( DataTypeUtil.toDate( args[1] ) ) );
}
 
Example 10
/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.impl.AbstractValueFactory#createLiteral(javax.xml.datatype.XMLGregorianCalendar)}
 * .
 */
@Test
public void testCreateLiteralXMLGregorianCalendar() {
	GregorianCalendar c = new GregorianCalendar();
	c.setTime(new Date());
	try {
		XMLGregorianCalendar xmlGregCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
		Literal l = f.createLiteral(xmlGregCalendar);
		assertNotNull(l);
		assertEquals(l.getDatatype(), XMLSchema.DATETIME);
		// TODO check lexical value?
	} catch (DatatypeConfigurationException e) {
		e.printStackTrace();
		fail("Could not instantiate javax.xml.datatype.DatatypeFactory");
	}
}
 
Example 11
Source Project: web-feature-service   Source File: CityGMLWriter.java    License: Apache License 2.0 6 votes vote down vote up
public CityGMLWriter(SAXWriter saxWriter, CityGMLVersion version, TransformerChainFactory transformerChainFactory, GeometryStripper geometryStripper, UIDCacheManager uidCacheManager, Object eventChannel, Config config) throws DatatypeConfigurationException {
	this.saxWriter = saxWriter;
	this.version = version;
	this.transformerChainFactory = transformerChainFactory;
	this.geometryStripper = geometryStripper;
	this.uidCacheManager = uidCacheManager;
	this.config = config;
	
	cityGMLBuilder = ObjectRegistry.getInstance().getCityGMLBuilder();
	jaxbMarshaller = cityGMLBuilder.createJAXBMarshaller(version);
	wfsFactory = new ObjectFactory();
	datatypeFactory = DatatypeFactory.newInstance();
	additionalObjectsHandler = new AdditionalObjectsHandler(saxWriter, version, cityGMLBuilder, transformerChainFactory, eventChannel);
	
	int queueSize = config.getProject().getExporter().getResources().getThreadPool().getDefaultPool().getMaxThreads() * 2;
	
	writerPool = new SingleWorkerPool<>(
			"citygml_writer_pool",
			new XMLWriterWorkerFactory(saxWriter, ObjectRegistry.getInstance().getEventDispatcher()),
			queueSize,
			false);

	writerPool.setEventSource(eventChannel);
	writerPool.prestartCoreWorkers();
}
 
Example 12
Source Project: OpenESPI-Common-java   Source File: DateConverter.java    License: Apache License 2.0 6 votes vote down vote up
public static DateTimeType toDateTimeType(Date date) {
	DateTimeType dateTimeType = new DateTimeType();
	GregorianCalendar gregorianCalendar = new DateTime(date)
			.toGregorianCalendar();
	gregorianCalendar.setTimeZone(TimeZone.getTimeZone("UTC"));
	DatatypeFactory datatypeFactory;

	try {
		datatypeFactory = DatatypeFactory.newInstance();
	} catch (DatatypeConfigurationException e) {
		throw new RuntimeException(e);
	}

	XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory
			.newXMLGregorianCalendar(gregorianCalendar);
	xmlGregorianCalendar.setFractionalSecond(null);
	dateTimeType.setValue(xmlGregorianCalendar);

	return dateTimeType;
}
 
Example 13
Source Project: openjdk-jdk9   Source File: DurationTest.java    License: GNU General Public License v2.0 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 14
Source Project: training   Source File: DateUtils.java    License: MIT License 6 votes vote down vote up
public static XMLGregorianCalendar extractXmlDateTime(Date timestamp) {
	if (timestamp == null) {
		return null;
	}
	XMLGregorianCalendar date = null;
	try {
		GregorianCalendar startDate = new GregorianCalendar();
		startDate.setTime(timestamp);
		date = DatatypeFactory.newInstance().newXMLGregorianCalendar(startDate);
		date.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
		date.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
	return date;
}
 
Example 15
Source Project: development   Source File: SupplierShareResultAssembler.java    License: Apache License 2.0 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 16
Source Project: ade   Source File: XMLMetaDataRetriever.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor
 * @throws AdeException
 */
public XMLMetaDataRetriever() throws AdeException {
    if (s_dataTypeFactory == null) {
        try {
            s_dataTypeFactory = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new AdeInternalException("Failed to instantiate data factory for calendar", e);
        }
    }

    m_gc = new GregorianCalendar(ExtOutputFilenameGenerator.getOutputTimeZone().toTimeZone());
}
 
Example 17
Source Project: TranskribusCore   Source File: JaxbUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static XMLGregorianCalendar getXmlCalendar(Date date){
	GregorianCalendar cal = new GregorianCalendar();
	cal.setTime(date);
	XMLGregorianCalendar xmlCal = null;
	try {
		xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
	} catch (DatatypeConfigurationException e) {
		logger.error("DatatypeFactory:  implementation is not available or cannot be instantiated. CreateDate will be null!", e);
	}
	return xmlCal;
}
 
Example 18
/**
 * Create test files
 *
 * @param javaVersion JDK version
 */
public void createTestFile(String javaVersion) {
    try {
        DatatypeFactory dtf = DatatypeFactory.newInstance();
        XMLGregorianCalendar c = dtf.newXMLGregorianCalendar(EXPECTED_CAL);
        Duration d = dtf.newDuration(EXPECTED_DURATION);
        toFile((Serializable) c, filePath + javaVersion + FILENAME_CAL);
        toFile((Serializable) d, filePath + javaVersion + FILENAME_DURATION);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
 
Example 19
Source Project: cloudstack   Source File: VmwareHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static XMLGregorianCalendar getXMLGregorianCalendar(final Date date, final int offsetSeconds) throws DatatypeConfigurationException {
    if (offsetSeconds > 0) {
        date.setTime(date.getTime() - offsetSeconds * 1000);
    }
    final GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTime(date);
    return DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
}
 
Example 20
Source Project: lemon   Source File: DeadlineHumanTaskListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(TaskInfo taskInfo) {
    String taskDefinitionKey = taskInfo.getCode();

    String processDefinitionId = taskInfo.getProcessDefinitionId();
    List<DeadlineDTO> deadlines = taskDefinitionConnector.findDeadlines(
            taskDefinitionKey, processDefinitionId);

    for (DeadlineDTO deadline : deadlines) {
        try {
            String durationText = deadline.getDuration();

            Date now = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(now);

            DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
            Duration duration = datatypeFactory.newDuration(durationText);
            duration.addTo(calendar);

            Date deadlineTime = calendar.getTime();
            TaskDeadline taskDeadline = new TaskDeadline();
            taskDeadline.setTaskInfo(taskInfo);
            taskDeadline.setType(deadline.getType());
            taskDeadline.setDeadlineTime(deadlineTime);
            taskDeadline
                    .setNotificationType(deadline.getNotificationType());
            taskDeadline.setNotificationTemplateCode(deadline
                    .getNotificationTemplateCode());
            taskDeadline.setNotificationReceiver(deadline
                    .getNotificationReceiver());
            taskDeadlineManager.save(taskDeadline);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
}
 
Example 21
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 22
public static XMLGregorianCalendar getXMLGregorianCalendar (Date dateValue) {
	XMLGregorianCalendar dateTime = null;
	try {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(dateValue);
		DatatypeFactory df;
		df = DatatypeFactory.newInstance();
		dateTime = df.newXMLGregorianCalendar(calendar);
	} catch (DatatypeConfigurationException e) {
		//printStackTrace(e,startTimeStamp,procedure,info);
	}
	return dateTime;
}
 
Example 23
Source Project: openjdk-jdk9   Source File: Bug6937964Test.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNewDurationYearMonthMilliseconds() throws DatatypeConfigurationException {
    DatatypeFactory dtf = DatatypeFactory.newInstance();
    Duration d = dtf.newDurationYearMonth(671976000000L);
    int years = d.getYears();
    System.out.println("Years: " + years);
    Assert.assertTrue(years == 21, "Return value should be normalized");
}
 
Example 24
Source Project: openjdk-jdk9   Source File: DurationTest.java    License: GNU General Public License v2.0 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 25
Source Project: estatio   Source File: PaymentBatch.java    License: Apache License 2.0 5 votes vote down vote up
private static XMLGregorianCalendar newDateTime(final DateTime dateTime) {
    if (dateTime == null) {
        return null;
    }
    try {
        DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
        return datatypeFactory.newXMLGregorianCalendar(dateTime.toGregorianCalendar());
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }
}
 
Example 26
Source Project: openjdk-jdk9   Source File: Bug6937964Test.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNewDurationDayTimeLexicalRepresentation() throws DatatypeConfigurationException {
    DatatypeFactory dtf = DatatypeFactory.newInstance();
    Duration d = dtf.newDurationDayTime("P1DT23H59M65S");
    int days = d.getDays();
    Assert.assertTrue(days == 2, "Return value should be normalized");
}
 
Example 27
Source Project: yawl   Source File: XMLUtils.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void setDurationValue(Element element, long value)
{
	try
	{
		DatatypeFactory df = DatatypeFactory.newInstance();
		Duration dur = df.newDuration(value);
		setStringValue(element, String.valueOf(dur.toString()));
	}
	catch (Exception e)
	{
		logger.error("'" + element.getName() + "' must be Duration, " + e.getMessage());
	}
}
 
Example 28
Source Project: r-course   Source File: Value.java    License: MIT License 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 29
Source Project: jackson-modules-base   Source File: JavaxTypesTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testGregorianCalendar() throws Exception
{
    DatatypeFactory f = DatatypeFactory.newInstance();
    XMLGregorianCalendar in = f.newXMLGregorianCalendar();
    in.setYear(2014);
    in.setMonth(3);
    
    String json = MAPPER.writeValueAsString(in);
    assertNotNull(json);
    XMLGregorianCalendar out = MAPPER.readValue(json, XMLGregorianCalendar.class);
    assertNotNull(out);
    
    // minor sanity check
    assertEquals(in.getYear(), out.getYear());
}
 
Example 30
public static XMLGregorianCalendar getDefaultVersion() {

        Calendar cal = Calendar.getInstance();
        cal.set(1980, 1, 1, 0, 0, 0);
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(cal.getTime());
        try {
            XMLGregorianCalendar gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
            return gc;
        } catch (DatatypeConfigurationException e) {
            e.printStackTrace();
            return null;
        }
    }