Source for java.sql.Time

   1: /* Time.java -- Wrapper around java.util.Date
   2:    Copyright (C) 1999, 2000, 2002, 2003, 2005, 2006
   3:    Free Software Foundation, Inc.
   4: 
   5: This file is part of GNU Classpath.
   6: 
   7: GNU Classpath is free software; you can redistribute it and/or modify
   8: it under the terms of the GNU General Public License as published by
   9: the Free Software Foundation; either version 2, or (at your option)
  10: any later version.
  11: 
  12: GNU Classpath is distributed in the hope that it will be useful, but
  13: WITHOUT ANY WARRANTY; without even the implied warranty of
  14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15: General Public License for more details.
  16: 
  17: You should have received a copy of the GNU General Public License
  18: along with GNU Classpath; see the file COPYING.  If not, write to the
  19: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20: 02110-1301 USA.
  21: 
  22: Linking this library statically or dynamically with other modules is
  23: making a combined work based on this library.  Thus, the terms and
  24: conditions of the GNU General Public License cover the whole
  25: combination.
  26: 
  27: As a special exception, the copyright holders of this library give you
  28: permission to link this library with independent modules to produce an
  29: executable, regardless of the license terms of these independent
  30: modules, and to copy and distribute the resulting executable under
  31: terms of your choice, provided that you also meet, for each linked
  32: independent module, the terms and conditions of the license of that
  33: module.  An independent module is a module which is not derived from
  34: or based on this library.  If you modify this library, you may extend
  35: this exception to your version of the library, but you are not
  36: obligated to do so.  If you do not wish to do so, delete this
  37: exception statement from your version. */
  38: 
  39: 
  40: package java.sql;
  41: 
  42: import java.text.ParseException;
  43: import java.text.SimpleDateFormat;
  44: 
  45: /**
  46:  * This class is a wrapper around java.util.Date to allow the JDBC
  47:  * driver to identify the value as a SQL Time.
  48:  *
  49:  * @author Aaron M. Renn (arenn@urbanophile.com)
  50:  */
  51: public class Time extends java.util.Date
  52: {
  53:   static final long serialVersionUID = 8397324403548013681L;
  54: 
  55:   /**
  56:    * Used for parsing and formatting this date.
  57:    */
  58:   private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
  59: 
  60:   /**
  61:    * This method always throws an IllegalArgumentException.
  62:    *
  63:    * @throws IllegalArgumentException when it's called.
  64:    * @deprecated
  65:    */
  66:   public int getDate() throws IllegalArgumentException
  67:   {
  68:     throw new IllegalArgumentException();
  69:   }
  70: 
  71:   /**
  72:    * This method always throws an IllegalArgumentException.
  73:    *
  74:    * @throws IllegalArgumentException when it's called.
  75:    * @deprecated
  76:    */
  77:   public int getDay() throws IllegalArgumentException
  78:   {
  79:     throw new IllegalArgumentException();
  80:   }
  81: 
  82:   /**
  83:    * This method always throws an IllegalArgumentException.
  84:    *
  85:    * @throws IllegalArgumentException when it's called.
  86:    * @deprecated
  87:    */
  88:   public int getMonth() throws IllegalArgumentException
  89:   {
  90:     throw new IllegalArgumentException();
  91:   }
  92: 
  93:   /**
  94:    * This method always throws an IllegalArgumentException.
  95:    *
  96:    * @throws IllegalArgumentException when it's called.
  97:    * @deprecated
  98:    */
  99:   public int getYear() throws IllegalArgumentException
 100:   {
 101:     throw new IllegalArgumentException();
 102:   }
 103: 
 104:   /**
 105:    * This method always throws an IllegalArgumentException.
 106:    *
 107:    * @throws IllegalArgumentException when it's called.
 108:    * @deprecated
 109:    */
 110:   public void setDate(int newValue) throws IllegalArgumentException
 111:   {
 112:     throw new IllegalArgumentException();
 113:   }
 114: 
 115:   /**
 116:    * This method always throws an IllegalArgumentException.
 117:    *
 118:    * @throws IllegalArgumentException when it's called.
 119:    * @deprecated
 120:    */
 121:   public void setMonth(int newValue) throws IllegalArgumentException
 122:   {
 123:     throw new IllegalArgumentException();
 124:   }
 125: 
 126:   /**
 127:    * This method always throws an IllegalArgumentException.
 128:    *
 129:    * @throws IllegalArgumentException when it's called.
 130:    * @deprecated
 131:    */
 132:   public void setYear(int newValue) throws IllegalArgumentException
 133:   {
 134:     throw new IllegalArgumentException();
 135:   }
 136: 
 137:   /**
 138:    * This method returns a new instance of this class by parsing a
 139:    * date in JDBC format into a Java date.
 140:    *
 141:    * @param str The string to parse.
 142:    * @return The resulting <code>java.sql.Time</code> value.
 143:    */
 144:   public static Time valueOf (String str)
 145:   {
 146:     try
 147:       {
 148:         java.util.Date d = (java.util.Date) sdf.parseObject(str);
 149: 
 150:         if (d == null)
 151:           throw new IllegalArgumentException(str);
 152:         else
 153:           return new Time(d.getTime());
 154:       }
 155:     catch (ParseException e)
 156:       {
 157:         throw new IllegalArgumentException(str);
 158:       }
 159:   }
 160: 
 161:   /**
 162:     * This method initializes a new instance of this class with the
 163:     * specified year, month, and day.
 164:     *
 165:     * @param hour The hour for this Time (0-23)
 166:     * @param minute The minute for this time (0-59)
 167:     * @param second The second for this time (0-59)
 168:     * @deprecated
 169:     */
 170:   public Time(int hour, int minute, int second)
 171:   {
 172:     super(System.currentTimeMillis());
 173: 
 174:     setHours(hour);
 175:     setMinutes(minute);
 176:     setSeconds(second);
 177:   }
 178: 
 179:   /**
 180:    * This method initializes a new instance of this class with the
 181:    * specified time value representing the number of milliseconds since
 182:    * Jan 1, 1970 at 12:00 midnight GMT.
 183:    *
 184:    * @param date The time value to intialize this <code>Time</code> to.
 185:    */
 186:   public Time(long date)
 187:   {
 188:     super(date);
 189:   }
 190: 
 191:   /**
 192:    * This method returns this date in JDBC format.
 193:    *
 194:    * @return This date as a string.
 195:    */
 196:   public String toString ()
 197:   {
 198:     return sdf.format (this);
 199:   }
 200: 
 201: }