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

The following examples show how to use javax.xml.datatype.XMLGregorianCalendar#getYear() . 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: 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 2
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 3
Source File: XMLGregorianCalendarImpl.java    From jdk8u60 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 4
Source File: XMLGregorianCalendarImpl.java    From hottub 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: DefaultDateLib.java    From jdmn with Apache License 2.0 6 votes vote down vote up
private boolean isValidDate(XMLGregorianCalendar calendar) {
    if (calendar == null) {
        return false;
    }

    long year = calendar.getYear();
    BigInteger eonAndYear = calendar.getEonAndYear();
    if (eonAndYear != null) {
        year = eonAndYear.intValue();
    }
    return
            isValidDate(year, calendar.getMonth(), calendar.getDay())
                    && isUndefined(calendar.getHour())
                    && isUndefined(calendar.getMinute())
                    && isUndefined(calendar.getSecond())
            ;
}
 
Example 6
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 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: Bug6937951Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws DatatypeConfigurationException {
    DatatypeFactory dtf = DatatypeFactory.newInstance();
    XMLGregorianCalendar c1 = dtf.newXMLGregorianCalendar("1999-12-31T24:00:00");
    XMLGregorianCalendar c2 = dtf.newXMLGregorianCalendar("2000-01-01T00:00:00");
    System.out.println("c1: " + c1.getYear() + "-" + c1.getMonth() + "-" + c1.getDay() + "T" + c1.getHour());
    System.out.println(c1.equals(c2) ? "pass" : "fail"); // fails
    if (!c1.equals(c2))
        Assert.fail("hour 24 needs to be treated as equal to hour 0 of the next day");
    if (c1.getYear() != 2000 && c1.getHour() != 0)
        Assert.fail("hour 24 needs to be treated as equal to hour 0 of the next day");

}
 
Example 9
Source File: XMLGregorianCalendarTypeInfoCompiler.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public JSAssignmentExpression createValue(MappingCompiler<T, C> mappingCompiler, String item) {
	final JSCodeModel codeModel = mappingCompiler.getCodeModel();
	final JSObjectLiteral result = codeModel.object();
	final XMLGregorianCalendar calendar = datatypeFactory.newXMLGregorianCalendar(item);
	if (calendar.getYear() != DatatypeConstants.FIELD_UNDEFINED) {
		result.append("year", codeModel.integer(calendar.getYear()));
	}
	if (calendar.getMonth() != DatatypeConstants.FIELD_UNDEFINED) {
		result.append("month", codeModel.integer(calendar.getMonth()));
	}
	if (calendar.getDay() != DatatypeConstants.FIELD_UNDEFINED) {
		result.append("day", codeModel.integer(calendar.getDay()));
	}
	if (calendar.getHour() != DatatypeConstants.FIELD_UNDEFINED) {
		result.append("hour", codeModel.integer(calendar.getHour()));
	}
	if (calendar.getMinute() != DatatypeConstants.FIELD_UNDEFINED) {
		result.append("minute", codeModel.integer(calendar.getMinute()));
	}
	if (calendar.getSecond() != DatatypeConstants.FIELD_UNDEFINED) {
		result.append("second", codeModel.integer(calendar.getSecond()));
	}
	if (calendar.getFractionalSecond() != null) {
		result.append("second", codeModel.decimal(calendar.getFractionalSecond().toString()));
	}
	if (calendar.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) {
		result.append("timeZone", codeModel.integer(calendar.getTimezone()));
	}
	return result;
}
 
Example 10
Source File: CalendarUtil.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
/**
 * Determines number of years between two dates so that premium duration can
 * be established.
 * 
 * @param startDate start date of a period (e.g. date of birth of insured
 *            party).
 * @param endDate end date (e.g. premium end date of an insurance).
 * @return number of years between start and end.
 */
public int getDurationInYears(XMLGregorianCalendar startDate, XMLGregorianCalendar endDate) {
    int startYear = startDate.getYear();
    final int dec = 12;
    if (startDate.getMonth() == dec) {
        // started in December, increase year with one
        startYear++;
    }
    int endYear = endDate.getYear();
    return endYear - startYear;
}
 
Example 11
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 12
Source File: DefaultDateLib.java    From jdmn with Apache License 2.0 5 votes vote down vote up
public Integer year(XMLGregorianCalendar date) {
    if (date == null) {
        return null;
    }

    return date.getYear();
}
 
Example 13
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 14
Source File: DateTimeCast.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected Literal convert(ValueFactory vf, Value value) throws ValueExprEvaluationException {
	if (value instanceof Literal) {
		Literal literal = (Literal) value;
		IRI datatype = literal.getDatatype();

		if (datatype.equals(XMLSchema.DATE)) {
			// If ST is xs:date, then let SYR be eg:convertYearToString(
			// fn:year-from-date( SV )), let SMO be eg:convertTo2CharString(
			// fn:month-from-date( SV )), let SDA be eg:convertTo2CharString(
			// fn:day-from-date( SV )) and let STZ be eg:convertTZtoString(
			// fn:timezone-from-date( SV )); TV is xs:dateTime( fn:concat(
			// SYR , '-', SMO , '-', SDA , 'T00:00:00 ', STZ ) ).
			try {
				XMLGregorianCalendar calValue = literal.calendarValue();

				int year = calValue.getYear();
				int month = calValue.getMonth();
				int day = calValue.getDay();
				int timezoneOffset = calValue.getTimezone();

				if (DatatypeConstants.FIELD_UNDEFINED != year && DatatypeConstants.FIELD_UNDEFINED != month
						&& DatatypeConstants.FIELD_UNDEFINED != day) {
					StringBuilder dtBuilder = new StringBuilder();
					dtBuilder.append(year);
					dtBuilder.append("-");
					if (month < 10) {
						dtBuilder.append("0");
					}
					dtBuilder.append(month);
					dtBuilder.append("-");
					if (day < 10) {
						dtBuilder.append("0");
					}
					dtBuilder.append(day);
					dtBuilder.append("T00:00:00");
					if (DatatypeConstants.FIELD_UNDEFINED != timezoneOffset) {
						int minutes = Math.abs(timezoneOffset);
						int hours = minutes / 60;
						minutes = minutes - (hours * 60);
						if (timezoneOffset > 0) {
							dtBuilder.append("+");
						} else {
							dtBuilder.append("-");
						}
						if (hours < 10) {
							dtBuilder.append("0");
						}
						dtBuilder.append(hours);
						dtBuilder.append(":");
						if (minutes < 10) {
							dtBuilder.append("0");
						}
						dtBuilder.append(minutes);
					}

					return vf.createLiteral(dtBuilder.toString(), XMLSchema.DATETIME);
				} else {
					throw typeError(literal, null);
				}
			} catch (IllegalArgumentException e) {
				throw typeError(literal, e);
			}
		}
	}
	throw typeError(value, null);
}
 
Example 15
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk8u 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 16
Source File: SignavioBaseDateTimeLib.java    From jdmn with Apache License 2.0 4 votes vote down vote up
protected boolean isTime(XMLGregorianCalendar dateTime1) {
    return dateTime1.getYear() < 0 && dateTime1.getHour() >= 0;
}
 
Example 17
Source File: SignavioBaseDateTimeLib.java    From jdmn with Apache License 2.0 4 votes vote down vote up
protected boolean isDate(XMLGregorianCalendar dateTime) {
    return dateTime.getYear() >= 0 && dateTime.getHour() < 0;
}
 
Example 18
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-8-source 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 hottub 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());
        }
}