Top Description Inners Fields Constructors Methods
org.apache.xerces.jaxp.datatype

pack-priv Class XMLGregorianCalendarImpl

extends XMLGregorianCalendar
implements Serializable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Serializable
Imports
java.io.IOException, .Serializable, java.math.BigDecimal, .BigInteger, java.util.Calendar, .Date, .GregorianCalendar, .Locale, .TimeZone, javax.xml.datatype.DatatypeConstants, .Duration, .XMLGregorianCalendar, javax.xml.namespace.QName, org.apache.xerces.util.DatatypeMessageFormatter

Representation for W3C XML Schema 1.0 date/time datatypes. Specifically, these date/time datatypes are dateTime, time, date, gYearMonth, gMonthDay, gYear, gMonth and gDay defined in the XML Namespace "http://www.w3.org/2001/XMLSchema". These datatypes are normatively defined in W3C XML Schema 1.0 Part 2, Section 3.2.7-14.

The table below defines the mapping between XML Schema 1.0 date/time datatype fields and this class' fields. It also summarizes the value constraints for the date and time fields defined in W3C XML Schema 1.0 Part 2, Appendix D, ISO 8601 Date and Time Formats.

Date/time datatype field mapping between XML Schema 1.0 and Java representation
XML Schema 1.0
datatype
field
Related
XMLGregorianCalendar
Accessor(s)
Value Range
year getYear() + getEon() or
getEonAndYear
getYear() is a value between -(10^9-1) to (10^9)-1 or DatatypeConstants#FIELD_UNDEFINED.
getEon() is high order year value in billion of years.
getEon() has values greater than or equal to (10^9) or less than or equal to -(10^9). A value of null indicates field is undefined.
Given that XML Schema 1.0 errata states that the year zero will be a valid lexical value in a future version of XML Schema, this class allows the year field to be set to zero. Otherwise, the year field value is handled exactly as described in the errata and [ISO-8601-1988]. Note that W3C XML Schema 1.0 validation does not allow for the year field to have a value of zero.
month getMonth() 1 to 12 or DatatypeConstants#FIELD_UNDEFINED
day getDay() Independent of month, max range is 1 to 31 or DatatypeConstants#FIELD_UNDEFINED.
The normative value constraint stated relative to month field's value is in W3C XML Schema 1.0 Part 2, Appendix D.
hour getHour() 0 to 24 or DatatypeConstants#FIELD_UNDEFINED For a value of 24, the minute and second field must be zero.
minute getMinute() 0 to 59 or DatatypeConstants#FIELD_UNDEFINED
second getSecond() + getMillisecond()/1000 or
getSecond() + getFractionalSecond()
getSecond() from 0 to 60 or DatatypeConstants#FIELD_UNDEFINED.
(Note: 60 only allowable for leap second.)
getFractionalSecond() allows for infinite precision over the range from 0.0 to 1.0 when the getSecond() is defined.
FractionalSecond is optional and has a value of null when it is undefined.
getMillisecond() is the convenience millisecond precision of value of getFractionalSecond().
timezone getTimezone() Number of minutes or DatatypeConstants#FIELD_UNDEFINED. Value range from -14 hours (-14 * 60 minutes) to 14 hours (14 * 60 minutes).

All maximum value space constraints listed for the fields in the table above are checked by factory methods, setter methods and parse methods of this class. IllegalArgumentException is thrown when parameter's value is outside the maximum value constraint for the field. Validation checks, for example, whether days in month should be limited to 29, 30 or 31 days, that are dependent on the values of other fields are not checked by these methods.

The following operations are defined for this class:

Authors
Kohsuke Kawaguchi, Joseph Fialli
Version
$Id: XMLGregorianCalendarImpl.java 759809 2009-03-30 00:44:05Z mrglavas $
See Also
javax.xml.datatype.Duration

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class

Field Summary

Modifier and TypeField and Description
private static final BigInteger
BILLION_B

BigInteger constant; representing a billion.

private static final int
BILLION_I

int constant; representing a billion.

private int
day

Day of this XMLGregorianCalendar.

private static final int
DAY

Day index for MIN_ and MAX_FIELD_VALUES.

private static final BigDecimal
private static final BigDecimal
private static final BigDecimal
private BigInteger
eon

Eon of this XMLGregorianCalendar.

