Java Code Examples for javax.xml.datatype.XMLGregorianCalendar#getSecond()

The following examples show how to use javax.xml.datatype.XMLGregorianCalendar#getSecond() . 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: DateTimeConverter.java    From atdl4j with MIT License 6 votes vote down vote up
public static DateTime convertXMLGregorianCalendarToDateTime( XMLGregorianCalendar aXMLGregorianCalendar, Timezone aTimezone )
{
	// -- DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) --
	int tempSubsecond = 0;
	if ( aXMLGregorianCalendar.getFractionalSecond() != null )
	{
		tempSubsecond = aXMLGregorianCalendar.getFractionalSecond().intValue();
	}
	
	DateTimeZone tempDateTimeZone = convertTimezoneToDateTimeZone( aTimezone );
	if ( tempDateTimeZone == null )
	{
		tempDateTimeZone = DateTimeZone.getDefault();
	}
	
	return new DateTime( aXMLGregorianCalendar.getYear(), 
								aXMLGregorianCalendar.getMonth(),
								aXMLGregorianCalendar.getDay(),
								aXMLGregorianCalendar.getHour(),
								aXMLGregorianCalendar.getMinute(),
								aXMLGregorianCalendar.getSecond(),
								tempSubsecond, 
								tempDateTimeZone );
}
 
Example 2
Source File: XMLGregorianCalendarImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Returns a hash code consistent with the definition of the equals method.</p>
 *
 * @return hash code of this object.
 */
public int hashCode() {

    // Following two dates compare to EQUALS since in different timezones.
    // 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
    //
    // Must ensure both instances generate same hashcode by normalizing
    // this to UTC timezone.
    int timezone = getTimezone();
    if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
        timezone = 0;
    }
    XMLGregorianCalendar gc = this;
    if (timezone != 0) {
        gc = this.normalizeToTimezone(getTimezone());
    }
    return gc.getYear() + gc.getMonth() + gc.getDay() +
            gc.getHour() + gc.getMinute() + gc.getSecond();
}
 
Example 3
Source File: XMLGregorianCalendarImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Returns a hash code consistent with the definition of the equals method.</p>
 *
 * @return hash code of this object.
 */
public int hashCode() {

    // Following two dates compare to EQUALS since in different timezones.
    // 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
    //
    // Must ensure both instances generate same hashcode by normalizing
    // this to UTC timezone.
    int timezone = getTimezone();
    if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
        timezone = 0;
    }
    XMLGregorianCalendar gc = this;
    if (timezone != 0) {
        gc = this.normalizeToTimezone(getTimezone());
    }
    return gc.getYear() + gc.getMonth() + gc.getDay() +
            gc.getHour() + gc.getMinute() + gc.getSecond();
}
 
Example 4
Source File: XMLGregorianCalendarImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Returns a hash code consistent with the definition of the equals method.</p>
 *
 * @return hash code of this object.
 */
public int hashCode() {

    // Following two dates compare to EQUALS since in different timezones.
    // 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
    //
    // Must ensure both instances generate same hashcode by normalizing
    // this to UTC timezone.
    int timezone = getTimezone();
    if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
        timezone = 0;
    }
    XMLGregorianCalendar gc = this;
    if (timezone != 0) {
        gc = this.normalizeToTimezone(getTimezone());
    }
    return gc.getYear() + gc.getMonth() + gc.getDay() +
            gc.getHour() + gc.getMinute() + gc.getSecond();
}
 
Example 5
Source File: XMLGregorianCalendarImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * <p>Returns a hash code consistent with the definition of the equals method.</p>
 *
 * @return hash code of this object.
 */
public int hashCode() {

    // Following two dates compare to EQUALS since in different timezones.
    // 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
    //
    // Must ensure both instances generate same hashcode by normalizing
    // this to UTC timezone.
    int timezone = getTimezone();
    if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
        timezone = 0;
    }
    XMLGregorianCalendar gc = this;
    if (timezone != 0) {
        gc = this.normalizeToTimezone(getTimezone());
    }
    return gc.getYear() + gc.getMonth() + gc.getDay() +
            gc.getHour() + gc.getMinute() + gc.getSecond();
}
 
