001    /* XMLGregorianCalendar.java -- 
002       Copyright (C) 2004, 2005  Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    package javax.xml.datatype;
039    
040    import java.math.BigDecimal;
041    import java.math.BigInteger;
042    import java.util.GregorianCalendar;
043    import java.util.Locale;
044    import java.util.TimeZone;
045    import javax.xml.namespace.QName;
046    
047    /**
048     * An XML Schema 1.0 date/time data type.
049     *
050     * @author (a href='mailto:dog@gnu.org'>Chris Burdess</a)
051     * @since 1.3
052     */
053    public abstract class XMLGregorianCalendar
054      implements Cloneable
055    {
056    
057      /**
058       * Resets all fields to undefined.
059       */
060      public abstract void clear();
061    
062      /**
063       * Resets all fields to their original values.
064       */
065      public abstract void reset();
066    
067      public abstract void setYear(BigInteger year);
068    
069      public abstract void setYear(int year);
070    
071      public abstract void setMonth(int month);
072    
073      public abstract void setDay(int day);
074    
075      public abstract void setTimezone(int offset);
076    
077      public void setTime(int hour, int minute, int second)
078      {
079        setHour(hour);
080        setMinute(minute);
081        setSecond(second);
082      }
083    
084      public abstract void setHour(int hour);
085    
086      public abstract void setMinute(int minute);
087    
088      public abstract void setSecond(int second);
089    
090      public abstract void setMillisecond(int millisecond);
091    
092      public abstract void setFractionalSecond(BigDecimal fractional);
093    
094      public void setTime(int hour, int minute, int second, BigDecimal fractional)
095      {
096        setHour(hour);
097        setMinute(minute);
098        setSecond(second);
099        setFractionalSecond(fractional);
100      }
101    
102      public void setTime(int hour, int minute, int second, int millisecond)
103      {
104        setHour(hour);
105        setMinute(minute);
106        setSecond(second);
107        setMillisecond(millisecond);
108      }
109    
110      public abstract BigInteger getEon();
111    
112      public abstract int getYear();
113    
114      public abstract BigInteger getEonAndYear();
115    
116      public abstract int getMonth();
117    
118      public abstract int getDay();
119    
120      public abstract int getTimezone();
121    
122      public abstract int getHour();
123    
124      public abstract int getMinute();
125    
126      public abstract int getSecond();
127    
128      public int getMillisecond()
129      {
130        BigDecimal factor = BigDecimal.valueOf(1000L);
131        BigDecimal val = getFractionalSecond().multiply(factor);
132        return val.intValue();
133      }
134    
135      public abstract BigDecimal getFractionalSecond();
136    
137      public abstract int compare(XMLGregorianCalendar xmlGregorianCalendar);
138    
139      public abstract XMLGregorianCalendar normalize();
140    
141      public boolean equals(Object obj)
142      {
143        if (obj instanceof XMLGregorianCalendar)
144          {
145            XMLGregorianCalendar xgc = (XMLGregorianCalendar) obj;
146            BigInteger y1 = getEonAndYear();
147            BigInteger y2 = xgc.getEonAndYear();
148            BigDecimal f1 = getFractionalSecond();
149            BigDecimal f2 = xgc.getFractionalSecond();
150            return ((y1 == null && y2 == null) || (y1 != null && y1.equals(y2))) &&
151              getMonth() == xgc.getMonth() &&
152              getDay() == xgc.getDay() &&
153              getTimezone() == xgc.getTimezone() &&
154              getHour() == xgc.getHour() &&
155              getMinute() == xgc.getMinute() &&
156              getSecond() == xgc.getSecond() &&
157              ((f1 == null && f2 == null) || (f1 != null && f1.equals(f2)));
158          }
159        return false;
160      }
161    
162      public int hashCode()
163      {
164        int hash = 0;
165        BigInteger y = getEonAndYear();
166        BigDecimal f = getFractionalSecond();
167        if (y != null)
168          {
169            hash *= 31 + y.hashCode();
170          }
171        hash *= 31 + getMonth();
172        hash *= 31 + getDay();
173        hash *= 31 + getTimezone();
174        hash *= 31 + getHour();
175        hash *= 31 + getMinute();
176        hash *= 31 + getSecond();
177        if (f != null)
178          {
179            hash *= 31 + f.hashCode();
180          }
181        return hash;
182      }
183    
184      /**
185       * Returns the XML Schema lexical representation of this calendar.
186       */
187      public abstract String toXMLFormat();
188    
189      public abstract QName getXMLSchemaType();
190    
191      public String toString()
192      {
193        return toXMLFormat();
194      }
195    
196      /**
197       * Determines the validity of this calendar by
198       * <code>getXMLSchemaType</code> constraints.
199       */
200      public abstract boolean isValid();
201    
202      /**
203       * Adds the specified duration to this calendar.
204       */
205      public abstract void add(Duration duration);
206    
207      public abstract GregorianCalendar toGregorianCalendar();
208    
209      public abstract GregorianCalendar toGregorianCalendar(TimeZone timezone,
210                                                            Locale locale,
211                                                            XMLGregorianCalendar defaults);
212    
213      public abstract TimeZone getTimeZone(int defaultZoneoffset);
214    
215      public abstract Object clone();
216      
217    }