private static final String[]
FIELD_NAME

field names indexed by YEAR..TIMEZONE.

private static final BigInteger
private static final BigInteger
private BigDecimal
fractionalSecond

Fractional second of this XMLGregorianCalendar.

private int
hour

Hour of this XMLGregorianCalendar.

private static final int
HOUR

Hour index for MIN_ and MAX_FIELD_VALUES.

private static final BigInteger
public static final XMLGregorianCalendar
LEAP_YEAR_DEFAULT

Use as a template for default field values when converting to a GregorianCalendar, set to a leap year date of January 1, 0400 at midnight.

private static final int[]
MAX_FIELD_VALUE

Maximum field values indexed by YEAR..TIMEZONE.

private static final int
MILLISECOND

Second index for MIN_ and MAX_FIELD_VALUES.

private static final int[]
MIN_FIELD_VALUE

Minimum field values indexed by YEAR..TIMEZONE.

private int
minute

Minute of this XMLGregorianCalendar.

private static final int
MINUTE

Minute index for MIN_ and MAX_FIELD_VALUES.

private int
month

Month of this XMLGregorianCalendar.

private static final int
MONTH

Month index for MIN_ and MAX_FIELD_VALUES.

private int
private BigInteger
orig_eon

Backup values

private BigDecimal
private int
private int
private int
private int
private int
private int
private static final Date
PURE_GREGORIAN_CHANGE

Obtain a pure Gregorian Calendar by calling GregorianCalendar.setChange(PURE_GREGORIAN_CHANGE).

private int
second

Second of this XMLGregorianCalendar.

private static final int
SECOND

Second index for MIN_ and MAX_FIELD_VALUES.

private static final long
serialVersionUID

Stream Unique Identifier.

private static final BigInteger
private int
timezone

Timezone of this XMLGregorianCalendar in minutes.

private static final int
TIMEZONE

Timezone index for MIN_ and MAX_FIELD_VALUES

private static final BigInteger
private static final BigInteger
private int
year

Year of this XMLGregorianCalendar.

private static final int
YEAR

Year index for MIN_ and MAX_FIELD_VALUES.

Constructor Summary

AccessConstructor and Description
protected
XMLGregorianCalendarImpl(String
Lexical representation of one the eight XML Schema date/time datatypes.
lexicalRepresentation
)

Constructs a new XMLGregorianCalendar object.

public
XMLGregorianCalendarImpl()

Create an instance with all date/time datatype fields set to DatatypeConstants#FIELD_UNDEFINED or null respectively.

protected
XMLGregorianCalendarImpl(BigInteger
of XMLGregorianCalendar to be created.
year
,
int
of XMLGregorianCalendar to be created.
month
,
int
of XMLGregorianCalendar to be created.
day
,
int
of XMLGregorianCalendar to be created.
hour
,
int
of XMLGregorianCalendar to be created.
minute
,
int
of XMLGregorianCalendar to be created.
second
,
BigDecimal
of XMLGregorianCalendar to be created.
fractionalSecond
,
int
of XMLGregorianCalendar to be created.
timezone
)

Private constructor allowing for complete value spaces allowed by W3C XML Schema 1.0 recommendation for xsd:dateTime and related builtin datatypes.

private
XMLGregorianCalendarImpl(int
of XMLGregorianCalendar to be created.
year
,
int
of XMLGregorianCalendar to be created.
month
,
int
of XMLGregorianCalendar to be created.
day
,
int
of XMLGregorianCalendar to be created.
hour
,
int
of XMLGregorianCalendar to be created.
minute
,
int
of XMLGregorianCalendar to be created.
second
,
int
of XMLGregorianCalendar to be created.
millisecond
,
int
of XMLGregorianCalendar to be created.
timezone
)

Private constructor of value spaces that a java.util.GregorianCalendar instance would need to convert to an XMLGregorianCalendar instance.

public
XMLGregorianCalendarImpl(GregorianCalendar
java.util.GregorianCalendar used to create XMLGregorianCalendar
cal
)

Convert a java.util.GregorianCalendar to XML Schema 1.0 representation.

Method Summary