Example 6
Source File: FEELXMLGregorianCalendar.java    From jdmn with Apache License 2.0 6 votes vote down vote up
@Override
public int hashCode() {
    // Following two dates compare to EQUALS since in different timezones.
    // 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
    //
    // Must ensure both instances generate same hashcode by normalizing this to UTC timezone.
    int timezone = getTimezone();
    if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
        timezone = 0;
    }
    XMLGregorianCalendar gc = this;
    if (timezone != 0) {
        gc = this.normalizeToTimezone(getZoneID());
    }
    return gc.getYear() + gc.getMonth() + gc.getDay() + gc.getHour() + gc.getMinute() + gc.getSecond();
}
 
Example 7
Source File: XMLGregorianCalendarImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Returns a hash code consistent with the definition of the equals method.</p>
 *
 * @return hash code of this object.
 */
public int hashCode() {

    // Following two dates compare to EQUALS since in different timezones.
    // 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
    //
    // Must ensure both instances generate same hashcode by normalizing
    // this to UTC timezone.
    int timezone = getTimezone();
    if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
        timezone = 0;
    }
    XMLGregorianCalendar gc = this;
    if (timezone != 0) {
        gc = this.normalizeToTimezone(getTimezone());
    }
    return gc.getYear() + gc.getMonth() + gc.getDay() +
            gc.getHour() + gc.getMinute() + gc.getSecond();
}
 
Example 8
Source File: XMLGregorianCalendarImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Returns a hash code consistent with the definition of the equals method.</p>
 *
 * @return hash code of this object.
 */
public int hashCode() {

    // Following two dates compare to EQUALS since in different timezones.
    // 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
    //
    // Must ensure both instances generate same hashcode by normalizing
    // this to UTC timezone.
    int timezone = getTimezone();
    if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
        timezone = 0;
    }
    XMLGregorianCalendar gc = this;
    if (timezone != 0) {
        gc = this.normalizeToTimezone(getTimezone());
    }
    return gc.getYear() + gc.getMonth() + gc.getDay() +
            gc.getHour() + gc.getMinute() + gc.getSecond();
}
 
Example 9
Source File: XMLGregorianCalendarImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Returns a hash code consistent with the definition of the equals method.</p>
 *
 * @return hash code of this object.
 */
public int hashCode() {

    // Following two dates compare to EQUALS since in different timezones.
    // 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
    //
    // Must ensure both instances generate same hashcode by normalizing
    // this to UTC timezone.
    int timezone = getTimezone();
    if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
        timezone = 0;
    }
    XMLGregorianCalendar gc = this;
    if (timezone != 0) {
        gc = this.normalizeToTimezone(getTimezone());
    }
    return gc.getYear() + gc.getMonth() + gc.getDay() +
            gc.getHour() + gc.getMinute() + gc.getSecond();
}
 
Example 10
Source File: XMLGregorianCalendarImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Returns a hash code consistent with the definition of the equals method.</p>
 *
 * @return hash code of this object.
 */
public int hashCode() {

    // Following two dates compare to EQUALS since in different timezones.
    // 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
    //
    // Must ensure both instances generate same hashcode by normalizing
    // this to UTC timezone.
    int timezone = getTimezone();
    if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
        timezone = 0;
    }
    XMLGregorianCalendar gc = this;
    if (timezone != 0) {
        gc = this.normalizeToTimezone(getTimezone());
    }
    return gc.getYear() + gc.getMonth() + gc.getDay() +
            gc.getHour() + gc.getMinute() + gc.getSecond();
}
 
Example 11
Source File: Seconds.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException {
	if (args.length != 1) {
		throw new ValueExprEvaluationException("SECONDS requires 1 argument, got " + args.length);
	}

	Value argValue = args[0];
	if (argValue instanceof Literal) {
		Literal literal = (Literal) argValue;

		IRI datatype = literal.getDatatype();

		if (datatype != null && XMLDatatypeUtil.isCalendarDatatype(datatype)) {
			try {
				XMLGregorianCalendar calValue = literal.calendarValue();

				int seconds = calValue.getSecond();
				if (DatatypeConstants.FIELD_UNDEFINED != seconds) {
					BigDecimal fraction = calValue.getFractionalSecond();
					String str = (fraction == null) ? String.valueOf(seconds)
							: String.valueOf(fraction.doubleValue() + seconds);

					return valueFactory.createLiteral(str, XMLSchema.DECIMAL);
				} else {
					throw new ValueExprEvaluationException("can not determine minutes from value: " + argValue);
				}
			} catch (IllegalArgumentException e) {
				throw new ValueExprEvaluationException("illegal calendar value: " + argValue);
			}
		} else {
			throw new ValueExprEvaluationException("unexpected input value for function: " + argValue);
		}
	} else {
		throw new ValueExprEvaluationException("unexpected input value for function: " + args[0]);
	}
}
 
