Class SaxonXMLGregorianCalendar
- java.lang.Object
-
- javax.xml.datatype.XMLGregorianCalendar
-
- net.sf.saxon.value.SaxonXMLGregorianCalendar
-
- All Implemented Interfaces:
java.lang.Cloneable
public class SaxonXMLGregorianCalendar extends javax.xml.datatype.XMLGregorianCalendar
Saxon implementation of the JAXP class javax.xml.datatype.XMLGregorianCalendar. This is currently used only by the XQJ interface for XQuery: the normal representation of a date, time, or dateTime value in Saxon is with a subclass ofCalendarValue
The JAXP specification for this class defines it in terms of XML Schema 1.0 semantics. This implementation is more aligned to the XPath 2.0 semantics of the data types.
Note that this class, unlike the representations of all other data types, is mutable.
-
-
Constructor Summary
Constructors Constructor Description SaxonXMLGregorianCalendar(CalendarValue value)
Create a SaxonXMLGregorianCalendar from a Saxon CalendarValue object
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(javax.xml.datatype.Duration duration)
Addduration
to this instance.void
clear()
Unset all fields to undefined.java.lang.Object
clone()
Creates and returns a copy of this object.int
compare(javax.xml.datatype.XMLGregorianCalendar xmlGregorianCalendar)
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.int
getDay()
Return day in month orDatatypeConstants.FIELD_UNDEFINED
.java.math.BigInteger
getEon()
Return high order component for XML Schema 1.0 dateTime datatype field foryear
.java.math.BigInteger
getEonAndYear()
Return XML Schema 1.0 dateTime datatype field foryear
.java.math.BigDecimal
getFractionalSecond()
Return fractional seconds.int
getHour()
Return hours orDatatypeConstants.FIELD_UNDEFINED
.int
getMicrosecond()
Return microsecond precision ofgetFractionalSecond()
.int
getMinute()
Return minutes orDatatypeConstants.FIELD_UNDEFINED
.int
getMonth()
Return number of month orDatatypeConstants.FIELD_UNDEFINED
.int
getSecond()
Return seconds orDatatypeConstants.FIELD_UNDEFINED
.int
getTimezone()
Return timezone offset in minutes orDatatypeConstants.FIELD_UNDEFINED
if this optional field is not defined.java.util.TimeZone
getTimeZone(int defaultZoneoffset)
Returns ajava.util.TimeZone
for this class.javax.xml.namespace.QName
getXMLSchemaType()
Return the name of the XML Schema date/time type that this instance maps to.int
getYear()
Return low order component for XML Schema 1.0 dateTime datatype field foryear
orDatatypeConstants.FIELD_UNDEFINED
.boolean
isValid()
Validate instance bygetXMLSchemaType()
constraints.javax.xml.datatype.XMLGregorianCalendar
normalize()
Normalize this instance to UTC.void
reset()
Reset thisXMLGregorianCalendar
to its original values.void
setCalendarValue(CalendarValue value)
Set the calendar value of this objectvoid
setDay(int day)
Set days in month.void
setFractionalSecond(java.math.BigDecimal fractional)
Set fractional seconds.void
setHour(int hour)
Set hours.void
setMillisecond(int millisecond)
Set milliseconds.void
setMinute(int minute)
Set minutes.void
setMonth(int month)
Set month.void
setSecond(int second)
Set seconds.void
setTimezone(int offset)
Set the number of minutes in the timezone offset.void
setYear(int year)
Set year of XSDdateTime
year field.void
setYear(java.math.BigInteger year)
Set low and high order component of XSDdateTime
year field.CalendarValue
toCalendarValue()
Convert this SaxonXMLGregorianCalendar to a Saxon CalendarValue objectjava.util.GregorianCalendar
toGregorianCalendar()
Convert thisXMLGregorianCalendar
to aGregorianCalendar
.java.util.GregorianCalendar
toGregorianCalendar(java.util.TimeZone timezone, java.util.Locale aLocale, javax.xml.datatype.XMLGregorianCalendar defaults)
Convert thisXMLGregorianCalendar
along with provided parameters to aGregorianCalendar
instance.java.lang.String
toXMLFormat()
Return the lexical representation ofthis
instance.
-
-
-
Constructor Detail
-
SaxonXMLGregorianCalendar
public SaxonXMLGregorianCalendar(CalendarValue value)
Create a SaxonXMLGregorianCalendar from a Saxon CalendarValue object- Parameters:
value
- the CalendarValue
-
-
Method Detail
-
setCalendarValue
public void setCalendarValue(CalendarValue value)
Set the calendar value of this object- Parameters:
value
- the calendar value
-
clear
public void clear()
Unset all fields to undefined.
Set all int fields to
DatatypeConstants.FIELD_UNDEFINED
and reference fields to null.- Specified by:
clear
in classjavax.xml.datatype.XMLGregorianCalendar
-
reset
public void reset()
Reset this
XMLGregorianCalendar
to its original values.Saxon does not attempt to reset to the initial value as defined in the specification of the superclass, because it cannot distinguish the initial setting from subsequent changes. This method is therefore synonymous with
clear()
- Specified by:
reset
in classjavax.xml.datatype.XMLGregorianCalendar
-
setYear
public void setYear(java.math.BigInteger year)
Set low and high order component of XSD
dateTime
year field.Unset this field by invoking the setter with a parameter value of
null
.- Specified by:
setYear
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
year
- value constraints summarized in year field of date/time field mapping table.- Throws:
java.lang.IllegalArgumentException
- ifyear
parameter is outside value constraints for the field as specified in date/time field mapping table.
-
setYear
public void setYear(int year)
Set year of XSD
dateTime
year field.Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.Note: if the absolute value of the
year
parameter is less than 10^9, the eon component of the XSD year field is set tonull
by this method.- Specified by:
setYear
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
year
- value constraints are summarized in year field of date/time field mapping table. If year isDatatypeConstants.FIELD_UNDEFINED
, then eon is set tonull
.
-
setMonth
public void setMonth(int month)
Set month.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.- Specified by:
setMonth
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
month
- value constraints summarized in month field of date/time field mapping table.- Throws:
java.lang.IllegalArgumentException
- ifmonth
parameter is outside value constraints for the field as specified in date/time field mapping table.
-
setDay
public void setDay(int day)
Set days in month.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.- Specified by:
setDay
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
day
- value constraints summarized in day field of date/time field mapping table.- Throws:
java.lang.IllegalArgumentException
- ifday
parameter is outside value constraints for the field as specified in date/time field mapping table.
-
setTimezone
public void setTimezone(int offset)
Set the number of minutes in the timezone offset.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.- Specified by:
setTimezone
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
offset
- value constraints summarized in timezone field of date/time field mapping table.- Throws:
java.lang.IllegalArgumentException
- ifoffset
parameter is outside value constraints for the field as specified in date/time field mapping table.
-
setHour
public void setHour(int hour)
Set hours.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.- Specified by:
setHour
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
hour
- value constraints summarized in hour field of date/time field mapping table.- Throws:
java.lang.IllegalArgumentException
- ifhour
parameter is outside value constraints for the field as specified in date/time field mapping table.
-
setMinute
public void setMinute(int minute)
Set minutes.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.- Specified by:
setMinute
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
minute
- value constraints summarized in minute field of date/time field mapping table.- Throws:
java.lang.IllegalArgumentException
- ifminute
parameter is outside value constraints for the field as specified in date/time field mapping table.
-
setSecond
public void setSecond(int second)
Set seconds.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.- Specified by:
setSecond
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
second
- value constraints summarized in second field of date/time field mapping table.- Throws:
java.lang.IllegalArgumentException
- ifsecond
parameter is outside value constraints for the field as specified in date/time field mapping table.
-
setMillisecond
public void setMillisecond(int millisecond)
Set milliseconds.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.- Specified by:
setMillisecond
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
millisecond
- value constraints summarized in millisecond field of date/time field mapping table.- Throws:
java.lang.IllegalArgumentException
- ifmillisecond
parameter is outside value constraints for the field as specified in date/time field mapping table.
-
setFractionalSecond
public void setFractionalSecond(java.math.BigDecimal fractional)
Set fractional seconds.
Unset this field by invoking the setter with a parameter value of
null
.- Specified by:
setFractionalSecond
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
fractional
- value constraints summarized in fractional field of date/time field mapping table.- Throws:
java.lang.IllegalArgumentException
- iffractional
parameter is outside value constraints for the field as specified in date/time field mapping table.
-
getEon
public java.math.BigInteger getEon()
Return high order component for XML Schema 1.0 dateTime datatype field for
year
.null
if this optional part of the year field is not defined.Value constraints for this value are summarized in year field of date/time field mapping table.
- Specified by:
getEon
in classjavax.xml.datatype.XMLGregorianCalendar
- Returns:
- eon of this
XMLGregorianCalendar
. The value returned is an integer multiple of 10^9. - See Also:
getYear()
,getEonAndYear()
-
getYear
public int getYear()
Return low order component for XML Schema 1.0 dateTime datatype field for
year
orDatatypeConstants.FIELD_UNDEFINED
.Value constraints for this value are summarized in year field of date/time field mapping table.
- Specified by:
getYear
in classjavax.xml.datatype.XMLGregorianCalendar
- Returns:
- year of this
XMLGregorianCalendar
. - See Also:
getEon()
,getEonAndYear()
-
getEonAndYear
public java.math.BigInteger getEonAndYear()
Return XML Schema 1.0 dateTime datatype field for
year
.Value constraints for this value are summarized in year field of date/time field mapping table.
-
getMonth
public int getMonth()
Return number of month or
DatatypeConstants.FIELD_UNDEFINED
.Value constraints for this value are summarized in month field of date/time field mapping table.
- Specified by:
getMonth
in classjavax.xml.datatype.XMLGregorianCalendar
- Returns:
- year of this
XMLGregorianCalendar
.
-
getDay
public int getDay()
Return day in month orDatatypeConstants.FIELD_UNDEFINED
.Value constraints for this value are summarized in day field of date/time field mapping table.
- Specified by:
getDay
in classjavax.xml.datatype.XMLGregorianCalendar
- See Also:
setDay(int)
-
getTimezone
public int getTimezone()
Return timezone offset in minutes orDatatypeConstants.FIELD_UNDEFINED
if this optional field is not defined.Value constraints for this value are summarized in timezone field of date/time field mapping table.
- Specified by:
getTimezone
in classjavax.xml.datatype.XMLGregorianCalendar
- See Also:
setTimezone(int)
-
getHour
public int getHour()
Return hours orDatatypeConstants.FIELD_UNDEFINED
. ReturnsDatatypeConstants.FIELD_UNDEFINED
if this field is not defined.Value constraints for this value are summarized in hour field of date/time field mapping table.
- Specified by:
getHour
in classjavax.xml.datatype.XMLGregorianCalendar
- See Also:
XMLGregorianCalendar.setTime(int, int, int)
-
getMinute
public int getMinute()
Return minutes orDatatypeConstants.FIELD_UNDEFINED
.Returns
DatatypeConstants.FIELD_UNDEFINED
if this field is not defined.Value constraints for this value are summarized in minute field of date/time field mapping table.
- Specified by:
getMinute
in classjavax.xml.datatype.XMLGregorianCalendar
- See Also:
XMLGregorianCalendar.setTime(int, int, int)
-
getSecond
public int getSecond()
Return seconds or
DatatypeConstants.FIELD_UNDEFINED
.Returns
DatatypeConstants.FIELD_UNDEFINED
if this field is not defined. When this field is not defined, the optional xs:dateTime fractional seconds field, represented bygetFractionalSecond()
andXMLGregorianCalendar.getMillisecond()
, must not be defined.Value constraints for this value are summarized in second field of date/time field mapping table.
- Specified by:
getSecond
in classjavax.xml.datatype.XMLGregorianCalendar
- Returns:
- Second of this
XMLGregorianCalendar
. - See Also:
getFractionalSecond()
,XMLGregorianCalendar.getMillisecond()
,XMLGregorianCalendar.setTime(int, int, int)
-
getMicrosecond
public int getMicrosecond()
Return microsecond precision of
getFractionalSecond()
.This method represents a convenience accessor to infinite precision fractional second value returned by
getFractionalSecond()
. The returned value is the rounded down to microseconds value ofgetFractionalSecond()
. WhengetFractionalSecond()
returnsnull
, this method must returnDatatypeConstants.FIELD_UNDEFINED
.Value constraints for this value are summarized in second field of date/time field mapping table.
- Returns:
- Millisecond of this
XMLGregorianCalendar
. - See Also:
getFractionalSecond()
,XMLGregorianCalendar.setTime(int, int, int)
-
getFractionalSecond
public java.math.BigDecimal getFractionalSecond()
Return fractional seconds.
null
is returned when this optional field is not defined.Value constraints are detailed in second field of date/time field mapping table.
This optional field can only have a defined value when the xs:dateTime second field, represented by
getSecond()
, does not returnDatatypeConstants.FIELD_UNDEFINED
.- Specified by:
getFractionalSecond
in classjavax.xml.datatype.XMLGregorianCalendar
- Returns:
- fractional seconds of this
XMLGregorianCalendar
. - See Also:
getSecond()
,XMLGregorianCalendar.setTime(int, int, int, java.math.BigDecimal)
-
compare
public int compare(javax.xml.datatype.XMLGregorianCalendar xmlGregorianCalendar)
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.
xsd:dateTime
datatype field mapping to accessors of this class are defined in date/time field mapping table.- Specified by:
compare
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
xmlGregorianCalendar
- Instance ofXMLGregorianCalendar
to compare- Returns:
- The relationship between
this
XMLGregorianCalendar
and the specifiedxmlGregorianCalendar
asDatatypeConstants.LESSER
,DatatypeConstants.EQUAL
,DatatypeConstants.GREATER
orDatatypeConstants.INDETERMINATE
. - Throws:
java.lang.NullPointerException
- ifxmlGregorianCalendar
is null.
-
normalize
public javax.xml.datatype.XMLGregorianCalendar normalize()
Normalize this instance to UTC.
2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z
Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).
- Specified by:
normalize
in classjavax.xml.datatype.XMLGregorianCalendar
- Returns:
- a copy of this
XMLGregorianCalendar
normalized to UTC.
-
toXMLFormat
public java.lang.String toXMLFormat()
Return the lexical representation of
this
instance. The format is specified in XML Schema 1.0 Part 2, Section 3.2.[7-14].1, Lexical Representation".Specific target lexical representation format is determined by
getXMLSchemaType()
.- Specified by:
toXMLFormat
in classjavax.xml.datatype.XMLGregorianCalendar
- Returns:
- XML, as
String
, representation of thisXMLGregorianCalendar
- Throws:
java.lang.IllegalStateException
- if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.
-
getXMLSchemaType
public javax.xml.namespace.QName getXMLSchemaType()
Return the name of the XML Schema date/time type that this instance maps to. Type is computed based on fields that are set.
- Specified by:
getXMLSchemaType
in classjavax.xml.datatype.XMLGregorianCalendar
- Returns:
- One of the following class constants:
DatatypeConstants.DATETIME
,DatatypeConstants.TIME
,DatatypeConstants.DATE
,DatatypeConstants.GYEARMONTH
,DatatypeConstants.GMONTHDAY
,DatatypeConstants.GYEAR
,DatatypeConstants.GMONTH
orDatatypeConstants.GDAY
. - Throws:
java.lang.IllegalStateException
- if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.
-
isValid
public boolean isValid()
Validate instance bygetXMLSchemaType()
constraints.- Specified by:
isValid
in classjavax.xml.datatype.XMLGregorianCalendar
- Returns:
- true if data values are valid.
-
add
public void add(javax.xml.datatype.Duration duration)
Add
duration
to this instance.The computation is specified in XML Schema 1.0 Part 2, Appendix E, Adding durations to dateTimes. date/time field mapping table defines the mapping from XML Schema 1.0
dateTime
fields to this class' representation of those fields.- Specified by:
add
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
duration
- Duration to add to thisXMLGregorianCalendar
.- Throws:
java.lang.NullPointerException
- whenduration
parameter isnull
.
-
toGregorianCalendar
public java.util.GregorianCalendar toGregorianCalendar()
Convert this
XMLGregorianCalendar
to aGregorianCalendar
.When
this
instance has an undefined field, this conversion relies on thejava.util.GregorianCalendar
default for its corresponding field. A notable difference between XML Schema 1.0 date/time datatypes andjava.util.GregorianCalendar
is that Timezone value is optional for date/time datatypes and it is a required field forjava.util.GregorianCalendar
. See javadoc forjava.util.TimeZone.getDefault()
on how the default is determined. To explicitly specify theTimeZone
instance, seetoGregorianCalendar(java.util.TimeZone, Locale, javax.xml.datatype.XMLGregorianCalendar)
.- Specified by:
toGregorianCalendar
in classjavax.xml.datatype.XMLGregorianCalendar
- See Also:
toGregorianCalendar(java.util.TimeZone, java.util.Locale, javax.xml.datatype.XMLGregorianCalendar)
-
toGregorianCalendar
public java.util.GregorianCalendar toGregorianCalendar(java.util.TimeZone timezone, java.util.Locale aLocale, javax.xml.datatype.XMLGregorianCalendar defaults)
Convert this
XMLGregorianCalendar
along with provided parameters to aGregorianCalendar
instance.Since XML Schema 1.0 date/time datetypes has no concept of timezone ids or daylight savings timezone ids, this conversion operation allows the user to explicitly specify one with
timezone
parameter.To compute the return value's
TimeZone
field:- when parameter
timeZone
is non-null, it is the timezone field. - else when
this.getTimezone() != FIELD_UNDEFINED
, create ajava.util.TimeZone
with a custom timezone id using thethis.getTimezone()
. - else when
defaults.getTimezone() != FIELD_UNDEFINED
, create ajava.util.TimeZone
with a custom timezone id usingdefaults.getTimezone()
. - else use the
GregorianCalendar
default timezone value for the host is defined as specified byjava.util.TimeZone.getDefault()
.
To ensure consistency in conversion implementations, the new
GregorianCalendar
should be instantiated in the following manner:- Create a new
java.util.GregorianCalendar(TimeZone, Locale)
with TimeZone set as specified above and theLocale
parameter. - Initialize all GregorianCalendar fields by calling
Calendar.clear()
- Obtain a pure Gregorian Calendar by invoking
GregorianCalendar.setGregorianChange( new Date(Long.MIN_VALUE))
. - Its fields ERA, YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY,
MINUTE, SECOND and MILLISECOND are set using the method
Calendar.set(int,int)
- Specified by:
toGregorianCalendar
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
timezone
- provide Timezone.null
is a legal value.aLocale
- provide explicit Locale. Use default GregorianCalendar locale if value isnull
.defaults
- provide default field values to use when corresponding field for this instance is FIELD_UNDEFINED or null. Ifdefaults
isnull
or a field within the specifieddefaults
is undefined, just usejava.util.GregorianCalendar
defaults.- Returns:
- a java.util.GregorianCalendar conversion of this instance.
- when parameter
-
getTimeZone
public java.util.TimeZone getTimeZone(int defaultZoneoffset)
Returns a
java.util.TimeZone
for this class.If timezone field is defined for this instance, returns TimeZone initialized with custom timezone id of zoneoffset. If timezone field is undefined, try the defaultZoneoffset that was passed in. If defaultZoneoffset is FIELD_UNDEFINED, return default timezone for this host. (Same default as java.util.GregorianCalendar).
- Specified by:
getTimeZone
in classjavax.xml.datatype.XMLGregorianCalendar
- Parameters:
defaultZoneoffset
- default zoneoffset if this zoneoffset isDatatypeConstants.FIELD_UNDEFINED
.- Returns:
- TimeZone for this.
-
clone
public java.lang.Object clone()
Creates and returns a copy of this object.
- Specified by:
clone
in classjavax.xml.datatype.XMLGregorianCalendar
- Returns:
- copy of this
Object
-
toCalendarValue
public CalendarValue toCalendarValue()
Convert this SaxonXMLGregorianCalendar to a Saxon CalendarValue object- Returns:
- the corresponding CalendarValue
-
-