summaryrefslogtreecommitdiff
path: root/javax/xml/datatype
diff options
context:
space:
mode:
Diffstat (limited to 'javax/xml/datatype')
-rw-r--r--javax/xml/datatype/DatatypeConfigurationException.java70
-rw-r--r--javax/xml/datatype/DatatypeConstants.java259
-rw-r--r--javax/xml/datatype/DatatypeFactory.java401
-rw-r--r--javax/xml/datatype/Duration.java295
-rw-r--r--javax/xml/datatype/XMLGregorianCalendar.java217
-rw-r--r--javax/xml/datatype/package.html57
6 files changed, 1299 insertions, 0 deletions
diff --git a/javax/xml/datatype/DatatypeConfigurationException.java b/javax/xml/datatype/DatatypeConfigurationException.java
new file mode 100644
index 000000000..154407988
--- /dev/null
+++ b/javax/xml/datatype/DatatypeConfigurationException.java
@@ -0,0 +1,70 @@
+/* DatatypeConfigurationException.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.datatype;
+
+/**
+ * A serious error during datatype configuration.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ * @since 1.3
+ */
+public class DatatypeConfigurationException
+ extends Exception
+{
+
+ public DatatypeConfigurationException()
+ {
+ super();
+ }
+
+ public DatatypeConfigurationException(String message)
+ {
+ super(message);
+ }
+
+ public DatatypeConfigurationException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public DatatypeConfigurationException(Throwable cause)
+ {
+ super(cause);
+ }
+
+}
diff --git a/javax/xml/datatype/DatatypeConstants.java b/javax/xml/datatype/DatatypeConstants.java
new file mode 100644
index 000000000..a761f88d5
--- /dev/null
+++ b/javax/xml/datatype/DatatypeConstants.java
@@ -0,0 +1,259 @@
+/* DatatypeConstants.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.datatype;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Basic data type constants.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ * @since 1.3
+ */
+public final class DatatypeConstants
+{
+
+ /**
+ * Typesafe enumerated class representing the six fields of the
+ * <a href='Duration.html'>Duration</a> class.
+ */
+ public static final class Field
+ {
+
+ final int id;
+ final String name;
+
+ Field(int id, String name)
+ {
+ this.id = id;
+ this.name = name;
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+
+ }
+
+ /**
+ * Value for January.
+ */
+ public static final int JANUARY = 1;
+
+ /**
+ * Value for February.
+ */
+ public static final int FEBRUARY = 2;
+
+ /**
+ * Value for March.
+ */
+ public static final int MARCH = 3;
+
+ /**
+ * Value for April.
+ */
+ public static final int APRIL = 4;
+
+ /**
+ * Value for May.
+ */
+ public static final int MAY = 5;
+
+ /**
+ * Value for June.
+ */
+ public static final int JUNE = 6;
+
+ /**
+ * Value for July.
+ */
+ public static final int JULY = 7;
+
+ /**
+ * Value for August.
+ */
+ public static final int AUGUST = 8;
+
+ /**
+ * Value for September.
+ */
+ public static final int SEPTEMBER = 9;
+
+ /**
+ * Value for October.
+ */
+ public static final int OCTOBER = 10;
+
+ /**
+ * Value for November.
+ */
+ public static final int NOVEMBER = 11;
+
+ /**
+ * Value for December.
+ */
+ public static final int DECEMBER = 12;
+
+ /**
+ * Comparison result.
+ */
+ public static final int LESSER = -1;
+
+ /**
+ * Comparison result.
+ */
+ public static final int EQUAL = 0;
+
+ /**
+ * Comparison result.
+ */
+ public static final int GREATER = 1;
+
+ /**
+ * Comparison result.
+ */
+ public static final int INDETERMINATE = 2;
+
+ /**
+ * Comparison result.
+ */
+ public static final int FIELD_UNDEFINED = -2147483648;
+
+ /**
+ * Constant that represents the years field.
+ */
+ public static final Field YEARS = new Field(1, "YEARS");
+
+ /**
+ * Constant that represents the months field.
+ */
+ public static final Field MONTHS = new Field(2, "MONTHS");
+
+ /**
+ * Constant that represents the days field.
+ */
+ public static final Field DAYS = new Field(3, "DAYS");
+
+ /**
+ * Constant that represents the hours field.
+ */
+ public static final Field HOURS = new Field(4, "HOURS");
+
+ /**
+ * Constant that represents the minutes field.
+ */
+ public static final Field MINUTES = new Field(5, "MINUTES");
+
+ /**
+ * Constant that represents the seconds field.
+ */
+ public static final Field SECONDS = new Field(6, "SECONDS");
+
+ /**
+ * The qualified-name for the <code>dateTime</code> data type.
+ */
+ public static final QName DATETIME = new QName ("http://www.w3.org/2001/XMLSchema#dateTime", "");
+
+ /**
+ * The qualified-name for the <code>time</code> data type.
+ */
+ public static final QName TIME = new QName ("http://www.w3.org/2001/XMLSchema#time", "");
+
+ /**
+ * The qualified-name for the <code>date</code> data type.
+ */
+ public static final QName DATE = new QName ("http://www.w3.org/2001/XMLSchema#date", "");
+
+ /**
+ * The qualified-name for the <code>gYearMonth</code> data type.
+ */
+ public static final QName GYEARMONTH = new QName ("http://www.w3.org/2001/XMLSchema#gYearMonth", "");
+
+ /**
+ * The qualified-name for the <code>gMonthDay</code> data type.
+ */
+ public static final QName GMONTHDAY = new QName ("http://www.w3.org/2001/XMLSchema#gMonthDay", "");
+
+ /**
+ * The qualified-name for the <code>gYear</code> data type.
+ */
+ public static final QName GYEAR = new QName ("http://www.w3.org/2001/XMLSchema#gYear", "");
+
+ /**
+ * The qualified-name for the <code>gMonth</code> data type.
+ */
+ public static final QName GMONTH = new QName ("http://www.w3.org/2001/XMLSchema#gMonth", "");
+
+ /**
+ * The qualified-name for the <code>gDay</code> data type.
+ */
+ public static final QName GDAY = new QName ("http://www.w3.org/2001/XMLSchema#gDay", "");
+
+ /**
+ * The qualified-name for the <code>duration</code> data type.
+ */
+ public static final QName DURATION = new QName ("http://www.w3.org/2001/XMLSchema#duration", "");
+
+ /**
+ * The qualified-name for the <code>dayTimeDuration</code> data type.
+ */
+ public static final QName DURATION_DAYTIME = new QName ("http://www.w3.org/2001/XMLSchema#dayTimeDuration", "");
+
+ /**
+ * The qualified-name for the <code>yearMonthDuration</code> data type.
+ */
+ public static final QName DURATION_YEARMONTH = new QName ("http://www.w3.org/2001/XMLSchema#yearMonthDuration", "");
+
+ /**
+ * XML Schema maximum timezone offset, in minutes.
+ */
+ public static final int MAX_TIMEZONE_OFFSET = -840;
+
+ /**
+ * XML Schema minimum timezone offset, in minutes.
+ */
+ public static final int MIN_TIMEZONE_OFFSET = 840;
+
+}
diff --git a/javax/xml/datatype/DatatypeFactory.java b/javax/xml/datatype/DatatypeFactory.java
new file mode 100644
index 000000000..2299435fc
--- /dev/null
+++ b/javax/xml/datatype/DatatypeFactory.java
@@ -0,0 +1,401 @@
+/* DatatypeFactory.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.datatype;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.GregorianCalendar;
+
+/**
+ * Factory class to create new datatype objects mapping XML to and from Java
+ * objects.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ * @since 1.3
+ */
+public abstract class DatatypeFactory
+{
+
+ /**
+ * JAXP 1.3 default property name.
+ */
+ public static final String DATATYPEFACTORY_PROPERTY = "javax.xml.datatype.DatatypeFactory";
+
+ /**
+ * JAXP 1.3 default implementation class name.
+ */
+ public static final java.lang.String DATATYPEFACTORY_IMPLEMENTATION_CLASS = "gnu.xml.datatype.JAXPDatatypeFactory";
+
+ protected DatatypeFactory()
+ {
+ }
+
+ /**
+ * Returns a new factory instance.
+ */
+ public static DatatypeFactory newInstance()
+ throws DatatypeConfigurationException
+ {
+ try
+ {
+ Class t = Class.forName(DATATYPEFACTORY_IMPLEMENTATION_CLASS);
+ return (DatatypeFactory) t.newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new DatatypeConfigurationException (e);
+ }
+ }
+
+ /**
+ * Returns a new duration from its string representation.
+ * @param lexicalRepresentation the lexical representation of the
+ * duration, as specified in XML Schema 1.0 section 3.2.6.1.
+ */
+ public abstract Duration newDuration(String lexicalRepresentation);
+
+ /**
+ * Returns a new duration.
+ * @param durationInMilliseconds the duration in milliseconds
+ */
+ public abstract Duration newDuration(long durationInMilliSeconds);
+
+ /**
+ * Returns a new duration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param years the number of years
+ * @param months the number of months
+ * @param days the number of days
+ * @param hours the number of hours
+ * @param minutes th number of minutes
+ * @param seconds the number of seconds
+ */
+ public abstract Duration newDuration(boolean isPositive,
+ BigInteger years,
+ BigInteger months,
+ BigInteger days,
+ BigInteger hours,
+ BigInteger minutes,
+ BigDecimal seconds);
+
+ /**
+ * Returns a new duration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param years the number of years
+ * @param months the number of months
+ * @param days the number of days
+ * @param hours the number of hours
+ * @param minutes th number of minutes
+ * @param seconds the number of seconds
+ */
+ public Duration newDuration(boolean isPositive,
+ int years,
+ int months,
+ int days,
+ int hours,
+ int minutes,
+ int seconds)
+ {
+ return newDuration(isPositive,
+ BigInteger.valueOf((long) years),
+ BigInteger.valueOf((long) months),
+ BigInteger.valueOf((long) days),
+ BigInteger.valueOf((long) hours),
+ BigInteger.valueOf((long) minutes),
+ BigDecimal.valueOf((long) seconds));
+ }
+
+ /**
+ * Returns a new dayTimeDuration from its string representation.
+ * @param lexicalRepresentation the lexical representation of the
+ * duration, as specified in XML Schema 1.0 section 3.2.6.1.
+ */
+ public Duration newDurationDayTime(String lexicalRepresentation)
+ {
+ return newDuration(lexicalRepresentation);
+ }
+
+ /**
+ * Returns a new dayTimeDuration.
+ * @param durationInMilliseconds the duration in milliseconds
+ */
+ public Duration newDurationDayTime(long durationInMilliseconds)
+ {
+ // TODO xmlSchemaType
+ return newDuration(durationInMilliseconds);
+ }
+
+ /**
+ * Returns a new dayTimeDuration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param days the number of days
+ * @param hours the number of hours
+ * @param minutes th number of minutes
+ * @param seconds the number of seconds
+ */
+ public Duration newDurationDayTime(boolean isPositive,
+ BigInteger days,
+ BigInteger hours,
+ BigInteger minutes,
+ BigDecimal seconds)
+ {
+ return newDuration(isPositive,
+ null,
+ null,
+ days,
+ hours,
+ minutes,
+ seconds);
+ }
+
+ /**
+ * Returns a new dayTimeDuration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param days the number of days
+ * @param hours the number of hours
+ * @param minutes th number of minutes
+ * @param seconds the number of seconds
+ */
+ public Duration newDurationDayTime(boolean isPositive,
+ int days,
+ int hours,
+ int minutes,
+ int seconds)
+ {
+ return newDuration(isPositive,
+ null,
+ null,
+ BigInteger.valueOf((long) days),
+ BigInteger.valueOf((long) hours),
+ BigInteger.valueOf((long) minutes),
+ BigDecimal.valueOf((long) seconds));
+ }
+
+ /**
+ * Returns a new yearMonthDuration from its string representation.
+ * @param lexicalRepresentation the lexical representation of the
+ * duration, as specified in XML Schema 1.0 section 3.2.6.1.
+ */
+ public Duration newDurationYearMonth(String lexicalRepresentation)
+ {
+ return newDuration(lexicalRepresentation);
+ }
+
+ /**
+ * Returns a new yearMonthDuration.
+ * @param durationInMilliseconds the duration in milliseconds
+ */
+ public Duration newDurationYearMonth(long durationInMilliseconds)
+ {
+ // TODO xmlSchemaType
+ return newDuration(durationInMilliseconds);
+ }
+
+ /**
+ * Returns a new yearMonthDuration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param years the number of years
+ * @param months the number of months
+ * @param days the number of days
+ * @param hours the number of hours
+ * @param minutes th number of minutes
+ * @param seconds the number of seconds
+ */
+ public Duration newDurationYearMonth(boolean isPositive,
+ BigInteger years,
+ BigInteger months)
+ {
+ return newDuration(isPositive,
+ years,
+ months,
+ null,
+ null,
+ null,
+ null);
+ }
+
+ /**
+ * Returns a new yearMonthDuration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param years the number of years
+ * @param months the number of months
+ * @param days the number of days
+ * @param hours the number of hours
+ * @param minutes th number of minutes
+ * @param seconds the number of seconds
+ */
+ public Duration newDurationYearMonth(boolean isPositive,
+ int years,
+ int months)
+ {
+ return newDuration(isPositive,
+ BigInteger.valueOf((long) years),
+ BigInteger.valueOf((long) months),
+ null,
+ null,
+ null,
+ null);
+ }
+
+ /**
+ * Returns a new XMLGregorianCalendar with no fields initialized.
+ */
+ public abstract XMLGregorianCalendar newXMLGregorianCalendar();
+
+ /**
+ * Returns a new XMLGregorianCalendar from a string representation.
+ * @param lexicalRepresentation the lexical representation as specified in
+ * XML Schema 1.0 Part 2, section 3.2.[7-14].1.
+ */
+ public abstract XMLGregorianCalendar newXMLGregorianCalendar(String lexicalRepresentation);
+
+ /**
+ * Returns a new XMLGregorianCalendar based on the specified Gregorian
+ * calendar.
+ */
+ public abstract XMLGregorianCalendar newXMLGregorianCalendar(GregorianCalendar cal);
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public abstract XMLGregorianCalendar newXMLGregorianCalendar(BigInteger year,
+ int month,
+ int day,
+ int hour,
+ int minute,
+ int second,
+ BigDecimal fractionalSecond,
+ int timezone);
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public XMLGregorianCalendar newXMLGregorianCalendar(int year,
+ int month,
+ int day,
+ int hour,
+ int minute,
+ int second,
+ int millisecond,
+ int timezone)
+ {
+ return newXMLGregorianCalendar(BigInteger.valueOf((long) year),
+ month,
+ day,
+ hour,
+ minute,
+ second,
+ new BigDecimal(((double) millisecond) / 1000.0),
+ timezone);
+ }
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public XMLGregorianCalendar newXMLGregorianCalendarDate(int year,
+ int month,
+ int day,
+ int timezone)
+ {
+ return newXMLGregorianCalendar(BigInteger.valueOf((long) year),
+ month,
+ day,
+ DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED,
+ null,
+ timezone);
+ }
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
+ int minutes,
+ int seconds,
+ int timezone)
+ {
+ return newXMLGregorianCalendar(null,
+ DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED,
+ hours,
+ minutes,
+ seconds,
+ null,
+ timezone);
+ }
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
+ int minutes,
+ int seconds,
+ BigDecimal fractionalSecond,
+ int timezone)
+ {
+ return newXMLGregorianCalendar(null,
+ DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED,
+ hours,
+ minutes,
+ seconds,
+ fractionalSecond,
+ timezone);
+ }
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
+ int minutes,
+ int seconds,
+ int milliseconds,
+ int timezone)
+ {
+ return newXMLGregorianCalendar(null,
+ DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED,
+ hours,
+ minutes,
+ seconds,
+ new BigDecimal(((double) milliseconds) / 1000.0),
+ timezone);
+ }
+
+}
diff --git a/javax/xml/datatype/Duration.java b/javax/xml/datatype/Duration.java
new file mode 100644
index 000000000..ed1221dbf
--- /dev/null
+++ b/javax/xml/datatype/Duration.java
@@ -0,0 +1,295 @@
+/* Duration.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.datatype;
+
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import javax.xml.datatype.DatatypeConstants;
+import javax.xml.namespace.QName;
+
+/**
+ * An immutable time space as specified in XML Schema 1.0.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ * @since 1.3
+ */
+public abstract class Duration
+{
+
+ /**
+ * Returns the name of the XML Schema data type this value maps to.
+ */
+ public QName getXMLSchemaType()
+ {
+ int state = 0;
+ state |= isSet(DatatypeConstants.YEARS) ? 32 : 0;
+ state |= isSet(DatatypeConstants.MONTHS) ? 16 : 0;
+ state |= isSet(DatatypeConstants.DAYS) ? 8 : 0;
+ state |= isSet(DatatypeConstants.HOURS) ? 4 : 0;
+ state |= isSet(DatatypeConstants.MINUTES) ? 2 : 0;
+ state |= isSet(DatatypeConstants.SECONDS) ? 1 : 0;
+ switch (state)
+ {
+ case 63:
+ return DatatypeConstants.DURATION;
+ case 15:
+ return DatatypeConstants.DURATION_DAYTIME;
+ case 48:
+ return DatatypeConstants.DURATION_YEARMONTH;
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
+ /**
+ * Returns the sign of this value.
+ */
+ public abstract int getSign();
+
+ /**
+ * Returns the years in this duration as an int, or 0 if not present.
+ */
+ public int getYears()
+ {
+ Number val = getField(DatatypeConstants.YEARS);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the months in this duration as an int, or 0 if not present.
+ */
+ public int getMonths()
+ {
+ Number val = getField(DatatypeConstants.MONTHS);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the days in this duration as an int, or 0 if not present.
+ */
+ public int getDays()
+ {
+ Number val = getField(DatatypeConstants.DAYS);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the hours in this duration as an int, or 0 if not present.
+ */
+ public int getHours()
+ {
+ Number val = getField(DatatypeConstants.HOURS);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the minutes in this duration as an int, or 0 if not present.
+ */
+ public int getMinutes()
+ {
+ Number val = getField(DatatypeConstants.MINUTES);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the seconds in this duration as an int, or 0 if not present.
+ */
+ public int getSeconds()
+ {
+ Number val = getField(DatatypeConstants.SECONDS);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the duration length in milliseconds.
+ * Because the length of a month or year may vary depending on the year,
+ * the <code>startInstant</code> parameter is used to specify the duration
+ * offset.
+ */
+ public long getTimeInMillis(Calendar startInstant)
+ {
+ Calendar cal = (Calendar) startInstant.clone();
+ long t1 = cal.getTimeInMillis();
+ addTo(cal);
+ long t2 = cal.getTimeInMillis();
+ return t2 - t1;
+ }
+
+ /**
+ * Returns the duration length in milliseconds.
+ * Because the length of a month or year may vary depending on the year,
+ * the <code>startInstant</code> parameter is used to specify the duration
+ * offset.
+ */
+ public long getTimeInMillis(Date startInstant)
+ {
+ Date date = (Date) startInstant.clone();
+ long t1 = date.getTime();
+ addTo(date);
+ long t2 = date.getTime();
+ return t2 - t1;
+ }
+
+ /**
+ * Returns the value of the specified field, or <code>null</code> if the
+ * field is undefined.
+ */
+ public abstract Number getField(DatatypeConstants.Field field);
+
+ /**
+ * Indicates whether the specified field is set.
+ */
+ public abstract boolean isSet(DatatypeConstants.Field field);
+
+ /**
+ * Returns the result of adding the specified duration to this duration.
+ */
+ public abstract Duration add(Duration rhs);
+
+ /**
+ * Adds this duration to the specified calendar.
+ */
+ public abstract void addTo(Calendar calendar);
+ /*{
+ switch (getSign())
+ {
+ case -1:
+ calendar.add(Calendar.YEAR, -getYears());
+ calendar.add(Calendar.MONTH, -getMonths());
+ calendar.add(Calendar.DATE, -getDays());
+ calendar.add(Calendar.HOUR, -getHours());
+ calendar.add(Calendar.MINUTE, -getMinutes());
+ calendar.add(Calendar.SECOND, -getSeconds());
+ break;
+ case 1:
+ calendar.add(Calendar.YEAR, getYears());
+ calendar.add(Calendar.MONTH, getMonths());
+ calendar.add(Calendar.DATE, getDays());
+ calendar.add(Calendar.HOUR, getHours());
+ calendar.add(Calendar.MINUTE, getMinutes());
+ calendar.add(Calendar.SECOND, getSeconds());
+ }
+ }*/
+
+ /**
+ * Adds this duration to the specified date.
+ */
+ public void addTo(Date date)
+ {
+ Calendar calendar = new GregorianCalendar();
+ calendar.setTimeInMillis(date.getTime());
+ addTo(calendar);
+ date.setTime(calendar.getTimeInMillis());
+ }
+
+ /**
+ * Returns the result of subtracting the given duration from this
+ * duration.
+ */
+ public Duration subtract(Duration rhs)
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Returns the result of multiplying this duration by the given factor.
+ */
+ public Duration multiply(int factor)
+ {
+ return multiply(BigDecimal.valueOf((long) factor));
+ }
+
+ /**
+ * Returns the result of multiplying this duration by the given factor.
+ */
+ public Duration multiply(BigDecimal factor)
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Returns the unary negative of this duration.
+ */
+ public abstract Duration negate();
+
+ /**
+ * Converts the years and months fields into the days field using a
+ * specific time instant as the reference point.
+ */
+ public abstract Duration normalizeWith(Calendar startTimeInstant);
+
+ /**
+ * Partial order relation comparison with this duration, in accordance
+ * with XML Schema 1.0 Part 2, Section 3.2.7.6.2.
+ */
+ public abstract int compare(Duration duration);
+
+ public boolean isLongerThan(Duration duration)
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isShorterThan(Duration duration)
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean equals(java.lang.Object duration)
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public abstract int hashCode();
+
+ /**
+ * Returns the lexical representation of this duration.
+ */
+ public String toString()
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/javax/xml/datatype/XMLGregorianCalendar.java b/javax/xml/datatype/XMLGregorianCalendar.java
new file mode 100644
index 000000000..c3585a489
--- /dev/null
+++ b/javax/xml/datatype/XMLGregorianCalendar.java
@@ -0,0 +1,217 @@
+/* XMLGregorianCalendar.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.datatype;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+import javax.xml.namespace.QName;
+
+/**
+ * An XML Schema 1.0 date/time data type.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ * @since 1.3
+ */
+public abstract class XMLGregorianCalendar
+ implements Cloneable
+{
+
+ /**
+ * Resets all fields to undefined.
+ */
+ public abstract void clear();
+
+ /**
+ * Resets all fields to their original values.
+ */
+ public abstract void reset();
+
+ public abstract void setYear(BigInteger year);
+
+ public abstract void setYear(int year);
+
+ public abstract void setMonth(int month);
+
+ public abstract void setDay(int day);
+
+ public abstract void setTimezone(int offset);
+
+ public void setTime(int hour, int minute, int second)
+ {
+ setHour(hour);
+ setMinute(minute);
+ setSecond(second);
+ }
+
+ public abstract void setHour(int hour);
+
+ public abstract void setMinute(int minute);
+
+ public abstract void setSecond(int second);
+
+ public abstract void setMillisecond(int millisecond);
+
+ public abstract void setFractionalSecond(BigDecimal fractional);
+
+ public void setTime(int hour, int minute, int second, BigDecimal fractional)
+ {
+ setHour(hour);
+ setMinute(minute);
+ setSecond(second);
+ setFractionalSecond(fractional);
+ }
+
+ public void setTime(int hour, int minute, int second, int millisecond)
+ {
+ setHour(hour);
+ setMinute(minute);
+ setSecond(second);
+ setMillisecond(millisecond);
+ }
+
+ public abstract BigInteger getEon();
+
+ public abstract int getYear();
+
+ public abstract BigInteger getEonAndYear();
+
+ public abstract int getMonth();
+
+ public abstract int getDay();
+
+ public abstract int getTimezone();
+
+ public abstract int getHour();
+
+ public abstract int getMinute();
+
+ public abstract int getSecond();
+
+ public int getMillisecond()
+ {
+ BigDecimal factor = BigDecimal.valueOf(1000L);
+ BigDecimal val = getFractionalSecond().multiply(factor);
+ return val.intValue();
+ }
+
+ public abstract BigDecimal getFractionalSecond();
+
+ public abstract int compare(XMLGregorianCalendar xmlGregorianCalendar);
+
+ public abstract XMLGregorianCalendar normalize();
+
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof XMLGregorianCalendar)
+ {
+ XMLGregorianCalendar xgc = (XMLGregorianCalendar) obj;
+ BigInteger y1 = getEonAndYear();
+ BigInteger y2 = xgc.getEonAndYear();
+ BigDecimal f1 = getFractionalSecond();
+ BigDecimal f2 = xgc.getFractionalSecond();
+ return ((y1 == null && y2 == null) || (y1 != null && y1.equals(y2))) &&
+ getMonth() == xgc.getMonth() &&
+ getDay() == xgc.getDay() &&
+ getTimezone() == xgc.getTimezone() &&
+ getHour() == xgc.getHour() &&
+ getMinute() == xgc.getMinute() &&
+ getSecond() == xgc.getSecond() &&
+ ((f1 == null && f2 == null) || (f1 != null && f1.equals(f2)));
+ }
+ return false;
+ }
+
+ public int hashCode()
+ {
+ int hash = 0;
+ BigInteger y = getEonAndYear();
+ BigDecimal f = getFractionalSecond();
+ if (y != null)
+ {
+ hash *= 31 + y.hashCode();
+ }
+ hash *= 31 + getMonth();
+ hash *= 31 + getDay();
+ hash *= 31 + getTimezone();
+ hash *= 31 + getHour();
+ hash *= 31 + getMinute();
+ hash *= 31 + getSecond();
+ if (f != null)
+ {
+ hash *= 31 + f.hashCode();
+ }
+ return hash;
+ }
+
+ /**
+ * Returns the XML Schema lexical representation of this calendar.
+ */
+ public abstract String toXMLFormat();
+
+ public abstract QName getXMLSchemaType();
+
+ public String toString()
+ {
+ return toXMLFormat();
+ }
+
+ /**
+ * Determines the validity of this calendar by
+ * <code>getXMLSchemaType</code> constraints.
+ */
+ public abstract boolean isValid();
+
+ /**
+ * Adds the specified duration to this calendar.
+ */
+ public abstract void add(Duration duration);
+
+ public abstract GregorianCalendar toGregorianCalendar();
+
+ public abstract GregorianCalendar toGregorianCalendar(TimeZone timezone,
+ Locale locale,
+ XMLGregorianCalendar defaults);
+
+ public abstract TimeZone getTimeZone(int defaultZoneoffset);
+
+ public abstract Object clone();
+
+}
diff --git a/javax/xml/datatype/package.html b/javax/xml/datatype/package.html
new file mode 100644
index 000000000..ffd850c04
--- /dev/null
+++ b/javax/xml/datatype/package.html
@@ -0,0 +1,57 @@
+<body>
+
+<div>
+This package provides type mappings between XML and Java data types.
+</div>
+
+<table summary='XML Schema type mappings'>
+ <tr>
+ <th>XML Schema data type</th><th>Java data type</th>
+ </tr>
+ <tr>
+ <td>xs:date</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:dateTime</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:duration</td><td><a href='Duration.html'>Duration</a></td>
+ </tr>
+ <tr>
+ <td>xs:gDay</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:gMonth</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:gMonthDay</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:gYear</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:gYearMonth</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:time</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+</table>
+
+<table summary='XPath 2.0 data type mappings'>
+ <tr>
+ <th>XPath 2.0 data type</th><th>Java data type</th>
+ </tr>
+ <tr>
+ <td>xdt:dayTimeDuration</td><td><a href='Duration.html'>Duration</a></td>
+ </tr>
+ <tr>
+ <td>xdt:yearMonthDuration</td><td><a href='Duration.html'>Duration</a></td>
+ </tr>
+</table>
+
+<div>
+Other XML Schema data types are considered to have a <q>natural</q> mapping to
+Java types, which are defined by the Java Architecture for XML Binding (JAXB).
+</div>
+
+</body>