Example 12
Source File: SwingJideClockWidget.java    From atdl4j with MIT License 5 votes vote down vote up
/**
 * Used when applying Clock@initValue (xs:time)
 * @param aValue
 * @param @InitValueMode
 */
protected void setAndRenderInitValue( XMLGregorianCalendar aValue, int aInitValueMode )
{
	if ( aValue != null )
	{
		// -- Note that this will throw IllegalArgumentException if timezone ID
		// specified cannot be resolved --
		DateTimeZone tempLocalMktTz = getLocalMktTz();
		logger.debug( "control.getID(): " + control.getID() + " aValue: " + aValue + " getLocalMktTz(): " + tempLocalMktTz );

		// -- localMktTz is required when using/interpreting aValue --
		if ( tempLocalMktTz == null )
		{
			throw new IllegalArgumentException( "localMktTz is required when aValue (" + aValue + ") is specified. (Control.ID: "
					+ control.getID() + ")" );
		}

		DateTime tempNow = new DateTime( tempLocalMktTz );

		DateTime tempInit = new DateTime( 
				( showMonthYear && aValue.getYear() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getYear() : tempNow.getYear(), 
				( showMonthYear && aValue.getMonth() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getMonth() : tempNow.getMonthOfYear(), 
				( showMonthYear && aValue.getDay() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getDay() : tempNow.getDayOfMonth(), 
				( showTime && aValue.getHour() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getHour() : 0,
				( showTime && aValue.getMinute() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getMinute() : 0,
				( showTime && aValue.getSecond() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getSecond(): 0, 
				0,
				tempLocalMktTz );
		
		if ( ( aInitValueMode == Atdl4jConstants.CLOCK_INIT_VALUE_MODE_USE_CURRENT_TIME_IF_LATER ) &&
			  ( tempNow.isAfter( tempInit ) ) )
		{
			// -- Use current time --
			tempInit = tempNow;
		}
		
		// -- Make sure that the value is rendered on the display in local timezone --
		setValue( tempInit.withZone( DateTimeZone.getDefault() ) );
	}
}
 
Example 13
Source File: XMLGregorianCalendarTypeInfoProducer.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public JsonValue createValue(JsonSchemaMappingCompiler<T, C> mappingCompiler, String item) {
	final JsonObjectBuilder objectBuilder = mappingCompiler.getJsonBuilderFactory().createObjectBuilder();
	final XMLGregorianCalendar calendar = datatypeFactory.newXMLGregorianCalendar(item);
	if (calendar.getYear() != DatatypeConstants.FIELD_UNDEFINED) {
		objectBuilder.add("year", calendar.getYear());
	}
	if (calendar.getMonth() != DatatypeConstants.FIELD_UNDEFINED) {
		objectBuilder.add("month", calendar.getMonth());
	}
	if (calendar.getDay() != DatatypeConstants.FIELD_UNDEFINED) {
		objectBuilder.add("day", calendar.getDay());
	}
	if (calendar.getHour() != DatatypeConstants.FIELD_UNDEFINED) {
		objectBuilder.add("hour", calendar.getHour());
	}
	if (calendar.getMinute() != DatatypeConstants.FIELD_UNDEFINED) {
		objectBuilder.add("minute", calendar.getMinute());
	}
	if (calendar.getSecond() != DatatypeConstants.FIELD_UNDEFINED) {
		objectBuilder.add("second", calendar.getSecond());
	}
	if (calendar.getFractionalSecond() != null) {
		objectBuilder.add("second", calendar.getFractionalSecond());
	}
	if (calendar.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) {
		objectBuilder.add("timeZone", calendar.getTimezone());
	}
	return objectBuilder.build();
}
 
Example 14
Source File: AbstractTypeTestClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected boolean equalsDate(XMLGregorianCalendar orig, XMLGregorianCalendar actual) {
    boolean result = false;

    if ((orig.getYear() == actual.getYear()) && (orig.getMonth() == actual.getMonth())
        && (orig.getDay() == actual.getDay()) && (actual.getHour() == DatatypeConstants.FIELD_UNDEFINED)
        && (actual.getMinute() == DatatypeConstants.FIELD_UNDEFINED)
        && (actual.getSecond() == DatatypeConstants.FIELD_UNDEFINED)
        && (actual.getMillisecond() == DatatypeConstants.FIELD_UNDEFINED)) {

        result = orig.getTimezone() == actual.getTimezone();
    }
    return result;
}
 
Example 15
Source File: DefaultTimeLib.java    From jdmn with Apache License 2.0 5 votes vote down vote up
public Integer second(XMLGregorianCalendar date) {
    if (date == null) {
        return null;
    }

    return date.getSecond();
}
 
Example 16
Source File: SWTClockWidget.java    From atdl4j with MIT License 5 votes vote down vote up
/**
 * Used when applying Clock@initValue (xs:time)
 * @param aValue
 * @param @InitValueMode
 */
protected void setAndRenderInitValue( XMLGregorianCalendar aValue, int aInitValueMode )
{
	if ( aValue != null )
	{
		// -- Note that this will throw IllegalArgumentException if timezone ID
		// specified cannot be resolved --
		DateTimeZone tempLocalMktTz = getLocalMktTz();
		logger.debug( "control.getID(): " + control.getID() + " aValue: " + aValue + " getLocalMktTz(): " + tempLocalMktTz );

		// -- localMktTz is required when using/interpreting aValue --
		if ( tempLocalMktTz == null )
		{
			throw new IllegalArgumentException( "localMktTz is required when aValue (" + aValue + ") is specified. (Control.ID: "
					+ control.getID() + ")" );
		}

		DateTime tempNow = new DateTime( tempLocalMktTz );

		DateTime tempInit = new DateTime( 
				( showMonthYear && aValue.getYear() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getYear() : tempNow.getYear(), 
				( showMonthYear && aValue.getMonth() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getMonth() : tempNow.getMonthOfYear(), 
				( showMonthYear && aValue.getDay() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getDay() : tempNow.getDayOfMonth(), 
				( showMonthYear && aValue.getHour() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getHour() : 0,
				( showMonthYear && aValue.getMinute() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getMinute() : 0,
				( showMonthYear && aValue.getSecond() != DatatypeConstants.FIELD_UNDEFINED ) ? aValue.getSecond(): 0, 
				0,
				tempLocalMktTz );
		
		if ( ( aInitValueMode == Atdl4jConstants.CLOCK_INIT_VALUE_MODE_USE_CURRENT_TIME_IF_LATER ) &&
			  ( tempNow.isAfter( tempInit ) ) )
		{
			// -- Use current time --
			tempInit = tempNow;
		}
		
		// -- Make sure that the value is rendered on the display in local timezone --
		setValue( tempInit.withZone( DateTimeZone.getDefault() ) );
	}
}
 
Example 17
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void checkXmlGregorianCalendarFieldRef(QName type,
        XMLGregorianCalendar cal)throws javax.xml.bind.MarshalException{
        StringBuilder buf = new StringBuilder();
        int bitField = xmlGregorianCalendarFieldRef.get(type);
        final int l = 0x1;
        int pos = 0;
        while (bitField != 0x0){
                int bit = bitField & l;
                bitField >>>= 4;
                pos++;

                if (bit == 1) {
                        switch(pos){
                                case 1:
                                        if (cal.getSecond() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_SEC);
                                        }
                                        break;
                                case 2:
                                        if (cal.getMinute() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_MIN);
                                        }
                                        break;
                                case 3:
                                        if (cal.getHour() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_HR);
                                        }
                                        break;
                                case 4:
                                        if (cal.getDay() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_DAY);
                                        }
                                        break;
                                case 5:
                                        if (cal.getMonth() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_MONTH);
                                        }
                                        break;
                                case 6:
                                        if (cal.getYear() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_YEAR);
                                        }
                                        break;
                                case 7:  // ignore timezone setting
                                        break;
                        }
                }
        }
        if (buf.length() > 0){
                throw new javax.xml.bind.MarshalException(
                 Messages.XMLGREGORIANCALENDAR_INVALID.format(type.getLocalPart())
                 + buf.toString());
        }
}
 
Example 18
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static void checkXmlGregorianCalendarFieldRef(QName type,
        XMLGregorianCalendar cal)throws javax.xml.bind.MarshalException{
        StringBuilder buf = new StringBuilder();
        int bitField = xmlGregorianCalendarFieldRef.get(type);
        final int l = 0x1;
        int pos = 0;
        while (bitField != 0x0){
                int bit = bitField & l;
                bitField >>>= 4;
                pos++;

                if (bit == 1) {
                        switch(pos){
                                case 1:
                                        if (cal.getSecond() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_SEC);
                                        }
                                        break;
                                case 2:
                                        if (cal.getMinute() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_MIN);
                                        }
                                        break;
                                case 3:
                                        if (cal.getHour() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_HR);
                                        }
                                        break;
                                case 4:
                                        if (cal.getDay() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_DAY);
                                        }
                                        break;
                                case 5:
                                        if (cal.getMonth() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_MONTH);
                                        }
                                        break;
                                case 6:
                                        if (cal.getYear() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_YEAR);
                                        }
                                        break;
                                case 7:  // ignore timezone setting
                                        break;
                        }
                }
        }
        if (buf.length() > 0){
                throw new javax.xml.bind.MarshalException(
                 Messages.XMLGREGORIANCALENDAR_INVALID.format(type.getLocalPart())
                 + buf.toString());
        }
}
 