Modifier and TypeMethod and Description
public void
add(Duration
Duration to add to this XMLGregorianCalendar.
duration
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.add.

Add duration to this instance.

private void
checkFieldValueConstraint(int field, int value)

public void
clear()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.clear.

Unset all fields to undefined.

public Object

Returns:

copy of this Object
clone
()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.clone.

Creates and returns a copy of this object.

public int
compare(XMLGregorianCalendar
instance of XMLGregorianCalendar to compare
rhs
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.compare.

Compare two instances of W3C XML Schema 1.0 date/time datatypes according to partial order relation defined in W3C XML Schema 1.0 Part 2, Section 3.2.7.3, Order relation on dateTime.

private static int
compareField(int Pfield, int Qfield)

Implement Step B from http://www.w3.org/TR/xmlschema-2/#dateTime-order.

private static int
private static int
public static XMLGregorianCalendar

Returns:

XMLGregorianCalendar created from parameter values.
createDate
(int
of XMLGregorianCalendar to be created.
year
,
int
of XMLGregorianCalendar to be created.
month
,
int
of XMLGregorianCalendar to be created.
day
,
int
offset in minutes. DatatypeConstants#FIELD_UNDEFINED indicates optional field is not set.
timezone
)

Create a Java representation of XML Schema builtin datatype date or g*.

public static XMLGregorianCalendar

Returns:

XMLGregorianCalendar created from parameter values.
createDateTime
(BigInteger
represents both high-order eons and low-order year.
year
,
int
of dateTime
month
,
int
of dateTime
day
,
int
of dateTime
hours
,
int
of dateTime
minutes
,
int
of dateTime
seconds
,
BigDecimal
value of null indicates optional field is absent.
fractionalSecond
,
int
offset in minutes. DatatypeConstants#FIELD_UNDEFINED indicates optional field is not set.
timezone
)

Create a Java representation of XML Schema builtin datatype dateTime.

public static XMLGregorianCalendar

Returns:

XMLGregorianCalendar created from parameter values.
createDateTime
(int
represents both high-order eons and low-order year.
year
,
int
of dateTime
month
,
int
of dateTime
day
,
int
of dateTime
hour
,
int
of dateTime
minute
,
int
of dateTime
second
)

Create a Java instance of XML Schema builtin datatype dateTime.

public static XMLGregorianCalendar

Returns:

XMLGregorianCalendar created from parameter values.
createDateTime
(int
represents low-order year.
year
,
int
of dateTime
month
,
int
of dateTime
day
,
int
of dateTime
hours
,
int
of dateTime
minutes
,
int
of dateTime
seconds
,
int
of dateTime. DatatypeConstants#FIELD_UNDEFINED indicates optional field is not set.
milliseconds
,
int
offset in minutes. DatatypeConstants#FIELD_UNDEFINED indicates optional field is not set.
timezone
)

Create a Java representation of XML Schema builtin datatype dateTime.

public static XMLGregorianCalendar

Returns:

XMLGregorianCalendar created from parameter values.
createTime
(int
number of hours
hours
,
int
number of minutes
minutes
,
int
number of seconds
seconds
,
int
offset in minutes. DatatypeConstants#FIELD_UNDEFINED indicates optional field is not set.
timezone
)

Create a Java instance of XML Schema builtin datatype time.

public static XMLGregorianCalendar

Returns:

XMLGregorianCalendar created from parameter values.
createTime
(int
number of hours
hours
,
int
number of minutes
minutes
,
int
number of seconds
seconds
,
BigDecimal
value of null indicates that this optional field is not set.
fractionalSecond
,
int
offset in minutes. DatatypeConstants#FIELD_UNDEFINED indicates optional field is not set.
timezone
)

Create a Java instance of XML Schema builtin datatype time.

public static XMLGregorianCalendar

Returns:

XMLGregorianCalendar created from parameter values.
createTime
(int
number of hours
hours
,
int
number of minutes
minutes
,
int
number of seconds
seconds
,
int
number of milliseconds
milliseconds
,
int
offset in minutes. DatatypeConstants#FIELD_UNDEFINED indicates optional field is not set.
timezone
)

Create a Java instance of XML Schema builtin datatype time.

public boolean

Returns:

true when compare(this,(XMLGregorianCalendar)obj) == EQUAL..
equals
(Object
to compare.
obj
)

Overrides javax.xml.datatype.XMLGregorianCalendar.equals.

Indicates whether parameter obj is "equal to" this one.

private String
format(String format)

public int
public BigInteger

Returns:

eon of this XMLGregorianCalendar. The value returned is an integer multiple of 10^9.
getEon
()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.getEon.

Return high order component for XML Schema 1.0 dateTime datatype field for year.

public BigInteger

Returns:

sum of eon and BigInteger.valueOf(year) when both fields are defined. When only year is defined, return it. When both eon and year are not defined, return null.
getEonAndYear
()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.getEonAndYear.

Return XML Schema 1.0 dateTime datatype field for year.

public BigDecimal

Returns:

fractional seconds of this XMLGregorianCalendar.
getFractionalSecond
()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.getFractionalSecond.

Return fractional seconds.

public int
public int

Returns:

Millisecond of this XMLGregorianCalendar.
getMillisecond
()

Overrides javax.xml.datatype.XMLGregorianCalendar.getMillisecond.

Return millisecond precision of getFractionalSecond().

public int
public int

Returns:

year of this XMLGregorianCalendar.
getMonth
()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.getMonth.

Return number of month or DatatypeConstants#FIELD_UNDEFINED.

public int

Returns:

Second of this XMLGregorianCalendar.
getSecond
()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.getSecond.

Return seconds or DatatypeConstants#FIELD_UNDEFINED.

private BigDecimal

Returns:

result of adding second and fractional second field
getSeconds
()

public int
getTimezone()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.getTimezone.

Return timezone offset in minutes or DatatypeConstants#FIELD_UNDEFINED if this optional field is not defined.
public TimeZone

Returns:

TimeZone for this.
getTimeZone
(int
default zoneoffset if this zoneoffset is DatatypeConstants#FIELD_UNDEFINED.
defaultZoneoffset
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.getTimeZone.

Returns a java.util.TimeZone for this class.

public QName
public int

Returns:

year of this XMLGregorianCalendar.
getYear
()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.getYear.

Return low order component for XML Schema 1.0 dateTime datatype field for year or DatatypeConstants#FIELD_UNDEFINED.

public int

Returns:

hash code of this object.
hashCode
()

Overrides javax.xml.datatype.XMLGregorianCalendar.hashCode.

Returns a hash code consistent with the definition of the equals method.

private static int
internalCompare(XMLGregorianCalendar
calendar instance with normalized timezone offset or having same timezone as Q
P
,
XMLGregorianCalendar
calendar instance with normalized timezone offset or having same timezone as P
Q
)

Implements Step B from http://www.w3.org/TR/xmlschema-2/#dateTime-order

private static boolean
isDigit(char ch)

public boolean

Returns:

true if data values are valid.
isValid
()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.isValid.

Validate instance by getXMLSchemaType() constraints.
private static int
private static int
maximumDayInMonthFor(int year, int month)

public XMLGregorianCalendar
normalize()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.normalize.

Normalize this instance to UTC.

private XMLGregorianCalendar
normalizeToTimezone(XMLGregorianCalendar cal, int timezone)

Normalize this instance to UTC.

public static XMLGregorianCalendar

Returns:

XMLGregorianCalendar created from parsing lexicalRepresentation parameter.
parse
(String
Lexical representation of one the 8 XML Schema calendar datatypes.
lexicalRepresentation
)

Constructs a new XMLGregorianCalendar object by parsing its lexical string representation as defined in XML Schema 1.0 Part 2, Section 3.2.[7-14].1, Lexical Representation.

The string representation may not have any leading and trailing whitespaces.

private void
printNumber(StringBuffer
The formatted string will be appended into this buffer.
out
,
int
The integer to be printed.
number
,
int
The field will be printed by using at least this number of digits. For example, 5 will be printed as "0005" if nDigits==4.
nDigits
)

Prints an integer as a String.

private void
printNumber(StringBuffer
The formatted string will be appended into this buffer.
out
,
BigInteger
The integer to be printed.
number
,
int
The field will be printed by using at least this number of digits. For example, 5 will be printed as "0005" if nDigits==4.
nDigits
)

Prints an BigInteger as a String.

public void
reset()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.reset.

reset() is designed to allow the reuse of existing XMLGregorianCalendars thus saving resources associated with the creation of new XMLGregorianCalendars.

pack-priv static BigInteger

Returns:

non-null BigInteger.
sanitize
(Number value, int signum)

Compute value*signum where value==null is treated as value==0.

private void
save()

public void
setDay(int
value constraints summarized in day field of date/time field mapping table.
day
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.setDay.

Set days in month.

private void
setEon(BigInteger
value constraints summarized in year field of date/time field mapping table.
eon
)

Set high order part of XSD dateTime year field.

public void
setFractionalSecond(BigDecimal
value constraints summarized in second field of date/time field mapping table.
fractional
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.setFractionalSecond.

Set fractional seconds.
public void
setHour(int
value constraints summarized in hour field of date/time field mapping table.
hour
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.setHour.

Set hours.
public void
setMillisecond(int
value constraints summarized in second field of date/time field mapping table.
millisecond
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.setMillisecond.

Set milliseconds.
public void
setMinute(int
value constraints summarized in minute field of date/time field mapping table.
minute
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.setMinute.

Set minutes.
public void
setMonth(int
value constraints summarized in month field of date/time field mapping table.
month
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.setMonth.

Set month.

public void
setSecond(int
value constraints summarized in second field of date/time field mapping table.
second
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.setSecond.

Set seconds.
public void
setTime(int
value constraints are summarized in hour field of date/time field mapping table.
hour
,
int
value constraints are summarized in minute field of date/time field mapping table.
minute
,
int
value constraints are summarized in second field of date/time field mapping table.
second
)

Overrides javax.xml.datatype.XMLGregorianCalendar.setTime.

Set time as one unit.

public void
setTime(int
value constraints are summarized in hour field of date/time field mapping table.
hour
,
int
value constraints are summarized in minute field of date/time field mapping table.
minute
,
int
value constraints are summarized in second field of date/time field mapping table.
second
,
BigDecimal
value of null indicates this optional field is not set.
fractional
)

Overrides javax.xml.datatype.XMLGregorianCalendar.setTime.

Set time as one unit, including the optional infinite precison fractional seconds.

public void
setTime(int
value constraints are summarized in hour field of date/time field mapping table.
hour
,
int
value constraints are summarized in minute field of date/time field mapping table.
minute
,
int
value constraints are summarized in second field of date/time field mapping table.
second
,
int
value of DatatypeConstants#FIELD_UNDEFINED indicates this optional field is not set.
millisecond
)

Overrides javax.xml.datatype.XMLGregorianCalendar.setTime.

Set time as one unit, including optional milliseconds.

public void
setTimezone(int
value constraints summarized in timezone field of date/time field mapping table.
offset
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.setTimezone.

Set the number of minutes in the timezone offset.

public void
setYear(BigInteger
value constraints summarized in year field of date/time field mapping table.
year
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.setYear.

Set low and high order component of XSD dateTime year field.

public void
setYear(int
value constraints are summarized in year field of date/time field mapping table. If year is DatatypeConstants#FIELD_UNDEFINED, then eon is set to null.
year
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.setYear.

Set year of XSD dateTime year field.

public GregorianCalendar
toGregorianCalendar()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.toGregorianCalendar.

Convert this to java.util.GregorianCalendar.

public GregorianCalendar

Returns:

a java.util.GregorianCalendar conversion of this instance.
toGregorianCalendar
(TimeZone
provide Timezone. null is a legal value.
timezone
,
Locale
provide explicit Locale. Use default GregorianCalendar locale if value is null.
aLocale
,
XMLGregorianCalendar
provide default field values to use when corresponding field for this instance is DatatypeConstants.FIELD_UNDEFINED or null. If defaultsis null or a field within the specified defaults is undefined, just use java.util.GregorianCalendar defaults.
defaults
)

Implements abstract javax.xml.datatype.XMLGregorianCalendar.toGregorianCalendar.

Convert this along with provided parameters to java.util.GregorianCalendar instance.

private String

Returns:

String representation of BigDecimal
toString
(BigDecimal
BigDecimal to format as a String
bd
)

Turns BigDecimal to a string representation.

public String

Returns:

XML, as String, representation of this XMLGregorianCalendar
toXMLFormat
()

Implements abstract javax.xml.datatype.XMLGregorianCalendar.toXMLFormat.

Return the lexical representation of this instance.

private Object

Returns:

An object that encapsulates the string returned by this.toXMLFormat().
writeReplace
()

Writes XMLGregorianCalendar as a lexical representation for maximum future compatibility.

Inherited from javax.xml.datatype.XMLGregorianCalendar:
toString