Java Code Examples for javax.xml.datatype.Duration#isSet()

The following examples show how to use javax.xml.datatype.Duration#isSet() . 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: XMLDatatypeMathUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static IRI getDatatypeForDuration(Duration duration) {
	// Could not be implemented with Duration.getXMLSchemaType that is too strict ("P1Y" is considered invalid)

	boolean yearSet = duration.isSet(DatatypeConstants.YEARS);
	boolean monthSet = duration.isSet(DatatypeConstants.MONTHS);
	boolean daySet = duration.isSet(DatatypeConstants.DAYS);
	boolean hourSet = duration.isSet(DatatypeConstants.HOURS);
	boolean minuteSet = duration.isSet(DatatypeConstants.MINUTES);
	boolean secondSet = duration.isSet(DatatypeConstants.SECONDS);

	if (!yearSet && !monthSet) {
		return XMLSchema.DAYTIMEDURATION;
	}
	if (!daySet && !hourSet && !minuteSet && !secondSet) {
		return XMLSchema.YEARMONTHDURATION;
	}
	return XMLSchema.DURATION;
}
 
Example 2
Source File: XsValueImpl.java    From java-client-api with Apache License 2.0 6 votes vote down vote up
private static QName getDurationType(Duration value) {
    boolean hasYearMonth = (
            value.isSet(DatatypeConstants.YEARS)  ||
            value.isSet(DatatypeConstants.MONTHS)
            );
    boolean hasDayTime = (
            value.isSet(DatatypeConstants.DAYS)    ||
            value.isSet(DatatypeConstants.HOURS)   ||
            value.isSet(DatatypeConstants.MINUTES) ||
            value.isSet(DatatypeConstants.SECONDS)
            );

    if (hasYearMonth && !hasDayTime) {
        return DatatypeConstants.DURATION_YEARMONTH;
    } else if ((!hasYearMonth) && hasDayTime) {
        return DatatypeConstants.DURATION_DAYTIME;
    }

    throw new IllegalArgumentException("value must be yearMonthDuration or dayTimeDuration: "+value);
}
 
Example 3
Source File: BaseDefaultDurationType.java    From jdmn with Apache License 2.0 5 votes vote down vote up
protected boolean isDaysAndTime(Duration duration) {
    if (duration == null) {
        return false;
    }
    return duration.isSet(DatatypeConstants.DAYS) || duration.isSet(DatatypeConstants.HOURS) ||
            duration.isSet(DatatypeConstants.MINUTES) || duration.isSet(DatatypeConstants.SECONDS);
}
 
Example 4
Source File: BaseDefaultDurationType.java    From jdmn with Apache License 2.0 4 votes vote down vote up
protected boolean isYearsAndMonths(Duration duration) {
    if (duration == null) {
        return false;
    }
    return duration.isSet(DatatypeConstants.YEARS) || duration.isSet(DatatypeConstants.MONTHS);
}
 
Example 5
Source File: DurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void checkDurationIsSetNeg() {
    Duration duration = datatypeFactory.newDuration(true, 0, 0, 0, 0, 0, 0);
    duration.isSet(null);
}