Example 19
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void checkXmlGregorianCalendarFieldRef(QName type,
        XMLGregorianCalendar cal)throws javax.xml.bind.MarshalException{
        StringBuilder buf = new StringBuilder();
        int bitField = xmlGregorianCalendarFieldRef.get(type);
        final int l = 0x1;
        int pos = 0;
        while (bitField != 0x0){
                int bit = bitField & l;
                bitField >>>= 4;
                pos++;

                if (bit == 1) {
                        switch(pos){
                                case 1:
                                        if (cal.getSecond() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_SEC);
                                        }
                                        break;
                                case 2:
                                        if (cal.getMinute() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_MIN);
                                        }
                                        break;
                                case 3:
                                        if (cal.getHour() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_HR);
                                        }
                                        break;
                                case 4:
                                        if (cal.getDay() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_DAY);
                                        }
                                        break;
                                case 5:
                                        if (cal.getMonth() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_MONTH);
                                        }
                                        break;
                                case 6:
                                        if (cal.getYear() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_YEAR);
                                        }
                                        break;
                                case 7:  // ignore timezone setting
                                        break;
                        }
                }
        }
        if (buf.length() > 0){
                throw new javax.xml.bind.MarshalException(
                 Messages.XMLGREGORIANCALENDAR_INVALID.format(type.getLocalPart())
                 + buf.toString());
        }
}
 
Example 20
Source File: RuntimeBuiltinLeafInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static void checkXmlGregorianCalendarFieldRef(QName type,
        XMLGregorianCalendar cal)throws javax.xml.bind.MarshalException{
        StringBuilder buf = new StringBuilder();
        int bitField = xmlGregorianCalendarFieldRef.get(type);
        final int l = 0x1;
        int pos = 0;
        while (bitField != 0x0){
                int bit = bitField & l;
                bitField >>>= 4;
                pos++;

                if (bit == 1) {
                        switch(pos){
                                case 1:
                                        if (cal.getSecond() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_SEC);
                                        }
                                        break;
                                case 2:
                                        if (cal.getMinute() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_MIN);
                                        }
                                        break;
                                case 3:
                                        if (cal.getHour() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_HR);
                                        }
                                        break;
                                case 4:
                                        if (cal.getDay() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_DAY);
                                        }
                                        break;
                                case 5:
                                        if (cal.getMonth() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_MONTH);
                                        }
                                        break;
                                case 6:
                                        if (cal.getYear() == DatatypeConstants.FIELD_UNDEFINED){
                                                buf.append("  ").append(Messages.XMLGREGORIANCALENDAR_YEAR);
                                        }
                                        break;
                                case 7:  // ignore timezone setting
                                        break;
                        }
                }
        }
        if (buf.length() > 0){
                throw new javax.xml.bind.MarshalException(
                 Messages.XMLGREGORIANCALENDAR_INVALID.format(type.getLocalPart())
                 + buf.toString());
        }
}