Showing the changes to java/pkg2/java/util (48 of 18352 files). Show all
Unified · Split
Empty file added.
| @@ -0,0 +1,782 @@ | |||
| 1 | /* | ||
| 2 | * @(#)Calendar.java 1.23 97/01/29 | ||
| 3 | * | ||
| 4 | * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved | ||
| 5 | * (C) Copyright IBM Corp. 1996 - All Rights Reserved | ||
| 6 | * | ||
| 7 | * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * The original version of this source code and documentation is copyrighted | ||
| 10 | * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These | ||
| 11 | * materials are provided under terms of a License Agreement between Taligent | ||
| 12 | * and Sun. This technology is protected by multiple US and International | ||
| 13 | * patents. This notice and attribution to Taligent may not be removed. | ||
| 14 | * Taligent is a registered trademark of Taligent, Inc. | ||
| 15 | * | ||
| 16 | * Permission to use, copy, modify, and distribute this software | ||
| 17 | * and its documentation for NON-COMMERCIAL purposes and without | ||
| 18 | * fee is hereby granted provided that this copyright notice | ||
| 19 | * appears in all copies. Please refer to the file "copyright.html" | ||
| 20 | * for further important copyright and licensing information. | ||
| 21 | * | ||
| 22 | * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF | ||
| 23 | * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 24 | * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 25 | * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR | ||
| 26 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | ||
| 27 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. | ||
| 28 | * | ||
| 29 | */ | ||
| 30 | |||
| 31 | package java.util; | ||
| 32 | |||
| 33 | import java.io.Serializable; | ||
| 34 | import java.io.ObjectInputStream; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * <code>Calendar</code> is an abstract base class for converting between | ||
| 38 | * a <code>Date</code> object and a set of integer fields such as | ||
| 39 | * <code>YEAR</code>, <code>MONTH</code>, <code>DAY</code>, <code>HOUR</code>, | ||
| 40 | * and so on. (A <code>Date</code> object represents a specific instant in | ||
| 41 | * time with millisecond precision. See | ||
| 42 | * <a href="java.util.Date.html"><code>java.util.Date</code></a> | ||
| 43 | * for information about the <code>Date</code> class.) | ||
| 44 | * | ||
| 45 | * <p> | ||
| 46 | * Subclasses of <code>Calendar</code> interpret a <code>Date</code> | ||
| 47 | * according to the rules of a specific calendar system. The JDK | ||
| 48 | * provides one concrete subclass of <code>Calendar</code>: | ||
| 49 | * <code>GregorianCalendar</code>. Future subclasses could represent | ||
| 50 | * the various types of lunar calendars in use in many parts of the world. | ||
| 51 | * | ||
| 52 | * <p> | ||
| 53 | * Like other locale-sensitive classes, <code>Calendar</code> provides a | ||
| 54 | * class method, <code>getInstance</code>, for getting a generally useful | ||
| 55 | * object of this type. <code>Calendar</code>'s <code>getInstance</code> method | ||
| 56 | * returns a <code>GregorianCalendar</code> object whose | ||
| 57 | * time fields have been initialized with the current date and time: | ||
| 58 | * <blockquote> | ||
| 59 | * <pre> | ||
| 60 | * Calendar rightNow = Calendar.getInstance(); | ||
| 61 | * </pre> | ||
| 62 | * </blockquote> | ||
| 63 | * | ||
| 64 | * <p> | ||
| 65 | * A <code>Calendar</code> object can produce all the time field values | ||
| 66 | * needed to implement the date-time formatting for a particular language | ||
| 67 | * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional). | ||
| 68 | * | ||
| 69 | * <p> | ||
| 70 | * When computing a <code>Date</code> from time fields, two special circumstances | ||
| 71 | * may arise: there may be insufficient information to compute the | ||
| 72 | * <code>Date</code> (such as only year and month but no day in the month), | ||
| 73 | * or there may be inconsistent information (such as "Tuesday, July 15, 1996" | ||
| 74 | * -- July 15, 1996 is actually a Monday). | ||
| 75 | * | ||
| 76 | * <p> | ||
| 77 | * <strong>Insufficient information.</strong> The calendar will use default | ||
| 78 | * information to specify the missing fields. This may vary by calendar; for | ||
| 79 | * the Gregorian calendar, the default for a field is the same as that of the | ||
| 80 | * start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc. | ||
| 81 | * | ||
| 82 | * <p> | ||
| 83 | * <strong>Inconsistent information.</strong> The calendar will give preference | ||
| 84 | * to the combinations of fields in the following order (and disregard other | ||
| 85 | * inconsistent information). | ||
| 86 | * | ||
| 87 | * <blockquote> | ||
| 88 | * <pre> | ||
| 89 | * month + day-of-month | ||
| 90 | * month + week-of-month + day-of-week | ||
| 91 | * month + day-of-week-of-month + day-of-week | ||
| 92 | * day-of-year | ||
| 93 | * day-of-week + week-of-year | ||
| 94 | * hour-of-day | ||
| 95 | * ampm + hour-of-ampm | ||
| 96 | * </pre> | ||
| 97 | * </blockquote> | ||
| 98 | * | ||
| 99 | * <p> | ||
| 100 | * <strong>Note:</strong> for some non-Gregorian calendars, different | ||
| 101 | * fields may be necessary for complete disambiguation. For example, a full | ||
| 102 | * specification of the historial Arabic astronomical calendar requires year, | ||
| 103 | * month, day-of-month <em>and</em> day-of-week in some cases. | ||
| 104 | * | ||
| 105 | * <p> | ||
| 106 | * <strong>Note:</strong> There are certain possible ambiguities in | ||
| 107 | * interpretation of certain singular times, which are resolved in the | ||
| 108 | * following ways: | ||
| 109 | * <ol> | ||
| 110 | * <li> 24:00:00 "belongs" to the following day. That is, | ||
| 111 | * 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970 | ||
| 112 | * | ||
| 113 | * <li> Although historically not precise, midnight also belongs to "am", | ||
| 114 | * and noon belongs to "pm", so on the same day, | ||
| 115 | * 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm | ||
| 116 | * </ol> | ||
| 117 | * | ||
| 118 | * <p> | ||
| 119 | * The date or time format strings are not part of the definition of a | ||
| 120 | * calendar, as those must be modifiable or overridable by the user at | ||
| 121 | * runtime. Use <a href="java.text.DateFormat.html">java.text.DateFormat</a> | ||
| 122 | * to format dates. | ||
| 123 | * | ||
| 124 | * <p> | ||
| 125 | * <code>Calendar</code> provides an API for field "rolling", where fields | ||
| 126 | * can be incremented or decremented, but wrap around. For example, rolling the | ||
| 127 | * month up in the date "September 12, 1996" results in "October 12, 1996". | ||
| 128 | * | ||
| 129 | * <p> | ||
| 130 | * <code>Calendar</code> also provides a date arithmetic function for | ||
| 131 | * adding the specified (signed) amount of time to a particular time field. | ||
| 132 | * For example, subtracting 5 days from the date "September 12, 1996" results | ||
| 133 | * in "September 7, 1996". | ||
| 134 | * | ||
| 135 | * @see Date | ||
| 136 | * @see GregorianCalendar | ||
| 137 | * @see TimeZone | ||
| 138 | * @see java.text.DateFormat | ||
| 139 | * @version 1.17 06 Jan 1997 | ||
| 140 | * @author Mark Davis, David Goldsmith, Chen-Lieh Huang | ||
| 141 | */ | ||
| 142 | public abstract class Calendar implements Serializable, Cloneable { | ||
| 143 | |||
| 144 | /** | ||
| 145 | * Useful constant for date and time. Used in time fields. | ||
| 146 | * ERA is calendar specific. | ||
| 147 | */ | ||
| 148 | public final static int ERA = 0; | ||
| 149 | /** | ||
| 150 | * Useful constant for date and time. Used in time fields. | ||
| 151 | */ | ||
| 152 | public final static int YEAR = 1; | ||
| 153 | /** | ||
| 154 | * Useful constant for date and time. Used in time fields. | ||
| 155 | */ | ||
| 156 | public final static int MONTH = 2; | ||
| 157 | /** | ||
| 158 | * Useful constant for date and time. Used in time fields. | ||
| 159 | */ | ||
| 160 | public final static int WEEK_OF_YEAR = 3; | ||
| 161 | /** | ||
| 162 | * Useful constant for date and time. Used in time fields. | ||
| 163 | */ | ||
| 164 | public final static int WEEK_OF_MONTH = 4; | ||
| 165 | /** | ||
| 166 | * Useful constant for date and time. Used in time fields. | ||
| 167 | * DATE is the time field name for day-of-month. | ||
| 168 | */ | ||
| 169 | public final static int DATE = 5; | ||
| 170 | /** | ||
| 171 | * Useful constant for date and time. Used in time fields. | ||
| 172 | * This is a synonym for DATE. | ||
| 173 | */ | ||
| 174 | public final static int DAY_OF_MONTH = 5; | ||
| 175 | /** | ||
| 176 | * Useful constant for date and time. Used in time fields. | ||
| 177 | */ | ||
| 178 | public final static int DAY_OF_YEAR = 6; | ||
| 179 | /** | ||
| 180 | * Useful constant for date and time. Used in time fields. | ||
| 181 | */ | ||
| 182 | public final static int DAY_OF_WEEK = 7; | ||
| 183 | /** | ||
| 184 | * Useful constant for date and time. Used in time fields. | ||
| 185 | */ | ||
| 186 | public final static int DAY_OF_WEEK_IN_MONTH = 8; | ||
| 187 | /** | ||
| 188 | * Useful constant for date and time. Used in time fields. | ||
| 189 | */ | ||
| 190 | public final static int AM_PM = 9; | ||
| 191 | /** | ||
| 192 | * Useful constant for date and time. Used in time fields. | ||
| 193 | * HOUR is used for the 12-hour clock. | ||
| 194 | */ | ||
| 195 | public final static int HOUR = 10; | ||
| 196 | /** | ||
| 197 | * Useful constant for date and time. Used in time fields. | ||
| 198 | * HOUR_OF_DAY is used for the 24-hour clock. | ||
| 199 | */ | ||
| 200 | public final static int HOUR_OF_DAY = 11; | ||
| 201 | /** | ||
| 202 | * Useful constant for date and time. Used in time fields. | ||
| 203 | */ | ||
| 204 | public final static int MINUTE = 12; | ||
| 205 | /** | ||
| 206 | * Useful constant for date and time. Used in time fields. | ||
| 207 | */ | ||
| 208 | public final static int SECOND = 13; | ||
| 209 | /** | ||
| 210 | * Useful constant for date and time. Used in time fields. | ||
| 211 | */ | ||
| 212 | public final static int MILLISECOND = 14; | ||
| 213 | /** | ||
| 214 | * Useful constant for date and time. Used in time fields. | ||
| 215 | */ | ||
| 216 | public final static int ZONE_OFFSET = 15; | ||
| 217 | /** | ||
| 218 | * Useful constant for date and time. Used in time fields. | ||
| 219 | */ | ||
| 220 | public final static int DST_OFFSET = 16; | ||
| 221 | /** | ||
| 222 | * Useful constant for date and time. | ||
| 223 | * FIELD_COUNT is used for the time field array creation. | ||
| 224 | */ | ||
| 225 | public final static int FIELD_COUNT = 17; | ||
| 226 | |||
| 227 | /** | ||
| 228 | * Useful constant for days of week. Used in GregorianCalendar. | ||
| 229 | */ | ||
| 230 | public final static int SUNDAY = 1; | ||
| 231 | /** | ||
| 232 | * Useful constant for days of week. Used in GregorianCalendar. | ||
| 233 | */ | ||
| 234 | public final static int MONDAY = 2; | ||
| 235 | /** | ||
| 236 | * Useful constant for days of week. Used in GregorianCalendar. | ||
| 237 | */ | ||
| 238 | public final static int TUESDAY = 3; | ||
| 239 | /** | ||
| 240 | * Useful constant for days of week. Used in GregorianCalendar. | ||
| 241 | */ | ||
| 242 | public final static int WEDNESDAY = 4; | ||
| 243 | /** | ||
| 244 | * Useful constant for days of week. Used in GregorianCalendar. | ||
| 245 | */ | ||
| 246 | public final static int THURSDAY = 5; | ||
| 247 | /** | ||
| 248 | * Useful constant for days of week. Used in GregorianCalendar. | ||
| 249 | */ | ||
| 250 | public final static int FRIDAY = 6; | ||
| 251 | /** | ||
| 252 | * Useful constant for days of week. Used in GregorianCalendar. | ||
| 253 | */ | ||
| 254 | public final static int SATURDAY = 7; | ||
| 255 | /** | ||
| 256 | * Useful constant for month. Used in GregorianCalendar. | ||
| 257 | * Note: Calendar month is now 0-based. | ||
| 258 | */ | ||
| 259 | public final static int JANUARY = 0; | ||
| 260 | /** | ||
| 261 | * Useful constant for month. Used in GregorianCalendar. | ||
| 262 | */ | ||
| 263 | public final static int FEBRUARY = 1; | ||
| 264 | /** | ||
| 265 | * Useful constant for month. Used in GregorianCalendar. | ||
| 266 | */ | ||
| 267 | public final static int MARCH = 2; | ||
| 268 | /** | ||
| 269 | * Useful constant for month. Used in GregorianCalendar. | ||
| 270 | */ | ||
| 271 | public final static int APRIL = 3; | ||
| 272 | /** | ||
| 273 | * Useful constant for month. Used in GregorianCalendar. | ||
| 274 | */ | ||
| 275 | public final static int MAY = 4; | ||
| 276 | /** | ||
| 277 | * Useful constant for month. Used in GregorianCalendar. | ||
| 278 | */ | ||
| 279 | public final static int JUNE = 5; | ||
| 280 | /** | ||
| 281 | * Useful constant for month. Used in GregorianCalendar. | ||
| 282 | */ | ||
| 283 | public final static int JULY = 6; | ||
| 284 | /** | ||
| 285 | * Useful constant for month. Used in GregorianCalendar. | ||
| 286 | */ | ||
| 287 | public final static int AUGUST = 7; | ||
| 288 | /** | ||
| 289 | * Useful constant for month. Used in GregorianCalendar. | ||
| 290 | */ | ||
| 291 | public final static int SEPTEMBER = 8; | ||
| 292 | /** | ||
| 293 | * Useful constant for month. Used in GregorianCalendar. | ||
| 294 | */ | ||
| 295 | public final static int OCTOBER = 9; | ||
| 296 | /** | ||
| 297 | * Useful constant for month. Used in GregorianCalendar. | ||
| 298 | */ | ||
| 299 | public final static int NOVEMBER = 10; | ||
| 300 | /** | ||
| 301 | * Useful constant for month. Used in GregorianCalendar. | ||
| 302 | */ | ||
| 303 | public final static int DECEMBER = 11; | ||
| 304 | /** | ||
| 305 | * Useful constant for month. Used in GregorianCalendar. | ||
| 306 | * UNDECIMBER is an artifical name. This 13th month is for lunar | ||
| 307 | * calendars. | ||
| 308 | */ | ||
| 309 | public final static int UNDECIMBER = 12; | ||
| 310 | /** | ||
| 311 | * Useful constant for hour in 12-hour clock. Used in GregorianCalendar. | ||
| 312 | */ | ||
| 313 | public final static int AM = 0; | ||
| 314 | /** | ||
| 315 | * Useful constant for hour in 12-hour clock. Used in GregorianCalendar. | ||
| 316 | */ | ||
| 317 | public final static int PM = 1; | ||
| 318 | |||
| 319 | // | ||
| 320 | // Internal notes: | ||
| 321 | // Calendar contains two kinds of time representations: current "time" in | ||
| 322 | // milliseconds, and a set of time "fields" representing the current time. | ||
| 323 | // Calling setTime() method only sets the current time without recomputing | ||
| 324 | // the time fields until the next get() method is called. Similarly, | ||
| 325 | // calling one of the set() methods only sets time fields without | ||
| 326 | // recomputing the current time value until the next getTime() method is | ||
| 327 | // called. | ||
| 328 | // | ||
| 329 | |||
| 330 | /** | ||
| 331 | * The time fields containing values into which the millis is computed. | ||
| 332 | */ | ||
| 333 | protected int fields[]; | ||
| 334 | /** | ||
| 335 | * The flags which tell if a specified time field for the calendar is set. | ||
| 336 | */ | ||
| 337 | protected boolean isSet[]; | ||
| 338 | /** | ||
| 339 | * The current time set for the calendar. | ||
| 340 | */ | ||
| 341 | protected long time; | ||
| 342 | /** | ||
| 343 | * The flag which indicates if the current time is set for the calendar. | ||
| 344 | */ | ||
| 345 | protected boolean isTimeSet; | ||
| 346 | /** | ||
| 347 | * The flag which tells if the time fields are set for the calendar. | ||
| 348 | */ | ||
| 349 | protected boolean areFieldsSet; | ||
| 350 | |||
| 351 | /** | ||
| 352 | * @see #setLenient | ||
| 353 | */ | ||
| 354 | private boolean lenient=true; | ||
| 355 | |||
| 356 | /** | ||
| 357 | * Time zone affects the time calculation done by Calendar. Calendar uses | ||
| 358 | * the time zone data to produce the local time. Both firstDayOfWeek | ||
| 359 | * and minimalDaysInFirstWeek are locale-dependent. For example, | ||
| 360 | * in US locale, firstDayOfWeek is SUNDAY; minimalDaysInFirstWeek is 1. | ||
| 361 | * They are used to figure out the week count for a specific date for | ||
| 362 | * a given locale. These must be set when a Calendar is constructed. | ||
| 363 | */ | ||
| 364 | private TimeZone zone; | ||
| 365 | private int firstDayOfWeek; | ||
| 366 | private int minimalDaysInFirstWeek; | ||
| 367 | |||
| 368 | /** | ||
| 369 | * Constructs a Calendar with the default time zone as returned | ||
| 370 | * by TimeZone.getDefault(), and the default locale. | ||
| 371 | * @see TimeZone#getDefault | ||
| 372 | */ | ||
| 373 | protected Calendar() | ||
| 374 | { | ||
| 375 | throw new NoSuchElementException(); | ||
| 376 | } | ||
| 377 | |||
| 378 | /** | ||
| 379 | * Constructs a Calendar with the given time zone and locale. | ||
| 380 | * @param zone the given time zone. | ||
| 381 | */ | ||
| 382 | protected Calendar(TimeZone zone, Locale aLocale) | ||
| 383 | { | ||
| 384 | throw new NoSuchElementException(); | ||
| 385 | } | ||
| 386 | |||
| 387 | /** | ||
| 388 | * Gets a Calendar using the default timezone and locale. | ||
| 389 | * @return a Calendar. | ||
| 390 | */ | ||
| 391 | public static synchronized Calendar getInstance() | ||
| 392 | { | ||
| 393 | throw new NoSuchElementException(); | ||
| 394 | } | ||
| 395 | |||
| 396 | /** | ||
| 397 | * Gets a Calendar using the given timezone and default locale. | ||
| 398 | * @param zone the given timezone. | ||
| 399 | * @return a Calendar. | ||
| 400 | */ | ||
| 401 | public static synchronized Calendar getInstance(TimeZone zone) | ||
| 402 | { | ||
| 403 | throw new NoSuchElementException(); | ||
| 404 | } | ||
| 405 | |||
| 406 | /** | ||
| 407 | * Gets a Calendar using the default timezone and given locale. | ||
| 408 | * @param aLocale the given locale. | ||
| 409 | * @return a Calendar. | ||
| 410 | */ | ||
| 411 | public static synchronized Calendar getInstance(Locale aLocale) | ||
| 412 | { | ||
| 413 | throw new NoSuchElementException(); | ||
| 414 | } | ||
| 415 | |||
| 416 | /** | ||
| 417 | * Gets a Calendar using the given timezone and given locale. | ||
| 418 | * @param zone the given timezone. | ||
| 419 | * @param aLocale the given locale. | ||
| 420 | * @return a Calendar. | ||
| 421 | */ | ||
| 422 | public static synchronized Calendar getInstance(TimeZone zone, | ||
| 423 | Locale aLocale) | ||
| 424 | { | ||
| 425 | throw new NoSuchElementException(); | ||
| 426 | } | ||
| 427 | |||
| 428 | /** | ||
| 429 | * Gets the set of locales for which Calendars are installed. | ||
| 430 | * @return the set of locales for which Calendars are installed. | ||
| 431 | */ | ||
| 432 | public static synchronized Locale[] getAvailableLocales() | ||
| 433 | { | ||
| 434 | throw new NoSuchElementException(); | ||
| 435 | } | ||
| 436 | |||
| 437 | /** | ||
| 438 | * Converts Calendar's time field values to UTC as milliseconds. | ||
| 439 | */ | ||
| 440 | protected abstract void computeTime(); | ||
| 441 | |||
| 442 | /** | ||
| 443 | * Converts UTC as milliseconds to time field values. | ||
| 444 | * This allows you to sync up the time field values with | ||
| 445 | * a new time that is set for the calendar. | ||
| 446 | */ | ||
| 447 | protected abstract void computeFields(); | ||
| 448 | |||
| 449 | /** | ||
| 450 | * Gets this Calendar's current time. | ||
| 451 | * @return the current time. | ||
| 452 | */ | ||
| 453 | public final Date getTime() { | ||
| 454 | throw new NoSuchElementException(); | ||
| 455 | } | ||
| 456 | |||
| 457 | /** | ||
| 458 | * Sets this Calendar's current time with the given Date. | ||
| 459 | * @param date the given Date. | ||
| 460 | */ | ||
| 461 | public final void setTime(Date date) { | ||
| 462 | throw new NoSuchElementException(); | ||
| 463 | } | ||
| 464 | |||
| 465 | /** | ||
| 466 | * Gets this Calendar's current time as a long. | ||
| 467 | * @return the current time as milliseconds from the epoch. | ||
| 468 | */ | ||
| 469 | protected long getTimeInMillis() { | ||
| 470 | throw new NoSuchElementException(); | ||
| 471 | } | ||
| 472 | |||
| 473 | /** | ||
| 474 | * Sets this Calendar's current time from the given long value. | ||
| 475 | * @param date the new time in milliseconds from the epoch. | ||
| 476 | */ | ||
| 477 | protected void setTimeInMillis( long millis ) { | ||
| 478 | throw new NoSuchElementException(); | ||
| 479 | } | ||
| 480 | |||
| 481 | |||
| 482 | /** | ||
| 483 | * Gets the value for a given time field. | ||
| 484 | * @param field the given time field. | ||
| 485 | * @return the value for the given time field. | ||
| 486 | */ | ||
| 487 | public final int get(int field) | ||
| 488 | { | ||
| 489 | throw new NoSuchElementException(); | ||
| 490 | } | ||
| 491 | |||
| 492 | /** | ||
| 493 | * Gets the value for a given time field. This is an internal | ||
| 494 | * fast time field value getter for the subclasses. | ||
| 495 | * @param field the given time field. | ||
| 496 | * @return the value for the given time field. | ||
| 497 | */ | ||
| 498 | protected final int internalGet(int field) | ||
| 499 | { | ||
| 500 | throw new NoSuchElementException(); | ||
| 501 | } | ||
| 502 | |||
| 503 | /** | ||
| 504 | * Sets the time field with the given value. | ||
| 505 | * @param field the given time field. | ||
| 506 | * @param value the value to be set for the given time field. | ||
| 507 | */ | ||
| 508 | public final void set(int field, int value) | ||
| 509 | { | ||
| 510 | throw new NoSuchElementException(); | ||
| 511 | } | ||
| 512 | |||
| 513 | /** | ||
| 514 | * Sets the values for the fields year, month, and date. | ||
| 515 | * @param year the value used to set the YEAR time field. | ||
| 516 | * @param month the value used to set the MONTH time field. | ||
| 517 | * Month value is 0-based. e.g., 0 for January. | ||
| 518 | * @param date the value used to set the DATE time field. | ||
| 519 | */ | ||
| 520 | public final void set(int year, int month, int date) | ||
| 521 | { | ||
| 522 | throw new NoSuchElementException(); | ||
| 523 | } | ||
| 524 | |||
| 525 | /** | ||
| 526 | * Sets the values for the fields year, month, date, hour, and minute. | ||
| 527 | * @param year the value used to set the YEAR time field. | ||
| 528 | * @param month the value used to set the MONTH time field. | ||
| 529 | * Month value is 0-based. e.g., 0 for January. | ||
| 530 | * @param date the value used to set the DATE time field. | ||
| 531 | * @param hour the value used to set the HOUR_OF_DAY time field. | ||
| 532 | * @param minute the value used to set the MINUTE time field. | ||
| 533 | */ | ||
| 534 | public final void set(int year, int month, int date, int hour, int minute) | ||
| 535 | { | ||
| 536 | throw new NoSuchElementException(); | ||
| 537 | } | ||
| 538 | |||
| 539 | /** | ||
| 540 | * Sets the values for the fields year, month, date, hour, minute, | ||
| 541 | * and second. | ||
| 542 | * @param year the value used to set the YEAR time field. | ||
| 543 | * @param month the value used to set the MONTH time field. | ||
| 544 | * Month value is 0-based. e.g., 0 for January. | ||
| 545 | * @param date the value used to set the DATE time field. | ||
| 546 | * @param hour the value used to set the HOUR_OF_DAY time field. | ||
| 547 | * @param minute the value used to set the MINUTE time field. | ||
| 548 | * @param second the value used to set the SECOND time field. | ||
| 549 | */ | ||
| 550 | public final void set(int year, int month, int date, int hour, int minute, | ||
| 551 | int second) | ||
| 552 | { | ||
| 553 | throw new NoSuchElementException(); | ||
| 554 | } | ||
| 555 | |||
| 556 | /** | ||
| 557 | * Clears the values of all the time fields. | ||
| 558 | */ | ||
| 559 | public final void clear() | ||
| 560 | { | ||
| 561 | throw new NoSuchElementException(); | ||
| 562 | } | ||
| 563 | |||
| 564 | /** | ||
| 565 | * Clears the value in the given time field. | ||
| 566 | * @param field the time field to be cleared. | ||
| 567 | */ | ||
| 568 | public final void clear(int field) | ||
| 569 | { | ||
| 570 | throw new NoSuchElementException(); | ||
| 571 | } | ||
| 572 | |||
| 573 | /** | ||
| 574 | * Determines if the given time field has a value set. | ||
| 575 | * @return true if the given time field has a value set; false otherwise. | ||
| 576 | */ | ||
| 577 | public final boolean isSet(int field) | ||
| 578 | { | ||
| 579 | throw new NoSuchElementException(); | ||
| 580 | } | ||
| 581 | |||
| 582 | /** | ||
| 583 | * Fills in any unset fields in the time field list. | ||
| 584 | */ | ||
| 585 | protected void complete() | ||
| 586 | { | ||
| 587 | throw new NoSuchElementException(); | ||
| 588 | } | ||
| 589 | |||
| 590 | /** | ||
| 591 | * Compares the time field records. | ||
| 592 | * Equivalent to comparing result of conversion to UTC. | ||
| 593 | * @param when the Calendar to be compared with this Calendar. | ||
| 594 | * @return true if the current time of this Calendar is before | ||
| 595 | * the time of Calendar when; false otherwise. | ||
| 596 | */ | ||
| 597 | abstract public boolean before(Object when); | ||
| 598 | |||
| 599 | /** | ||
| 600 | * Compares the time field records. | ||
| 601 | * Equivalent to comparing result of conversion to UTC. | ||
| 602 | * @param when the Calendar to be compared with this Calendar. | ||
| 603 | * @return true if the current time of this Calendar is after | ||
| 604 | * the time of Calendar when; false otherwise. | ||
| 605 | */ | ||
| 606 | abstract public boolean after(Object when); | ||
| 607 | |||
| 608 | /** | ||
| 609 | * Date Arithmetic function. | ||
| 610 | * Adds the specified (signed) amount of time to the given time field, | ||
| 611 | * based on the calendar's rules. For example, to subtract 5 days from | ||
| 612 | * the current time of the calendar, you can achieve it by calling: | ||
| 613 | * <p>add(Calendar.DATE, -5). | ||
| 614 | * @param field the time field. | ||
| 615 | * @param amount the amount of date or time to be added to the field. | ||
| 616 | */ | ||
| 617 | abstract public void add(int field, int amount); | ||
| 618 | |||
| 619 | /** | ||
| 620 | * Time Field Rolling function. | ||
| 621 | * Rolls (up/down) a single unit of time on the given time field. For | ||
| 622 | * example, to roll the current date up by one day, you can achieve it | ||
| 623 | * by calling: | ||
| 624 | * <p>roll(Calendar.DATE, true). | ||
| 625 | * When rolling on the year or Calendar.YEAR field, it will roll the year | ||
| 626 | * value in the range between 1 and the value returned by calling | ||
| 627 | * getMaximum(Calendar.YEAR). | ||
| 628 | * When rolling on the month or Calendar.MONTH field, other fields like | ||
| 629 | * date might conflict and, need to be changed. For instance, | ||
| 630 | * rolling the month on the date 01/31/96 will result in 03/02/96. | ||
| 631 | * When rolling on the hour-in-day or Calendar.HOUR_OF_DAY field, it will | ||
| 632 | * roll the hour value in the range between 0 and 23, which is zero-based. | ||
| 633 | * @param field the time field. | ||
| 634 | * @param up indicates if the value of the specified time field is to be | ||
| 635 | * rolled up or rolled down. Use true if rolling up, false otherwise. | ||
| 636 | */ | ||
| 637 | abstract public void roll(int field, boolean up); | ||
| 638 | |||
| 639 | /** | ||
| 640 | * Sets the time zone with the given time zone value. | ||
| 641 | * @param value the given time zone. | ||
| 642 | */ | ||
| 643 | public void setTimeZone(TimeZone value) | ||
| 644 | { | ||
| 645 | throw new NoSuchElementException(); | ||
| 646 | } | ||
| 647 | |||
| 648 | /** | ||
| 649 | * Gets the time zone. | ||
| 650 | * @return the time zone object associated with this calendar. | ||
| 651 | */ | ||
| 652 | public TimeZone getTimeZone() | ||
| 653 | { | ||
| 654 | throw new NoSuchElementException(); | ||
| 655 | } | ||
| 656 | |||
| 657 | /** | ||
| 658 | * Specify whether or not date/time interpretation is to be lenient. With | ||
| 659 | * lenient interpretation, a date such as "February 942, 1996" will be | ||
| 660 | * treated as being equivalent to the 941st day after February 1, 1996. | ||
| 661 | * With strict interpretation, such dates will cause an exception to be | ||
| 662 | * thrown. | ||
| 663 | * | ||
| 664 | * @see java.text.DateFormat#setLenient | ||
| 665 | */ | ||
| 666 | public void setLenient(boolean lenient) | ||
| 667 | { | ||
| 668 | throw new NoSuchElementException(); | ||
| 669 | } | ||
| 670 | |||
| 671 | /** | ||
| 672 | * Tell whether date/time interpretation is to be lenient. | ||
| 673 | */ | ||
| 674 | public boolean isLenient() | ||
| 675 | { | ||
| 676 | throw new NoSuchElementException(); | ||
| 677 | } | ||
| 678 | |||
| 679 | /** | ||
| 680 | * Sets what the first day of the week is; e.g., Sunday in US, | ||
| 681 | * Monday in France. | ||
| 682 | * @param value the given first day of the week. | ||
| 683 | */ | ||
| 684 | public void setFirstDayOfWeek(int value) | ||
| 685 | { | ||
| 686 | throw new NoSuchElementException(); | ||
| 687 | } | ||
| 688 | |||
| 689 | /** | ||
| 690 | * Gets what the first day of the week is; e.g., Sunday in US, | ||
| 691 | * Monday in France. | ||
| 692 | * @return the first day of the week. | ||
| 693 | */ | ||
| 694 | public int getFirstDayOfWeek() | ||
| 695 | { | ||
| 696 | throw new NoSuchElementException(); | ||
| 697 | } | ||
| 698 | |||
| 699 | /** | ||
| 700 | * Sets what the minimal days required in the first week of the year are; | ||
| 701 | * For example, if the first week is defined as one that contains the first | ||
| 702 | * day of the first month of a year, call the method with value 1. If it | ||
| 703 | * must be a full week, use value 7. | ||
| 704 | * @param value the given minimal days required in the first week | ||
| 705 | * of the year. | ||
| 706 | */ | ||
| 707 | public void setMinimalDaysInFirstWeek(int value) | ||
| 708 | { | ||
| 709 | throw new NoSuchElementException(); | ||
| 710 | } | ||
| 711 | |||
| 712 | /** | ||
| 713 | * Gets what the minimal days required in the first week of the year are; | ||
| 714 | * e.g., if the first week is defined as one that contains the first day | ||
| 715 | * of the first month of a year, getMinimalDaysInFirstWeek returns 1. If | ||
| 716 | * the minimal days required must be a full week, getMinimalDaysInFirstWeek | ||
| 717 | * returns 7. | ||
| 718 | * @return the minimal days required in the first week of the year. | ||
| 719 | */ | ||
| 720 | public int getMinimalDaysInFirstWeek() | ||
| 721 | { | ||
| 722 | throw new NoSuchElementException(); | ||
| 723 | } | ||
| 724 | |||
| 725 | /** | ||
| 726 | * Gets the minimum value for the given time field. | ||
| 727 | * e.g., for Gregorian DAY_OF_MONTH, 1. | ||
| 728 | * @param field the given time field. | ||
| 729 | * @return the minimum value for the given time field. | ||
| 730 | */ | ||
| 731 | abstract public int getMinimum(int field); | ||
| 732 | |||
| 733 | /** | ||
| 734 | * Gets the maximum value for the given time field. | ||
| 735 | * e.g. for Gregorian DAY_OF_MONTH, 31. | ||
| 736 | * @param field the given time field. | ||
| 737 | * @return the maximum value for the given time field. | ||
| 738 | */ | ||
| 739 | abstract public int getMaximum(int field); | ||
| 740 | |||
| 741 | /** | ||
| 742 | * Gets the highest minimum value for the given field if varies. | ||
| 743 | * Otherwise same as getMinimum(). For Gregorian, no difference. | ||
| 744 | * @param field the given time field. | ||
| 745 | * @return the highest minimum value for the given time field. | ||
| 746 | */ | ||
| 747 | abstract public int getGreatestMinimum(int field); | ||
| 748 | |||
| 749 | /** | ||
| 750 | * Gets the lowest maximum value for the given field if varies. | ||
| 751 | * Otherwise same as getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28. | ||
| 752 | * @param field the given time field. | ||
| 753 | * @return the lowest maximum value for the given time field. | ||
| 754 | */ | ||
| 755 | abstract public int getLeastMaximum(int field); | ||
| 756 | |||
| 757 | /** | ||
| 758 | * Overrides Cloneable | ||
| 759 | */ | ||
| 760 | public Object clone() | ||
| 761 | { | ||
| 762 | throw new NoSuchElementException(); | ||
| 763 | } | ||
| 764 | |||
| 765 | |||
| 766 | // =======================privates=============================== | ||
| 767 | |||
| 768 | /** | ||
| 769 | * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. | ||
| 770 | * They are used to figure out the week count for a specific date for | ||
| 771 | * a given locale. These must be set when a Calendar is constructed. | ||
| 772 | * @param desiredLocale the given locale. | ||
| 773 | */ | ||
| 774 | private void setWeekCountData(Locale desiredLocale) | ||
| 775 | { | ||
| 776 | throw new NoSuchElementException(); | ||
| 777 | } | ||
| 778 | |||
| 779 | private void readObject(ObjectInputStream s) { | ||
| 780 | throw new NoSuchElementException(); | ||
| 781 | } | ||
| 782 | } | ||
Empty file added.
| @@ -0,0 +1,180 @@ | |||
| 1 | implement Date_L; | ||
| 2 | |||
| 3 | # javal v1.3 generated file: edit with care | ||
| 4 | |||
| 5 | include "jni.m"; | ||
| 6 | jni : JNI; | ||
| 7 | ClassModule, | ||
| 8 | JString, | ||
| 9 | JArray, | ||
| 10 | JArrayI, | ||
| 11 | JArrayC, | ||
| 12 | JArrayB, | ||
| 13 | JArrayS, | ||
| 14 | JArrayJ, | ||
| 15 | JArrayF, | ||
| 16 | JArrayD, | ||
| 17 | JArrayZ, | ||
| 18 | JArrayJObject, | ||
| 19 | JArrayJClass, | ||
| 20 | JArrayJString, | ||
| 21 | JClass, | ||
| 22 | JThread, | ||
| 23 | JObject : import jni; | ||
| 24 | |||
| 25 | #>> extra pre includes here | ||
| 26 | include "daytime.m"; | ||
| 27 | localtime : ref Daytime->Tm; | ||
| 28 | gmttime : ref Daytime->Tm; | ||
| 29 | daytime : Daytime; | ||
| 30 | sys : import jni; | ||
| 31 | FALSE : import jni; | ||
| 32 | TRUE : import jni; | ||
| 33 | month := array[] of { | ||
| 34 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", | ||
| 35 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" | ||
| 36 | }; | ||
| 37 | |||
| 38 | #<< | ||
| 39 | |||
| 40 | include "Date_L.m"; | ||
| 41 | |||
| 42 | #>> extra post includes here | ||
| 43 | |||
| 44 | #<< | ||
| 45 | |||
| 46 | init( jni_p : JNI ) | ||
| 47 | { | ||
| 48 | # save java native inteface mod instance | ||
| 49 | jni = jni_p; | ||
| 50 | #>>extra initialization here | ||
| 51 | sys = jni->sys; | ||
| 52 | daytime = load Daytime Daytime->PATH; | ||
| 53 | if(daytime == nil) | ||
| 54 | jni->InitError( sys->sprint( "java.util.Date: could not load %s: %r", Daytime->PATH ) ); | ||
| 55 | #<< | ||
| 56 | } | ||
| 57 | |||
| 58 | toString_rString( this : ref Date_obj) : JString | ||
| 59 | {#>> | ||
| 60 | if (this.expanded != byte TRUE) | ||
| 61 | expand_V(this); | ||
| 62 | if (this.expanded != byte TRUE) | ||
| 63 | jni->ThrowException("java.lang.IllegalArgumentException", "could not expand time"); | ||
| 64 | s := daytime->text(localtime); | ||
| 65 | return (jni->NewString( s)); | ||
| 66 | }#<< | ||
| 67 | |||
| 68 | toLocaleString_rString( this : ref Date_obj) : JString | ||
| 69 | {#>> | ||
| 70 | s : string; | ||
| 71 | # | ||
| 72 | # put the date in the following format | ||
| 73 | # 09-Sep-97 9:15:24 PM | ||
| 74 | # | ||
| 75 | if (this.expanded != byte TRUE) | ||
| 76 | expand_V(this); | ||
| 77 | if (this.expanded != byte TRUE) | ||
| 78 | jni->ThrowException("java.lang.IllegalArgumentException", "could not expand time"); | ||
| 79 | |||
| 80 | if ((int this.tm_hour) >= 12) { | ||
| 81 | s = sys->sprint( "%.2d-%s-%.2d %d:%.2d:%.2d PM", | ||
| 82 | int this.tm_mday, | ||
| 83 | month[int this.tm_mon], | ||
| 84 | this.tm_year, | ||
| 85 | (int this.tm_hour) - 12, | ||
| 86 | int this.tm_min, | ||
| 87 | int this.tm_sec); | ||
| 88 | } else { | ||
| 89 | s = sys->sprint( "%.2d-%s-%.2d %d:%.2d:%.2d AM", | ||
| 90 | int this.tm_mday, | ||
| 91 | month[int this.tm_mon], | ||
| 92 | this.tm_year, | ||
| 93 | int this.tm_hour, | ||
| 94 | int this.tm_min, | ||
| 95 | int this.tm_sec); | ||
| 96 | } | ||
| 97 | return (jni->NewString( s)); | ||
| 98 | }#<< | ||
| 99 | |||
| 100 | toGMTString_rString( this : ref Date_obj) : JString | ||
| 101 | {#>> | ||
| 102 | s : string; | ||
| 103 | if (this.valueValid != byte TRUE) | ||
| 104 | computeValue_V( this); | ||
| 105 | if (this.valueValid != byte TRUE) | ||
| 106 | jni->ThrowException("java.lang.IllegalArgumentException", "could not compute time"); | ||
| 107 | t := (big this.value) / big 1000; | ||
| 108 | #10 Sep 1997 02:15:24 GMT | ||
| 109 | s = sys->sprint( "%.2d %s %d %.2d:%.2d:%.2d GMT", | ||
| 110 | int this.tm_mday, | ||
| 111 | month[int this.tm_mon], | ||
| 112 | this.tm_year + 1900, | ||
| 113 | int this.tm_hour, | ||
| 114 | int this.tm_min, | ||
| 115 | int this.tm_sec); | ||
| 116 | |||
| 117 | gmttime = daytime->gmt(int t); | ||
| 118 | return (jni->NewString( s)); | ||
| 119 | }#<< | ||
| 120 | |||
| 121 | expand_V( this : ref Date_obj) | ||
| 122 | {#>> | ||
| 123 | # | ||
| 124 | # this routine assumes there is a valid date stored | ||
| 125 | # in this.value. If not, return error. | ||
| 126 | # | ||
| 127 | if (this.value <= (big 0)) { | ||
| 128 | this.expanded = byte FALSE; | ||
| 129 | this.tm_millis = 0; | ||
| 130 | this.tm_sec = byte 0; | ||
| 131 | this.tm_min = byte 0; | ||
| 132 | this.tm_hour = byte 0; | ||
| 133 | this.tm_mday = byte 0; | ||
| 134 | this.tm_mon = byte 0; | ||
| 135 | this.tm_wday = byte 0; | ||
| 136 | this.tm_yday = 0; | ||
| 137 | this.tm_year = 0; | ||
| 138 | this.tm_isdst = 0; | ||
| 139 | return; | ||
| 140 | } | ||
| 141 | t := (big this.value) / big 1000; | ||
| 142 | localtime = daytime->local(int t); | ||
| 143 | # | ||
| 144 | # set the following to 0 since java code is not using them. | ||
| 145 | # | ||
| 146 | this.tm_millis = 0; | ||
| 147 | this.tm_isdst = 0; # flag for alternate daylight savings time | ||
| 148 | # | ||
| 149 | # these values come from calculations done by local(). | ||
| 150 | # | ||
| 151 | this.tm_sec = byte localtime.sec; | ||
| 152 | this.tm_min = byte localtime.min; | ||
| 153 | this.tm_hour = byte localtime.hour; | ||
| 154 | this.tm_mday = byte localtime.mday; # day of the month - [1, 31] | ||
| 155 | this.tm_mon = byte localtime.mon; # months since January - [0, 11] | ||
| 156 | this.tm_wday = byte localtime.wday; # days since Sunday - [0, 6] | ||
| 157 | this.tm_yday = localtime.yday; # days since January 1 - [0, 365] | ||
| 158 | this.tm_year = localtime.year; # years since 1900 | ||
| 159 | this.expanded = byte TRUE; | ||
| 160 | }#<< | ||
| 161 | |||
| 162 | computeValue_V( this : ref Date_obj) | ||
| 163 | {#>> | ||
| 164 | now := daytime->now(); | ||
| 165 | localtime = daytime->local(now); | ||
| 166 | localtime.sec = int this.tm_sec; | ||
| 167 | localtime.min = int this.tm_min; | ||
| 168 | localtime.hour = int this.tm_hour; | ||
| 169 | localtime.mday = int this.tm_mday; | ||
| 170 | localtime.mon = int this.tm_mon; | ||
| 171 | localtime.year = int this.tm_year; | ||
| 172 | localtime.wday = int this.tm_wday; | ||
| 173 | localtime.yday = int this.tm_yday; | ||
| 174 | |||
| 175 | t := daytime->tm2epoch(localtime); | ||
| 176 | this.value = (big t) * big 1000; | ||
| 177 | this.valueValid = byte TRUE; | ||
| 178 | }#<< | ||
| 179 | |||
| 180 | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | # javal v1.3 generated file: edit with care | ||
| 2 | |||
| 3 | Date_L : module | ||
| 4 | { | ||
| 5 | Date_obj : adt | ||
| 6 | { | ||
| 7 | cl_mod : ClassModule; | ||
| 8 | value : big; | ||
| 9 | valueValid : byte; | ||
| 10 | expanded : byte; | ||
| 11 | tm_millis : int; | ||
| 12 | tm_sec : byte; | ||
| 13 | tm_min : byte; | ||
| 14 | tm_hour : byte; | ||
| 15 | tm_mday : byte; | ||
| 16 | tm_mon : byte; | ||
| 17 | tm_wday : byte; | ||
| 18 | tm_yday : int; | ||
| 19 | tm_year : int; | ||
| 20 | tm_isdst : int; | ||
| 21 | }; | ||
| 22 | |||
| 23 | init : fn( jni_p : JNI ); | ||
| 24 | toString_rString : fn( this : ref Date_obj) : JString; | ||
| 25 | toLocaleString_rString : fn( this : ref Date_obj) : JString; | ||
| 26 | toGMTString_rString : fn( this : ref Date_obj) : JString; | ||
| 27 | expand_V : fn( this : ref Date_obj); | ||
| 28 | computeValue_V : fn( this : ref Date_obj); | ||
| 29 | |||
| 30 | }; | ||
Empty file added.
Empty file added.
Empty file added.
Empty file added.
Empty file added.
| @@ -0,0 +1,557 @@ | |||
| 1 | /* | ||
| 2 | * @(#)GregorianCalendar.java 1.20 97/03/09 | ||
| 3 | * | ||
| 4 | * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved | ||
| 5 | * (C) Copyright IBM Corp. 1996 - All Rights Reserved | ||
| 6 | * | ||
| 7 | * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * The original version of this source code and documentation is copyrighted | ||
| 10 | * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These | ||
| 11 | * materials are provided under terms of a License Agreement between Taligent | ||
| 12 | * and Sun. This technology is protected by multiple US and International | ||
| 13 | * patents. This notice and attribution to Taligent may not be removed. | ||
| 14 | * Taligent is a registered trademark of Taligent, Inc. | ||
| 15 | * | ||
| 16 | * Permission to use, copy, modify, and distribute this software | ||
| 17 | * and its documentation for NON-COMMERCIAL purposes and without | ||
| 18 | * fee is hereby granted provided that this copyright notice | ||
| 19 | * appears in all copies. Please refer to the file "copyright.html" | ||
| 20 | * for further important copyright and licensing information. | ||
| 21 | * | ||
| 22 | * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF | ||
| 23 | * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 24 | * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 25 | * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR | ||
| 26 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | ||
| 27 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. | ||
| 28 | * | ||
| 29 | */ | ||
| 30 | |||
| 31 | package java.util; | ||
| 32 | |||
| 33 | import java.io.ObjectInputStream; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * <code>GregorianCalendar</code> is a concrete subclass of | ||
| 37 | * <a href="java.util.Calendar.html"><code>Calendar</code></a> | ||
| 38 | * and provides the standard calendar used by most of the world. | ||
| 39 | * | ||
| 40 | * <p> | ||
| 41 | * The standard (Gregorian) calendar has 2 eras, BC and AD. | ||
| 42 | * | ||
| 43 | * <p> | ||
| 44 | * This implementation handles a single discontinuity, which corresponds | ||
| 45 | * by default to the date the Gregorian calendar was instituted (October 15, | ||
| 46 | * 1582 in some countries, later in others). This cutover date may be changed | ||
| 47 | * by the caller. | ||
| 48 | * | ||
| 49 | * <p> | ||
| 50 | * Prior to the institution of the Gregorian calendar, New Year's Day was | ||
| 51 | * March 25. To avoid confusion, this calendar always uses January 1. A manual | ||
| 52 | * adjustment may be made if desired for dates that are prior to the Gregorian | ||
| 53 | * changeover and which fall between January 1 and March 24. | ||
| 54 | * | ||
| 55 | * <p> | ||
| 56 | * <strong>Example:</strong> | ||
| 57 | * <blockquote> | ||
| 58 | * <pre> | ||
| 59 | * // get the supported ids for GMT-08:00 (Pacific Standard Time) | ||
| 60 | * String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); | ||
| 61 | * // if no ids were returned, something is wrong. get out. | ||
| 62 | * if (ids.length == 0) | ||
| 63 | * System.exit(0); | ||
| 64 | * | ||
| 65 | * // begin output | ||
| 66 | * System.out.println("Current Time"); | ||
| 67 | * | ||
| 68 | * // create a Pacific Standard Time time zone | ||
| 69 | * SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); | ||
| 70 | * | ||
| 71 | * // set up rules for daylight savings time | ||
| 72 | * pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); | ||
| 73 | * pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); | ||
| 74 | * | ||
| 75 | * // create a GregorianCalendar with the Pacific Daylight time zone | ||
| 76 | * // and the current date and time | ||
| 77 | * Calendar calendar = new GregorianCalendar(pdt); | ||
| 78 | * Date trialTime = new Date(); | ||
| 79 | * calendar.setTime(trialTime); | ||
| 80 | * | ||
| 81 | * // print out a bunch of interesting things | ||
| 82 | * System.out.println("ERA: " + calendar.get(Calendar.ERA)); | ||
| 83 | * System.out.println("YEAR: " + calendar.get(Calendar.YEAR)); | ||
| 84 | * System.out.println("MONTH: " + calendar.get(Calendar.MONTH)); | ||
| 85 | * System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR)); | ||
| 86 | * System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH)); | ||
| 87 | * System.out.println("DATE: " + calendar.get(Calendar.DATE)); | ||
| 88 | * System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH)); | ||
| 89 | * System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR)); | ||
| 90 | * System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK)); | ||
| 91 | * System.out.println("DAY_OF_WEEK_IN_MONTH: " | ||
| 92 | * + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH)); | ||
| 93 | * System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM)); | ||
| 94 | * System.out.println("HOUR: " + calendar.get(Calendar.HOUR)); | ||
| 95 | * System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY)); | ||
| 96 | * System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE)); | ||
| 97 | * System.out.println("SECOND: " + calendar.get(Calendar.SECOND)); | ||
| 98 | * System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND)); | ||
| 99 | * System.out.println("ZONE_OFFSET: " | ||
| 100 | * + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000))); | ||
| 101 | * System.out.println("DST_OFFSET: " | ||
| 102 | * + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000))); | ||
| 103 | |||
| 104 | * System.out.println("Current Time, with hour reset to 3"); | ||
| 105 | * calendar.clear(Calendar.HOUR_OF_DAY); // so doesn't override | ||
| 106 | * calendar.set(Calendar.HOUR, 3); | ||
| 107 | * System.out.println("ERA: " + calendar.get(Calendar.ERA)); | ||
| 108 | * System.out.println("YEAR: " + calendar.get(Calendar.YEAR)); | ||
| 109 | * System.out.println("MONTH: " + calendar.get(Calendar.MONTH)); | ||
| 110 | * System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR)); | ||
| 111 | * System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH)); | ||
| 112 | * System.out.println("DATE: " + calendar.get(Calendar.DATE)); | ||
| 113 | * System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH)); | ||
| 114 | * System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR)); | ||
| 115 | * System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK)); | ||
| 116 | * System.out.println("DAY_OF_WEEK_IN_MONTH: " | ||
| 117 | * + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH)); | ||
| 118 | * System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM)); | ||
| 119 | * System.out.println("HOUR: " + calendar.get(Calendar.HOUR)); | ||
| 120 | * System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY)); | ||
| 121 | * System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE)); | ||
| 122 | * System.out.println("SECOND: " + calendar.get(Calendar.SECOND)); | ||
| 123 | * System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND)); | ||
| 124 | * System.out.println("ZONE_OFFSET: " | ||
| 125 | * + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000))); // in hours | ||
| 126 | * System.out.println("DST_OFFSET: " | ||
| 127 | * + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000))); // in hours | ||
| 128 | * </pre> | ||
| 129 | * </blockquote> | ||
| 130 | * | ||
| 131 | * @see Calendar | ||
| 132 | * @see TimeZone | ||
| 133 | * @version 1.20 03/09/97 | ||
| 134 | * @author David Goldsmith, Mark Davis, Chen-Lieh Huang | ||
| 135 | */ | ||
| 136 | public class GregorianCalendar extends Calendar { | ||
| 137 | |||
| 138 | // Internal notes: | ||
| 139 | // This algorithm is based on the one presented on pp. 10-12 of | ||
| 140 | // "Numerical Recipes in C", William H. Press, et. al., Cambridge | ||
| 141 | // University Press 1988, ISBN 0-521-35465-X. | ||
| 142 | |||
| 143 | /** | ||
| 144 | * Useful constant for GregorianCalendar. | ||
| 145 | */ | ||
| 146 | public static final int BC = 0; | ||
| 147 | /** | ||
| 148 | * Useful constant for GregorianCalendar. | ||
| 149 | */ | ||
| 150 | public static final int AD = 1; | ||
| 151 | |||
| 152 | // Note that the Julian date used here is not a true Julian date, since | ||
| 153 | // it is measured from midnight, not noon. | ||
| 154 | |||
| 155 | private static final long julianDayOffset = 2440588; | ||
| 156 | private static final int millisPerDay = 24 * 60 * 60 * 1000; | ||
| 157 | private static final int numDays[] | ||
| 158 | = {0,31,59,90,120,151,181,212,243,273,304,334}; // 0-based, for day-in-year | ||
| 159 | private static final int leapNumDays[] | ||
| 160 | = {0,31,60,91,121,152,182,213,244,274,305,335}; // 0-based, for day-in-year | ||
| 161 | private static final int maxDaysInMonth[] | ||
| 162 | = {31,28,31,30,31,30,31,31,30,31,30,31}; // 0-based | ||
| 163 | |||
| 164 | // This is measured from the standard epoch, not in Julian Days. | ||
| 165 | // Default is 00:00:00 local time, October 15, 1582. | ||
| 166 | private long gregorianCutover = -12219292800000L; | ||
| 167 | |||
| 168 | /** | ||
| 169 | * Converts time as milliseconds to Julian date. | ||
| 170 | * @param millis the given milliseconds. | ||
| 171 | * @return the Julian date number. | ||
| 172 | */ | ||
| 173 | private static final long millisToJulianDay(long millis) | ||
| 174 | { | ||
| 175 | throw new NoSuchElementException(); | ||
| 176 | } | ||
| 177 | |||
| 178 | /** | ||
| 179 | * Converts Julian date to time as milliseconds. | ||
| 180 | * @param julian the given Julian date number. | ||
| 181 | * @return time as milliseconds. | ||
| 182 | */ | ||
| 183 | private static final long julianDayToMillis(long julian) | ||
| 184 | { | ||
| 185 | throw new NoSuchElementException(); | ||
| 186 | } | ||
| 187 | |||
| 188 | /** | ||
| 189 | * Constructs a default GregorianCalendar using the current time | ||
| 190 | * in the default time zone with the default locale. | ||
| 191 | */ | ||
| 192 | public GregorianCalendar() | ||
| 193 | { | ||
| 194 | throw new NoSuchElementException(); | ||
| 195 | } | ||
| 196 | |||
| 197 | /** | ||
| 198 | * Constructs a GregorianCalendar based on the current time | ||
| 199 | * in the given time zone with the default locale. | ||
| 200 | * @param zone the given time zone. | ||
| 201 | */ | ||
| 202 | public GregorianCalendar(TimeZone zone) | ||
| 203 | { | ||
| 204 | throw new NoSuchElementException(); | ||
| 205 | } | ||
| 206 | |||
| 207 | /** | ||
| 208 | * Constructs a GregorianCalendar based on the current time | ||
| 209 | * in the default time zone with the given locale. | ||
| 210 | * @param aLocale the given locale. | ||
| 211 | */ | ||
| 212 | public GregorianCalendar(Locale aLocale) | ||
| 213 | { | ||
| 214 | throw new NoSuchElementException(); | ||
| 215 | } | ||
| 216 | |||
| 217 | /** | ||
| 218 | * Constructs a GregorianCalendar based on the current time | ||
| 219 | * in the given time zone with the given locale. | ||
| 220 | * @param zone the given time zone. | ||
| 221 | * @param aLocale the given locale. | ||
| 222 | */ | ||
| 223 | public GregorianCalendar(TimeZone zone, Locale aLocale) | ||
| 224 | { | ||
| 225 | throw new NoSuchElementException(); | ||
| 226 | } | ||
| 227 | |||
| 228 | /** | ||
| 229 | * Constructs a GregorianCalendar with the given date set | ||
| 230 | * in the default time zone with the default locale. | ||
| 231 | * @param year the value used to set the YEAR time field in the calendar. | ||
| 232 | * @param month the value used to set the MONTH time field in the calendar. | ||
| 233 | * Month value is 0-based. e.g., 0 for January. | ||
| 234 | * @param date the value used to set the DATE time field in the calendar. | ||
| 235 | */ | ||
| 236 | public GregorianCalendar(int year, int month, int date) | ||
| 237 | { | ||
| 238 | throw new NoSuchElementException(); | ||
| 239 | } | ||
| 240 | |||
| 241 | /** | ||
| 242 | * Constructs a GregorianCalendar with the given date | ||
| 243 | * and time set for the default time zone with the default locale. | ||
| 244 | * @param year the value used to set the YEAR time field in the calendar. | ||
| 245 | * @param month the value used to set the MONTH time field in the calendar. | ||
| 246 | * Month value is 0-based. e.g., 0 for January. | ||
| 247 | * @param date the value used to set the DATE time field in the calendar. | ||
| 248 | * @param hour the value used to set the HOUR_OF_DAY time field | ||
| 249 | * in the calendar. | ||
| 250 | * @param minute the value used to set the MINUTE time field | ||
| 251 | * in the calendar. | ||
| 252 | */ | ||
| 253 | public GregorianCalendar(int year, int month, int date, int hour, | ||
| 254 | int minute) | ||
| 255 | { | ||
| 256 | throw new NoSuchElementException(); | ||
| 257 | } | ||
| 258 | |||
| 259 | /** | ||
| 260 | * Constructs a GregorianCalendar with the given date | ||
| 261 | * and time set for the default time zone with the default locale. | ||
| 262 | * @param year the value used to set the YEAR time field in the calendar. | ||
| 263 | * @param month the value used to set the MONTH time field in the calendar. | ||
| 264 | * Month value is 0-based. e.g., 0 for January. | ||
| 265 | * @param date the value used to set the DATE time field in the calendar. | ||
| 266 | * @param hour the value used to set the HOUR_OF_DAY time field | ||
| 267 | * in the calendar. | ||
| 268 | * @param minute the value used to set the MINUTE time field | ||
| 269 | * in the calendar. | ||
| 270 | * @param second the value used to set the SECOND time field | ||
| 271 | * in the calendar. | ||
| 272 | */ | ||
| 273 | public GregorianCalendar(int year, int month, int date, int hour, | ||
| 274 | int minute, int second) | ||
| 275 | { | ||
| 276 | throw new NoSuchElementException(); | ||
| 277 | } | ||
| 278 | |||
| 279 | /** | ||
| 280 | * Sets the GregorianCalendar change date. This is the point when the | ||
| 281 | * switch from Julian dates to Gregorian dates occurred. Default is | ||
| 282 | * 00:00:00 local time, October 15, 1582. Previous to this time and date | ||
| 283 | * will be Julian dates. | ||
| 284 | * | ||
| 285 | * @param date the given Gregorian cutover date. | ||
| 286 | */ | ||
| 287 | public void setGregorianChange(Date date) | ||
| 288 | { | ||
| 289 | throw new NoSuchElementException(); | ||
| 290 | } | ||
| 291 | |||
| 292 | /** | ||
| 293 | * Gets the Gregorian Calendar change date. This is the point when the | ||
| 294 | * switch from Julian dates to Gregorian dates occurred. Default is | ||
| 295 | * 00:00:00 local time, October 15, 1582. Previous to | ||
| 296 | * this time and date will be Julian dates. | ||
| 297 | * @return the Gregorian cutover time for this calendar. | ||
| 298 | */ | ||
| 299 | public final Date getGregorianChange() | ||
| 300 | { | ||
| 301 | throw new NoSuchElementException(); | ||
| 302 | } | ||
| 303 | |||
| 304 | // Converts the time field list to the time as milliseconds. | ||
| 305 | private final void timeToFields(long theTime) | ||
| 306 | { | ||
| 307 | throw new NoSuchElementException(); | ||
| 308 | } | ||
| 309 | |||
| 310 | |||
| 311 | /** | ||
| 312 | * @param date day-of-year or day-of-month. Month is zero based. | ||
| 313 | * @param day day-of-week for date. Zero based. | ||
| 314 | * @param firstDatesDay the day-of-week for the first day of the year | ||
| 315 | * or month. | ||
| 316 | * @param firstDay the first day of the week for the calendar. | ||
| 317 | * e.g. Sunday for US. | ||
| 318 | * @param minimalDaysInFirstWeek the minimal number of days in the | ||
| 319 | * week to qualify as the first week; otherwise partial week belongs | ||
| 320 | * to last (year/month). | ||
| 321 | * <note> weekCount is the number of weeks in the (year/month) for the | ||
| 322 | * date. If zero, belongs to last (year/month). You MUST add the date to | ||
| 323 | * the last day of the previous (year/month), and call this method again! | ||
| 324 | * @return week number, one-based. | ||
| 325 | */ | ||
| 326 | private static int weekNumber(int date, int day, int firstDatesDay, | ||
| 327 | int firstDay, int minimalDaysInFirstWeek) | ||
| 328 | { | ||
| 329 | throw new NoSuchElementException(); | ||
| 330 | } | ||
| 331 | |||
| 332 | |||
| 333 | // XXX Currently this method has a bug, and it is not being used. | ||
| 334 | private static int dateFrom(int weekNumber, int day, int firstDatesDay, | ||
| 335 | int firstDay, int minimalDaysInFirstWeek) | ||
| 336 | { | ||
| 337 | throw new NoSuchElementException(); | ||
| 338 | } | ||
| 339 | |||
| 340 | |||
| 341 | /** | ||
| 342 | * Determines if the given year is a leap year. Returns true if the | ||
| 343 | * given year is a leap year. | ||
| 344 | * @param year the given year. | ||
| 345 | * @return true if the given year is a leap year; false otherwise. | ||
| 346 | */ | ||
| 347 | public boolean isLeapYear(int year) | ||
| 348 | { | ||
| 349 | throw new NoSuchElementException(); | ||
| 350 | } | ||
| 351 | |||
| 352 | /** | ||
| 353 | * Overrides Calendar | ||
| 354 | * Converts UTC as milliseconds to time field values. | ||
| 355 | */ | ||
| 356 | protected void computeFields() | ||
| 357 | { | ||
| 358 | throw new NoSuchElementException(); | ||
| 359 | } | ||
| 360 | |||
| 361 | /** | ||
| 362 | * Validates the values of the set time fields. | ||
| 363 | */ | ||
| 364 | private boolean validateFields() | ||
| 365 | { | ||
| 366 | throw new NoSuchElementException(); | ||
| 367 | } | ||
| 368 | |||
| 369 | /** | ||
| 370 | * Validates the value of the given time field. | ||
| 371 | */ | ||
| 372 | private boolean boundsCheck(int value, int field) | ||
| 373 | { | ||
| 374 | throw new NoSuchElementException(); | ||
| 375 | } | ||
| 376 | |||
| 377 | /** | ||
| 378 | * Overrides Calendar | ||
| 379 | * Converts time field values to UTC as milliseconds. | ||
| 380 | * @exception IllegalArgumentException if an unknown field is given. | ||
| 381 | */ | ||
| 382 | protected void computeTime() | ||
| 383 | { | ||
| 384 | throw new NoSuchElementException(); | ||
| 385 | } | ||
| 386 | |||
| 387 | /** | ||
| 388 | * Overrides Cloneable | ||
| 389 | */ | ||
| 390 | public Object clone() | ||
| 391 | { | ||
| 392 | throw new NoSuchElementException(); | ||
| 393 | } | ||
| 394 | |||
| 395 | /** | ||
| 396 | * Override hashCode. | ||
| 397 | * Generates the hash code for the GregorianCalendar object | ||
| 398 | */ | ||
| 399 | public synchronized int hashCode() | ||
| 400 | { | ||
| 401 | throw new NoSuchElementException(); | ||
| 402 | } | ||
| 403 | |||
| 404 | /** | ||
| 405 | * Overrides Calendar | ||
| 406 | * Compares the time field records. | ||
| 407 | * Equivalent to comparing result of conversion to UTC. | ||
| 408 | * Please see Calendar.equals for descriptions on parameters and | ||
| 409 | * the return value. | ||
| 410 | */ | ||
| 411 | public boolean equals(Object obj) | ||
| 412 | { | ||
| 413 | throw new NoSuchElementException(); | ||
| 414 | } | ||
| 415 | |||
| 416 | /** | ||
| 417 | * Overrides Calendar | ||
| 418 | * Compares the time field records. | ||
| 419 | * Equivalent to comparing result of conversion to UTC. | ||
| 420 | * Please see Calendar.before for descriptions on parameters and | ||
| 421 | * the return value. | ||
| 422 | */ | ||
| 423 | public boolean before(Object when) | ||
| 424 | { | ||
| 425 | throw new NoSuchElementException(); | ||
| 426 | } | ||
| 427 | |||
| 428 | /** | ||
| 429 | * Overrides Calendar | ||
| 430 | * Compares the time field records. | ||
| 431 | * Equivalent to comparing result of conversion to UTC. | ||
| 432 | * Please see Calendar.after for descriptions on parameters and | ||
| 433 | * the return value. | ||
| 434 | */ | ||
| 435 | public boolean after(Object when) | ||
| 436 | { | ||
| 437 | throw new NoSuchElementException(); | ||
| 438 | } | ||
| 439 | |||
| 440 | /** | ||
| 441 | * Overrides Calendar | ||
| 442 | * Date Arithmetic function. | ||
| 443 | * Adds the specified (signed) amount of time to the given time field, | ||
| 444 | * based on the calendar's rules. | ||
| 445 | * @param field the time field. | ||
| 446 | * @param amount the amount of date or time to be added to the field. | ||
| 447 | * @exception IllegalArgumentException if an unknown field is given. | ||
| 448 | */ | ||
| 449 | public void add(int field, int amount) | ||
| 450 | { | ||
| 451 | throw new NoSuchElementException(); | ||
| 452 | } | ||
| 453 | |||
| 454 | |||
| 455 | /** | ||
| 456 | * Overrides Calendar | ||
| 457 | * Time Field Rolling function. | ||
| 458 | * Rolls (up/down) a single unit of time on the given time field. | ||
| 459 | * @param field the time field. | ||
| 460 | * @param up Indicates if rolling up or rolling down the field value. | ||
| 461 | * @exception IllegalArgumentException if an unknown field value is given. | ||
| 462 | */ | ||
| 463 | public void roll(int field, boolean up) | ||
| 464 | { | ||
| 465 | throw new NoSuchElementException(); | ||
| 466 | } | ||
| 467 | |||
| 468 | |||
| 469 | // Roll the time field value down by 1. | ||
| 470 | private void rollDown(int field) | ||
| 471 | { | ||
| 472 | throw new NoSuchElementException(); | ||
| 473 | } | ||
| 474 | |||
| 475 | |||
| 476 | /** | ||
| 477 | * <pre> | ||
| 478 | * Field names Minimum Greatest Minimum Least Maximum Maximum | ||
| 479 | * ----------- ------- ---------------- ------------- ------- | ||
| 480 | * ERA 0 0 1 1 | ||
| 481 | * YEAR 1 1 5,000,000 5,000,000 | ||
| 482 | * MONTH 0 0 11 11 | ||
| 483 | * WEEK_OF_YEAR 1 1 53 54 | ||
| 484 | * WEEK_OF_MONTH 1 1 4 6 | ||
| 485 | * DAY_OF_MONTH 1 1 28 31 | ||
| 486 | * DAY_OF_YEAR 1 1 365 366 | ||
| 487 | * DAY_OF_WEEK 1 1 7 7 | ||
| 488 | * DAY_OF_WEEK_IN_MONTH -1 -1 4 6 | ||
| 489 | * AM_PM 0 0 1 1 | ||
| 490 | * HOUR 0 0 11 12 | ||
| 491 | * HOUR_OF_DAY 0 0 23 23 | ||
| 492 | * MINUTE 0 0 59 59 | ||
| 493 | * SECOND 0 0 59 59 | ||
| 494 | * MILLISECOND 0 0 999 999 | ||
| 495 | * ZONE_OFFSET -12*60*60*1000 -12*60*60*1000 12*60*60*1000 12*60*60*1000 | ||
| 496 | * DST_OFFSET 0 0 1*60*60*1000 1*60*60*1000 | ||
| 497 | * </pre> | ||
| 498 | */ | ||
| 499 | private static final int MinValues[] | ||
| 500 | = {0,1,0,1,1,1,1,1,-1,0,0,0,0,0,0,-12*60*60*1000,0}; | ||
| 501 | private static final int GreatestMinValues[] | ||
| 502 | = {0,1,0,1,1,1,1,1,-1,0,0,0,0,0,0,-12*60*60*1000,0};// same as MinValues | ||
| 503 | private static final int LeastMaxValues[] | ||
| 504 | = {1,5000000,11,53,4,28,365,7,4,1,11,23,59,59,999, | ||
| 505 | 12*60*60*1000,1*60*60*1000}; | ||
| 506 | private static final int MaxValues[] | ||
| 507 | = {1,5000000,11,54,6,31,366,7,6,1,12,23,59,59,999, | ||
| 508 | 12*60*60*1000,1*60*60*1000}; | ||
| 509 | |||
| 510 | /** | ||
| 511 | * Returns minimum value for the given field. | ||
| 512 | * e.g. for Gregorian DAY_OF_MONTH, 1 | ||
| 513 | * Please see Calendar.getMinimum for descriptions on parameters and | ||
| 514 | * the return value. | ||
| 515 | */ | ||
| 516 | public int getMinimum(int field) | ||
| 517 | { | ||
| 518 | throw new NoSuchElementException(); | ||
| 519 | } | ||
| 520 | |||
| 521 | /** | ||
| 522 | * Returns maximum value for the given field. | ||
| 523 | * e.g. for Gregorian DAY_OF_MONTH, 31 | ||
| 524 | * Please see Calendar.getMaximum for descriptions on parameters and | ||
| 525 | * the return value. | ||
| 526 | */ | ||
| 527 | public int getMaximum(int field) | ||
| 528 | { | ||
| 529 | throw new NoSuchElementException(); | ||
| 530 | } | ||
| 531 | |||
| 532 | /** | ||
| 533 | * Returns highest minimum value for the given field if varies. | ||
| 534 | * Otherwise same as getMinimum(). For Gregorian, no difference. | ||
| 535 | * Please see Calendar.getGreatestMinimum for descriptions on parameters | ||
| 536 | * and the return value. | ||
| 537 | */ | ||
| 538 | public int getGreatestMinimum(int field) | ||
| 539 | { | ||
| 540 | throw new NoSuchElementException(); | ||
| 541 | } | ||
| 542 | |||
| 543 | /** | ||
| 544 | * Returns lowest maximum value for the given field if varies. | ||
| 545 | * Otherwise same as getMaximum(). For Gregorian DAY_OF_MONTH, 28 | ||
| 546 | * Please see Calendar.getLeastMaximum for descriptions on parameters and | ||
| 547 | * the return value. | ||
| 548 | */ | ||
| 549 | public int getLeastMaximum(int field) | ||
| 550 | { | ||
| 551 | throw new NoSuchElementException(); | ||
| 552 | } | ||
| 553 | |||
| 554 | private void readObject(ObjectInputStream s) { | ||
| 555 | throw new NoSuchElementException(); | ||
| 556 | } | ||
| 557 | } | ||
Empty file added.
| @@ -0,0 +1,169 @@ | |||
| 1 | /* | ||
| 2 | * @(#)ListResourceBundle.java 1.6 97/01/29 | ||
| 3 | * | ||
| 4 | * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved | ||
| 5 | * (C) Copyright IBM Corp. 1996 - All Rights Reserved | ||
| 6 | * | ||
| 7 | * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * The original version of this source code and documentation is copyrighted | ||
| 10 | * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These | ||
| 11 | * materials are provided under terms of a License Agreement between Taligent | ||
| 12 | * and Sun. This technology is protected by multiple US and International | ||
| 13 | * patents. This notice and attribution to Taligent may not be removed. | ||
| 14 | * Taligent is a registered trademark of Taligent, Inc. | ||
| 15 | * | ||
| 16 | * Permission to use, copy, modify, and distribute this software | ||
| 17 | * and its documentation for NON-COMMERCIAL purposes and without | ||
| 18 | * fee is hereby granted provided that this copyright notice | ||
| 19 | * appears in all copies. Please refer to the file "copyright.html" | ||
| 20 | * for further important copyright and licensing information. | ||
| 21 | * | ||
| 22 | * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF | ||
| 23 | * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 24 | * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 25 | * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR | ||
| 26 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | ||
| 27 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. | ||
| 28 | * | ||
| 29 | */ | ||
| 30 | |||
| 31 | package java.util; | ||
| 32 | import java.util.Hashtable; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * <code>ListResourceBundle</code> is a abstract subclass of | ||
| 36 | * <code>ResourceBundle</code> that manages resources for a locale | ||
| 37 | * in a convenient and easy to use list. See <code>ResourceBundle</code> for | ||
| 38 | * more information about resource bundles in general. | ||
| 39 | * | ||
| 40 | * <P> | ||
| 41 | * Subclasses must override <code>getContents</code> and provide an array, | ||
| 42 | * where each item in the array is a pair of objects. | ||
| 43 | * The first element of each pair is a <code>String</code> key, and the second | ||
| 44 | * is the value associated with that key. | ||
| 45 | * | ||
| 46 | * <p> | ||
| 47 | * In the following example, the keys are of the form "s1"... The actual | ||
| 48 | * keys are entirely up to your choice, so long as they are the same as | ||
| 49 | * the keys you use in your program to retrieve the objects from the bundle. | ||
| 50 | * Keys are case-sensitive. <code>MyResource</code> is the default version | ||
| 51 | * of the bundle family, and <code>MyResource_fr</code> is the french version: | ||
| 52 | * <blockquote> | ||
| 53 | * <pre> | ||
| 54 | * //==================== | ||
| 55 | * class MyResource extends ListResourceBundle { | ||
| 56 | * public Object[][] getContents() { | ||
| 57 | * return contents; | ||
| 58 | * } | ||
| 59 | * static final Object[][] contents = { | ||
| 60 | * // LOCALIZE THIS | ||
| 61 | * {"s1", "3"}, // starting value in choice field | ||
| 62 | * {"s2", "MyDisk"}, // starting value in string field | ||
| 63 | * {"s3", "3 Mar 96"}, // starting value in date field | ||
| 64 | * {"s4", "The disk '{1}' contained {0} on {2}."}, // initial pattern | ||
| 65 | * {"s5", "0"}, // first choice number | ||
| 66 | * {"s6", "no files"}, // first choice value | ||
| 67 | * {"s7", "1"}, // second choice number | ||
| 68 | * {"s8", "one file"}, // second choice value | ||
| 69 | * {"s9", "2"}, // third choice number | ||
| 70 | * {"s10", "{0}|3 files"}, // third choice value | ||
| 71 | * {"s11", "format threw an exception: {0}"}, // generic exception message | ||
| 72 | * {"s12", "ERROR"}, // what to show in field in case of error | ||
| 73 | * {"s14", "Result"}, // label for formatted stuff | ||
| 74 | * {"s13", "Dialog"}, // standard font | ||
| 75 | * {"s15", "Pattern"}, // label for standard pattern | ||
| 76 | * {"s16", new Dimension(1,5)} // real object, not just string | ||
| 77 | * // END OF MATERIAL TO LOCALIZE | ||
| 78 | * }; | ||
| 79 | * } | ||
| 80 | * //==================== | ||
| 81 | * class MyResource_fr extends ListResourceBundle { | ||
| 82 | * public Object[][] getContents() { | ||
| 83 | * return contents; | ||
| 84 | } | ||
| 85 | * static final Object[][] contents = { | ||
| 86 | * // LOCALIZE THIS | ||
| 87 | * {"s1", "3"}, // starting value in choice field | ||
| 88 | * {"s2", "MonDisk"}, // starting value in string field | ||
| 89 | * {"s3", "3 Mar 96"}, // starting value in date field | ||
| 90 | * {"s4", "Le disk '{1}' a {0} a {2}."}, // initial pattern | ||
| 91 | * {"s5", "0"}, // first choice number | ||
| 92 | * {"s6", "pas de files"}, // first choice value | ||
| 93 | * {"s7", "1"}, // second choice number | ||
| 94 | * {"s8", "une file"}, // second choice value | ||
| 95 | * {"s9", "2"}, // third choice number | ||
| 96 | * {"s10", "{0}|3 files"}, // third choice value | ||
| 97 | * {"s11", "Le format a jete une exception: {0}"}, // generic exception message | ||
| 98 | * {"s12", "ERROR"}, // what to show in field in case of error | ||
| 99 | * {"s14", "Resulte"}, // label for formatted stuff | ||
| 100 | * {"s13", "Dialogue"}, // standard font | ||
| 101 | * {"s15", "Pattern"}, // label for standard pattern | ||
| 102 | * {"s16", new Dimension(1,3)} // real object, not just string | ||
| 103 | * // END OF MATERIAL TO LOCALIZE | ||
| 104 | * }; | ||
| 105 | * } | ||
| 106 | * </pre> | ||
| 107 | * </blockquote> | ||
| 108 | * @see ResourceBundle | ||
| 109 | * @see PropertyResourceBundle | ||
| 110 | */ | ||
| 111 | public abstract class ListResourceBundle extends ResourceBundle { | ||
| 112 | /** | ||
| 113 | * Override of ResourceBundle, same semantics | ||
| 114 | */ | ||
| 115 | public final Object handleGetObject(String key) { | ||
| 116 | // lazily load the lookup hashtable. | ||
| 117 | if (lookup == null) { | ||
| 118 | loadLookup(); | ||
| 119 | } | ||
| 120 | return lookup.get(key); // this class ignores locales | ||
| 121 | } | ||
| 122 | |||
| 123 | /** | ||
| 124 | * Implementation of ResourceBundle.getKeys. | ||
| 125 | */ | ||
| 126 | public Enumeration getKeys() { | ||
| 127 | // lazily load the lookup hashtable. | ||
| 128 | if (lookup == null) { | ||
| 129 | loadLookup(); | ||
| 130 | } | ||
| 131 | Enumeration result = null; | ||
| 132 | if (parent != null) { | ||
| 133 | Hashtable temp = new Hashtable(); | ||
| 134 | for (Enumeration parentKeys = parent.getKeys() ; | ||
| 135 | parentKeys.hasMoreElements() ; /* nothing */) { | ||
| 136 | temp.put(parentKeys.nextElement(), this); | ||
| 137 | } | ||
| 138 | for (Enumeration thisKeys = lookup.keys(); | ||
| 139 | thisKeys.hasMoreElements() ; /* nothing */) { | ||
| 140 | temp.put(thisKeys.nextElement(), this); | ||
| 141 | } | ||
| 142 | result = temp.keys(); | ||
| 143 | } else { | ||
| 144 | result = lookup.keys(); | ||
| 145 | } | ||
| 146 | return result; | ||
| 147 | } | ||
| 148 | |||
| 149 | /** | ||
| 150 | * See class description. | ||
| 151 | */ | ||
| 152 | abstract protected Object[][] getContents(); | ||
| 153 | |||
| 154 | // ==================privates==================== | ||
| 155 | |||
| 156 | /** | ||
| 157 | * We lazily load the lookup hashtable. This function does the | ||
| 158 | * loading. | ||
| 159 | */ | ||
| 160 | private void loadLookup() { | ||
| 161 | Object[][] contents = getContents(); | ||
| 162 | lookup = new Hashtable(contents.length); | ||
| 163 | for (int i = 0; i < contents.length; ++i) { | ||
| 164 | lookup.put(contents[i][0],contents[i][1]); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | private Hashtable lookup = null; | ||
| 169 | } | ||
| @@ -0,0 +1,631 @@ | |||
| 1 | /* | ||
| 2 | * @(#)Locale.java 1.21 97/01/29 | ||
| 3 | * | ||
| 4 | * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved | ||
| 5 | * (C) Copyright IBM Corp. 1996 - All Rights Reserved | ||
| 6 | * | ||
| 7 | * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * The original version of this source code and documentation is copyrighted | ||
| 10 | * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These | ||
| 11 | * materials are provided under terms of a License Agreement between Taligent | ||
| 12 | * and Sun. This technology is protected by multiple US and International | ||
| 13 | * patents. This notice and attribution to Taligent may not be removed. | ||
| 14 | * Taligent is a registered trademark of Taligent, Inc. | ||
| 15 | * | ||
| 16 | * Permission to use, copy, modify, and distribute this software | ||
| 17 | * and its documentation for NON-COMMERCIAL purposes and without | ||
| 18 | * fee is hereby granted provided that this copyright notice | ||
| 19 | * appears in all copies. Please refer to the file "copyright.html" | ||
| 20 | * for further important copyright and licensing information. | ||
| 21 | * | ||
| 22 | * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF | ||
| 23 | * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 24 | * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 25 | * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR | ||
| 26 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | ||
| 27 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. | ||
| 28 | * | ||
| 29 | */ | ||
| 30 | |||
| 31 | package java.util; | ||
| 32 | import java.io.Serializable; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * | ||
| 36 | * A <code>Locale</code> object represents a specific geographical, political, | ||
| 37 | * or cultural region. An operation that requires a <code>Locale</code> to perform | ||
| 38 | * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code> | ||
| 39 | * to tailor information for the user. For example, displaying a number | ||
| 40 | * is a locale-sensitive operation--the number should be formatted | ||
| 41 | * according to the customs/conventions of the user's native country, | ||
| 42 | * region, or culture. | ||
| 43 | * | ||
| 44 | * <P> | ||
| 45 | * You create a <code>Locale</code> object using one of the two constructors in | ||
| 46 | * this class: | ||
| 47 | * <blockquote> | ||
| 48 | * <pre> | ||
| 49 | * Locale(String language, String country) | ||
| 50 | * Locale(String language, String country, String variant) | ||
| 51 | * </pre> | ||
| 52 | * </blockquote> | ||
| 53 | * The first argument to both constructors is a valid <STRONG>ISO | ||
| 54 | * Language Code.</STRONG> These codes are the lower-case two-letter | ||
| 55 | * codes as defined by ISO-639. | ||
| 56 | * You can find a full list of these codes at a number of sites, such as: | ||
| 57 | * <BR><a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt"> | ||
| 58 | * <code>http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</code></a> | ||
| 59 | * | ||
| 60 | * <P> | ||
| 61 | * The second argument to both constructors is a valid <STRONG>ISO Country | ||
| 62 | * Code.</STRONG> These codes are the upper-case two-letter codes | ||
| 63 | * as defined by ISO-3166. | ||
| 64 | * You can find a full list of these codes at a number of sites, such as: | ||
| 65 | * <BR><a href="http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html"> | ||
| 66 | * <code>http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html</code></a> | ||
| 67 | * | ||
| 68 | * <P> | ||
| 69 | * The second constructor requires a third argument--the <STRONG>Variant.</STRONG> | ||
| 70 | * The Variant codes are vendor and browser-specific. | ||
| 71 | * For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX. | ||
| 72 | * Where there are two variants, separate them with an underscore, and | ||
| 73 | * put the most important one first. For | ||
| 74 | * example, a Traditional Spanish collation might be referenced, with | ||
| 75 | * "ES", "ES", "Traditional_WIN". | ||
| 76 | * | ||
| 77 | * <P> | ||
| 78 | * Because a <code>Locale</code> object is just an identifier for a region, | ||
| 79 | * no validity check is performed when you construct a <code>Locale</code>. | ||
| 80 | * If you want to see whether particular resources are available for the | ||
| 81 | * <code>Locale</code> you construct, you must query those resources. For | ||
| 82 | * example, ask the <code>NumberFormat</code> for the locales it supports | ||
| 83 | * using its <code>getAvailableLocales</code> method. | ||
| 84 | * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular | ||
| 85 | * locale, you get back the best available match, not necessarily | ||
| 86 | * precisely what you asked for. For more information, look at | ||
| 87 | * <a href="java.util.ResourceBundle.html"><code>ResourceBundle</code></a>. | ||
| 88 | * | ||
| 89 | * <P> | ||
| 90 | * The <code>Locale</code> class provides a number of convenient constants | ||
| 91 | * that you can use to create <code>Locale</code> objects for commonly used | ||
| 92 | * locales. For example, the following creates a <code>Locale</code> object | ||
| 93 | * for the United States: | ||
| 94 | * <blockquote> | ||
| 95 | * <pre> | ||
| 96 | * Locale.US | ||
| 97 | * </pre> | ||
| 98 | * </blockquote> | ||
| 99 | * | ||
| 100 | * <P> | ||
| 101 | * Once you've created a <code>Locale</code> you can query it for information about | ||
| 102 | * itself. Use <code>getCountry</code> to get the ISO Country Code and | ||
| 103 | * <code>getLanguage</code> to get the ISO Language Code. You can | ||
| 104 | * use <code>getDisplayCountry</code> to get the | ||
| 105 | * name of the country suitable for displaying to the user. Similarly, | ||
| 106 | * you can use <code>getDisplayLanguage</code> to get the name of | ||
| 107 | * the language suitable for displaying to the user. Interestingly, | ||
| 108 | * the <code>getDisplayXXX</code> methods are themselves locale-sensitive | ||
| 109 | * and have two versions: one that uses the default locale and one | ||
| 110 | * that uses the locale specified as an argument. | ||
| 111 | * | ||
| 112 | * <P> | ||
| 113 | * The JDK provides a number of classes that perform locale-sensitive | ||
| 114 | * operations. For example, the <code>NumberFormat</code> class formats | ||
| 115 | * numbers, currency, or percentages in a locale-sensitive manner. Classes | ||
| 116 | * such as <code>NumberFormat</code> have a number of convenience methods | ||
| 117 | * for creating a default object of that type. For example, the | ||
| 118 | * <code>NumberFormat</code> class provides these three convenience methods | ||
| 119 | * for creating a default <code>NumberFormat</code> object: | ||
| 120 | * <blockquote> | ||
| 121 | * <pre> | ||
| 122 | * NumberFormat.getInstance() | ||
| 123 | * NumberFormat.getCurrencyInstance() | ||
| 124 | * NumberFormat.getPercentInstance() | ||
| 125 | * </pre> | ||
| 126 | * </blockquote> | ||
| 127 | * These methods have two variants; one with an explicit locale | ||
| 128 | * and one without; the latter using the default locale. | ||
| 129 | * <blockquote> | ||
| 130 | * <pre> | ||
| 131 | * NumberFormat.getInstance(myLocale) | ||
| 132 | * NumberFormat.getCurrencyInstance(myLocale) | ||
| 133 | * NumberFormat.getPercentInstance(myLocale) | ||
| 134 | * </pre> | ||
| 135 | * </blockquote> | ||
| 136 | * A <code>Locale</code> is the mechanism for identifying the kind of object | ||
| 137 | * (<code>NumberFormat</code>) that you would like to get. The locale is | ||
| 138 | * <STRONG>just</STRONG> a mechanism for identifying objects, | ||
| 139 | * <STRONG>not</STRONG> a container for the objects themselves. | ||
| 140 | * | ||
| 141 | * <P> | ||
| 142 | * Each class that performs locale-sensitive operations allows you | ||
| 143 | * to get all the available objects of that type. You can sift | ||
| 144 | * through these objects by language, country, or variant, | ||
| 145 | * and use the display names to present a menu to the user. | ||
| 146 | * For example, you can create a menu of all the collation objects | ||
| 147 | * suitable for a given language. Such classes must implement these | ||
| 148 | * three class methods: | ||
| 149 | * <blockquote> | ||
| 150 | * <pre> | ||
| 151 | * public static Locale[] getAvailableLocales() | ||
| 152 | * public static String getDisplayName(Locale objectLocale, | ||
| 153 | * Locale displayLocale) | ||
| 154 | * public static final String getDisplayName(Locale objectLocale) | ||
| 155 | * // getDisplayName will throw MissingResourceException if the locale | ||
| 156 | * // is not one of the available locales. | ||
| 157 | * </pre> | ||
| 158 | * </blockquote> | ||
| 159 | * | ||
| 160 | * @see ResourceBundle | ||
| 161 | * @see java.text.Format | ||
| 162 | * @see java.text.NumberFormat | ||
| 163 | * @see java.text.Collation | ||
| 164 | * @version 1.21 29 Jan 1997 | ||
| 165 | * @author Mark Davis | ||
| 166 | */ | ||
| 167 | |||
| 168 | public final class Locale implements Cloneable, Serializable { | ||
| 169 | |||
| 170 | /** Useful constant for language. | ||
| 171 | */ | ||
| 172 | static public final Locale ENGLISH = new Locale("en","",""); | ||
| 173 | |||
| 174 | /** Useful constant for language. | ||
| 175 | */ | ||
| 176 | static public final Locale FRENCH = new Locale("fr","",""); | ||
| 177 | |||
| 178 | /** Useful constant for language. | ||
| 179 | */ | ||
| 180 | static public final Locale GERMAN = new Locale("de","",""); | ||
| 181 | |||
| 182 | /** Useful constant for language. | ||
| 183 | */ | ||
| 184 | static public final Locale ITALIAN = new Locale("it","",""); | ||
| 185 | |||
| 186 | /** Useful constant for language. | ||
| 187 | */ | ||
| 188 | static public final Locale JAPANESE = new Locale("ja","",""); | ||
| 189 | |||
| 190 | /** Useful constant for language. | ||
| 191 | */ | ||
| 192 | static public final Locale KOREAN = new Locale("ko","",""); | ||
| 193 | |||
| 194 | /** Useful constant for language. | ||
| 195 | */ | ||
| 196 | static public final Locale CHINESE = new Locale("zh","",""); | ||
| 197 | |||
| 198 | /** Useful constant for language. | ||
| 199 | */ | ||
| 200 | static public final Locale SIMPLIFIED_CHINESE = new Locale("zh","CN",""); | ||
| 201 | |||
| 202 | /** Useful constant for language. | ||
| 203 | */ | ||
| 204 | static public final Locale TRADITIONAL_CHINESE = new Locale("zh","TW",""); | ||
| 205 | |||
| 206 | /** Useful constant for country. | ||
| 207 | */ | ||
| 208 | static public final Locale FRANCE = new Locale("fr","FR",""); | ||
| 209 | |||
| 210 | /** Useful constant for country. | ||
| 211 | */ | ||
| 212 | static public final Locale GERMANY = new Locale("de","DE",""); | ||
| 213 | |||
| 214 | /** Useful constant for country. | ||
| 215 | */ | ||
| 216 | static public final Locale ITALY = new Locale("it","IT",""); | ||
| 217 | |||
| 218 | /** Useful constant for country. | ||
| 219 | */ | ||
| 220 | static public final Locale JAPAN = new Locale("ja","JP",""); | ||
| 221 | |||
| 222 | /** Useful constant for country. | ||
| 223 | */ | ||
| 224 | static public final Locale KOREA = new Locale("ko","KR",""); | ||
| 225 | |||
| 226 | /** Useful constant for country. | ||
| 227 | */ | ||
| 228 | static public final Locale CHINA = new Locale("zh","CN",""); | ||
| 229 | |||
| 230 | /** Useful constant for country. | ||
| 231 | */ | ||
| 232 | static public final Locale PRC = new Locale("zh","CN",""); | ||
| 233 | |||
| 234 | /** Useful constant for country. | ||
| 235 | */ | ||
| 236 | static public final Locale TAIWAN = new Locale("zh","TW",""); | ||
| 237 | |||
| 238 | /** Useful constant for country. | ||
| 239 | */ | ||
| 240 | static public final Locale UK = new Locale("en","GB",""); | ||
| 241 | |||
| 242 | /** Useful constant for country. | ||
| 243 | */ | ||
| 244 | static public final Locale US = new Locale("en","US",""); | ||
| 245 | |||
| 246 | /** Useful constant for country. | ||
| 247 | */ | ||
| 248 | static public final Locale CANADA = new Locale("en","CA",""); | ||
| 249 | |||
| 250 | /** Useful constant for country. | ||
| 251 | */ | ||
| 252 | static public final Locale CANADA_FRENCH = new Locale("fr","CA",""); | ||
| 253 | |||
| 254 | /** | ||
| 255 | * Construct a locale from language, country, variant. | ||
| 256 | * @param language lowercase two-letter ISO-639 code. | ||
| 257 | * @param country uppercase two-letter ISO-3166 code. | ||
| 258 | * @param variant vendor and browser specific code. See class description. | ||
| 259 | */ | ||
| 260 | public Locale(String language, String country, String variant) { | ||
| 261 | this.language = toLowerCase(language); | ||
| 262 | this.country = toUpperCase(country); | ||
| 263 | this.variant = toUpperCase(variant); | ||
| 264 | } | ||
| 265 | |||
| 266 | /** | ||
| 267 | * Construct a locale from language, country. | ||
| 268 | * @param language lowercase two-letter ISO-639 code. | ||
| 269 | * @param country uppercase two-letter ISO-3166 code. | ||
| 270 | */ | ||
| 271 | public Locale(String language, String country) { | ||
| 272 | this.language = toLowerCase(language); | ||
| 273 | this.country = toUpperCase(country); | ||
| 274 | this.variant = ""; | ||
| 275 | } | ||
| 276 | |||
| 277 | /** | ||
| 278 | * Common method of getting the current default Locale. | ||
| 279 | * Used for the presentation: menus, dialogs, etc. | ||
| 280 | * Generally set once when your applet or application is initialized, | ||
| 281 | * then never reset. (If you do reset the default locale, you | ||
| 282 | * probably want to reload your GUI, so that the change is reflected | ||
| 283 | * in your interface.) | ||
| 284 | * <p>More advanced programs will allow users to use different locales | ||
| 285 | * for different fields, e.g. in a spreadsheet. | ||
| 286 | * <BR>Note that the initial setting will match the host system. | ||
| 287 | */ | ||
| 288 | public static synchronized Locale getDefault() { | ||
| 289 | if (defaultLocale == null) { | ||
| 290 | String language = System.getProperty("user.language", "EN"); | ||
| 291 | String region = System.getProperty("user.region", ""); | ||
| 292 | |||
| 293 | defaultLocale = new Locale(language, region); | ||
| 294 | } | ||
| 295 | return defaultLocale; | ||
| 296 | } | ||
| 297 | |||
| 298 | /** | ||
| 299 | * Sets the default. | ||
| 300 | * Normally set once at the beginning of applet or application, | ||
| 301 | * then never reset. <code>setDefault</code> does not reset the host locale. | ||
| 302 | * @param newLocale Locale to set to. | ||
| 303 | */ | ||
| 304 | public static synchronized void setDefault(Locale newLocale) { | ||
| 305 | SecurityManager security = System.getSecurityManager(); | ||
| 306 | if (security != null) { | ||
| 307 | security.checkPropertyAccess("user.language"); | ||
| 308 | } | ||
| 309 | defaultLocale = newLocale; | ||
| 310 | } | ||
| 311 | |||
| 312 | /** | ||
| 313 | * Getter for programmatic name of field, | ||
| 314 | * an lowercased two-letter ISO-639 code. | ||
| 315 | * @see #getDisplayLanguage | ||
| 316 | */ | ||
| 317 | public String getLanguage() { | ||
| 318 | return language; | ||
| 319 | } | ||
| 320 | |||
| 321 | /** | ||
| 322 | * Getter for programmatic name of field, | ||
| 323 | * an uppercased two-letter ISO-3166 code. | ||
| 324 | * @see #getDisplayCountry | ||
| 325 | */ | ||
| 326 | public String getCountry() { | ||
| 327 | return country; | ||
| 328 | } | ||
| 329 | |||
| 330 | /** | ||
| 331 | * Getter for programmatic name of field. | ||
| 332 | * @see #getDisplayVariant | ||
| 333 | */ | ||
| 334 | public String getVariant() { | ||
| 335 | return variant; | ||
| 336 | } | ||
| 337 | |||
| 338 | /** | ||
| 339 | * Getter for the programmatic name of the entire locale, | ||
| 340 | * with the language, country and variant separated by underbars. | ||
| 341 | * If a field is missing, at most one underbar will occur. | ||
| 342 | * Example: "EN", "DE_DE", "EN_US_WIN", "DE_POSIX", "FR_MAC" | ||
| 343 | * @see #getDisplayName | ||
| 344 | */ | ||
| 345 | public final String toString() { | ||
| 346 | StringBuffer result = new StringBuffer(language); | ||
| 347 | if (country.length() != 0) { | ||
| 348 | result.append('_'); | ||
| 349 | result.append(country); | ||
| 350 | if (variant.length() != 0) { | ||
| 351 | result.append('_'); | ||
| 352 | result.append(variant); | ||
| 353 | } | ||
| 354 | } | ||
| 355 | return result.toString(); | ||
| 356 | } | ||
| 357 | |||
| 358 | /** | ||
| 359 | * Getter for the three-letter ISO language abbreviation | ||
| 360 | * of the locale. | ||
| 361 | * @exception MissingResourceException Throws MissingResourceException if the | ||
| 362 | * three-letter language abbreviation is not available for this locale. | ||
| 363 | */ | ||
| 364 | public String getISO3Language() throws MissingResourceException { | ||
| 365 | ResourceBundle resource | ||
| 366 | = ResourceBundle.getBundle | ||
| 367 | ("java.text.resources.LocaleElements", this); | ||
| 368 | return resource.getString("ShortLanguage"); | ||
| 369 | } | ||
| 370 | |||
| 371 | /** | ||
| 372 | * Getter for the three-letter ISO country abbreviation | ||
| 373 | * of the locale. | ||
| 374 | * @exception MissingResourceException Throws MissingResourceException if the | ||
| 375 | * three-letter language abbreviation is not available for this locale. | ||
| 376 | */ | ||
| 377 | public String getISO3Country() throws MissingResourceException { | ||
| 378 | ResourceBundle resource = | ||
| 379 | ResourceBundle.getBundle | ||
| 380 | ("java.text.resources.LocaleElements", this); | ||
| 381 | return resource.getString("ShortCountry"); | ||
| 382 | } | ||
| 383 | |||
| 384 | /** | ||
| 385 | * Getter for the Locale ID, as used in Windows. | ||
| 386 | * @exception MissingResourceException Throws MissingResourceException if there is | ||
| 387 | * no LCID associated with the locale. | ||
| 388 | */ | ||
| 389 | // FIXME this should go away completely! | ||
| 390 | private int getLCID() throws MissingResourceException { | ||
| 391 | ResourceBundle resource = | ||
| 392 | ResourceBundle.getBundle | ||
| 393 | ("java.text.resources.LocaleElements", this); | ||
| 394 | String lcid = resource.getString("LocaleID"); | ||
| 395 | return Integer.parseInt(lcid,16); | ||
| 396 | } | ||
| 397 | |||
| 398 | /** | ||
| 399 | * Getter for display of field to user. | ||
| 400 | * If the localized name is not found, returns the ISO code. | ||
| 401 | * The desired user language is from the default locale. | ||
| 402 | */ | ||
| 403 | public final String getDisplayLanguage() { | ||
| 404 | return getDisplayLanguage(getDefault()); | ||
| 405 | } | ||
| 406 | |||
| 407 | /** | ||
| 408 | * Getter for display of field to user. | ||
| 409 | * If the localized name is not found, returns the ISO codes. | ||
| 410 | * Example: "English (UK)", "Deutch", "Germany" | ||
| 411 | * @param inLocale specifies the desired user language. | ||
| 412 | */ | ||
| 413 | public String getDisplayLanguage(Locale inLocale) { | ||
| 414 | try { | ||
| 415 | ResourceBundle resource = | ||
| 416 | ResourceBundle.getBundle | ||
| 417 | ("java.text.resources.LocaleElements", this); | ||
| 418 | return findStringMatch((String[][])resource.getObject("Languages"), | ||
| 419 | inLocale.language, language); | ||
| 420 | } catch (Exception e) { | ||
| 421 | return language; | ||
| 422 | } | ||
| 423 | } | ||
| 424 | |||
| 425 | /** | ||
| 426 | * Getter for display of field to user. | ||
| 427 | * If the localized name is not found, returns the ISO code. | ||
| 428 | * The default locale is used for the presentation language. | ||
| 429 | */ | ||
| 430 | public final String getDisplayCountry() { | ||
| 431 | return getDisplayCountry(getDefault()); | ||
| 432 | } | ||
| 433 | |||
| 434 | /** | ||
| 435 | * Getter for display of field to user. | ||
| 436 | * If the localized name is not found, returns the ISO code. | ||
| 437 | * @param inLocale specifies the desired user language. | ||
| 438 | */ | ||
| 439 | public String getDisplayCountry(Locale inLocale) { | ||
| 440 | try { | ||
| 441 | ResourceBundle resource = | ||
| 442 | ResourceBundle.getBundle | ||
| 443 | ("java.text.resources.LocaleElements",this); | ||
| 444 | return findStringMatch((String[][])resource.getObject("Countries"), | ||
| 445 | inLocale.language, language); | ||
| 446 | } catch (Exception e) { | ||
| 447 | return country; | ||
| 448 | } | ||
| 449 | } | ||
| 450 | |||
| 451 | /** | ||
| 452 | * Getter for display of field to user. | ||
| 453 | * If the localized name is not found, returns the variant code. | ||
| 454 | * The default locale is used for the presentation language. | ||
| 455 | */ | ||
| 456 | public final String getDisplayVariant() { | ||
| 457 | return getDisplayVariant(getDefault()); | ||
| 458 | } | ||
| 459 | |||
| 460 | /** | ||
| 461 | * Getter for display of field to user | ||
| 462 | * If the localized name is not found, returns the variant code. | ||
| 463 | * @param inLocale specifies the desired user language. | ||
| 464 | */ | ||
| 465 | public String getDisplayVariant(Locale inLocale) { | ||
| 466 | try { | ||
| 467 | ResourceBundle resource = | ||
| 468 | ResourceBundle.getBundle | ||
| 469 | ("java.text.resources.LocaleElements", inLocale); | ||
| 470 | String[][] pairedStrings = (String[][])resource.getObject("Variants"); | ||
| 471 | if (pairedStrings == null) | ||
| 472 | return variant; | ||
| 473 | return findStringMatch(pairedStrings, inLocale.language, language); | ||
| 474 | } catch (Exception e) { | ||
| 475 | return variant; | ||
| 476 | } | ||
| 477 | } | ||
| 478 | |||
| 479 | /** | ||
| 480 | * Getter for display of the entire locale to user. | ||
| 481 | * If the localized name is not found, uses the ISO codes. | ||
| 482 | * The default locale is used for the presentation language. | ||
| 483 | */ | ||
| 484 | public final String getDisplayName() { | ||
| 485 | return getDisplayName(getDefault()); | ||
| 486 | } | ||
| 487 | |||
| 488 | /** | ||
| 489 | * Getter for display of the entire locale to user. | ||
| 490 | * If the localized name is not found, uses the ISO codes | ||
| 491 | * @param inLocale specifies the desired user language. | ||
| 492 | */ | ||
| 493 | public String getDisplayName(Locale inLocale) { | ||
| 494 | // TODO: use pattern string from locale data | ||
| 495 | StringBuffer result = new StringBuffer (getDisplayLanguage(inLocale)); | ||
| 496 | String aCountry = getDisplayCountry(inLocale); | ||
| 497 | String aVariant = getDisplayVariant(inLocale); | ||
| 498 | if (aCountry.length() != 0 || aVariant.length() != 0) { | ||
| 499 | result.append(" ("); | ||
| 500 | result.append(getDisplayCountry(inLocale)); | ||
| 501 | if (aCountry.length() != 0 && aVariant.length() != 0) | ||
| 502 | result.append(","); | ||
| 503 | result.append(getDisplayVariant(inLocale)); | ||
| 504 | result.append(")"); | ||
| 505 | } | ||
| 506 | return result.toString(); | ||
| 507 | } | ||
| 508 | |||
| 509 | /** | ||
| 510 | * Overrides Cloneable | ||
| 511 | */ | ||
| 512 | public Object clone() | ||
| 513 | { | ||
| 514 | try { | ||
| 515 | Locale that = (Locale)super.clone(); | ||
| 516 | return that; | ||
| 517 | } catch (CloneNotSupportedException e) { | ||
| 518 | throw new InternalError(); | ||
| 519 | } | ||
| 520 | } | ||
| 521 | |||
| 522 | /** | ||
| 523 | * Override hashCode. | ||
| 524 | * Since Locales are often used in hashtables, caches the value | ||
| 525 | * for speed. | ||
| 526 | */ | ||
| 527 | // XXX Depending on performance of synchronized, may want to | ||
| 528 | // XXX just compute in constructor. | ||
| 529 | public synchronized int hashCode() { | ||
| 530 | if (hashcode == -1) { | ||
| 531 | hashcode = | ||
| 532 | language.hashCode() ^ | ||
| 533 | country.hashCode() ^ | ||
| 534 | variant.hashCode(); | ||
| 535 | } | ||
| 536 | return hashcode; | ||
| 537 | } | ||
| 538 | |||
| 539 | // Overrides | ||
| 540 | |||
| 541 | public boolean equals(Object obj) { | ||
| 542 | if (this == obj) // quick check | ||
| 543 | return true; | ||
| 544 | if (!(obj instanceof Locale)) // (1) same object? | ||
| 545 | return false; | ||
| 546 | Locale other = (Locale) obj; | ||
| 547 | if (hashCode() != other.hashCode()) return false; // quick check | ||
| 548 | if (!language.equals(other.language)) return false; | ||
| 549 | if (!country.equals(other.country)) return false; | ||
| 550 | if (!variant.equals(other.variant)) return false; | ||
| 551 | return true; // we made it through the guantlet. | ||
| 552 | // (1) We don't check super.equals since it is Object. | ||
| 553 | // Since Locale is final, we don't have to check both directions. | ||
| 554 | } | ||
| 555 | |||
| 556 | // ================= privates ===================================== | ||
| 557 | |||
| 558 | // XXX instance and class variables. For now keep these separate, since it is | ||
| 559 | // faster to match. Later, make into single string. | ||
| 560 | |||
| 561 | private String language = ""; | ||
| 562 | private String country = ""; | ||
| 563 | private String variant = ""; | ||
| 564 | |||
| 565 | private /*FIXME(83) transient*/ int hashcode = -1; // lazy evaluated | ||
| 566 | |||
| 567 | private static Locale defaultLocale = null; | ||
| 568 | |||
| 569 | /* | ||
| 570 | * Locale needs its own, locale insenitive version of toLowerCase to | ||
| 571 | * avoid circularity problems between Locale and String. | ||
| 572 | * The most straightforward algorithm is used. Look at optimizations later. | ||
| 573 | */ | ||
| 574 | private String toLowerCase(String str) { | ||
| 575 | char[] buf = str.toCharArray(); | ||
| 576 | for (int i = 0; i < buf.length; i++) { | ||
| 577 | buf[i] = Character.toLowerCase( buf[i] ); | ||
| 578 | } | ||
| 579 | return new String( buf ); | ||
| 580 | } | ||
| 581 | |||
| 582 | /* | ||
| 583 | * Locale needs its own, locale insenitive version of toUpperCase to | ||
| 584 | * avoid circularity problems between Locale and String. | ||
| 585 | * The most straightforward algorithm is used. Look at optimizations later. | ||
| 586 | */ | ||
| 587 | private String toUpperCase(String str) { | ||
| 588 | char[] buf = str.toCharArray(); | ||
| 589 | for (int i = 0; i < buf.length; i++) { | ||
| 590 | buf[i] = Character.toUpperCase( buf[i] ); | ||
| 591 | } | ||
| 592 | return new String( buf ); | ||
| 593 | } | ||
| 594 | |||
| 595 | private String findStringMatch(String[][] languages, | ||
| 596 | String desiredLanguage, String fallbackLanguage) | ||
| 597 | { | ||
| 598 | for (int i = 0; i < languages.length; ++i) | ||
| 599 | if (desiredLanguage.equals(languages[i][0])) | ||
| 600 | return languages[i][1]; | ||
| 601 | if (!fallbackLanguage.equals(desiredLanguage)) | ||
| 602 | for (int i = 0; i < languages.length; ++i) | ||
| 603 | if (fallbackLanguage.equals(languages[i][0])) | ||
| 604 | return languages[i][1]; | ||
| 605 | if (!"EN".equals(desiredLanguage) && "EN".equals(fallbackLanguage)) | ||
| 606 | for (int i = 0; i < languages.length; ++i) | ||
| 607 | if ("EN".equals(languages[i][0])) | ||
| 608 | return languages[i][1]; | ||
| 609 | return ""; | ||
| 610 | } | ||
| 611 | /* | ||
| 612 | * Does an equals check, plus an empty field in this means a wildcard; | ||
| 613 | * matches any other field in other. | ||
| 614 | */ | ||
| 615 | private boolean matches (Locale other) { | ||
| 616 | //System.out.println("language:" + language + "," + other.language); | ||
| 617 | if (language.length() != 0) | ||
| 618 | if (!language.equals(other.language)) | ||
| 619 | return false; | ||
| 620 | //System.out.println("country:" + country + "," + other.country); | ||
| 621 | if (country.length() != 0) | ||
| 622 | if (!country.equals(other.country)) | ||
| 623 | return false; | ||
| 624 | //System.out.println("variant:" + variant + "," + other.variant); | ||
| 625 | if (variant.length() != 0) | ||
| 626 | if (!variant.equals(other.variant)) | ||
| 627 | return false; | ||
| 628 | return true; // whew, we made it through the guantlet. | ||
| 629 | } | ||
| 630 | |||
| 631 | } | ||
| @@ -0,0 +1,73 @@ | |||
| 1 | /* | ||
| 2 | * @(#)MissingResourceException.java 1.4 97/01/29 | ||
| 3 | * | ||
| 4 | * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved | ||
| 5 | * (C) Copyright IBM Corp. 1996 - All Rights Reserved | ||
| 6 | * | ||
| 7 | * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * The original version of this source code and documentation is copyrighted | ||
| 10 | * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These | ||
| 11 | * materials are provided under terms of a License Agreement between Taligent | ||
| 12 | * and Sun. This technology is protected by multiple US and International | ||
| 13 | * patents. This notice and attribution to Taligent may not be removed. | ||
| 14 | * Taligent is a registered trademark of Taligent, Inc. | ||
| 15 | * | ||
| 16 | * Permission to use, copy, modify, and distribute this software | ||
| 17 | * and its documentation for NON-COMMERCIAL purposes and without | ||
| 18 | * fee is hereby granted provided that this copyright notice | ||
| 19 | * appears in all copies. Please refer to the file "copyright.html" | ||
| 20 | * for further important copyright and licensing information. | ||
| 21 | * | ||
| 22 | * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF | ||
| 23 | * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 24 | * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 25 | * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR | ||
| 26 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | ||
| 27 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. | ||
| 28 | * | ||
| 29 | */ | ||
| 30 | |||
| 31 | package java.util; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * Signals that a resource is missing. | ||
| 35 | * @see java.io.Exception | ||
| 36 | * @see ResourceBundle | ||
| 37 | * @version 1.4, 01/29/97 | ||
| 38 | * @author Mark Davis | ||
| 39 | */ | ||
| 40 | public | ||
| 41 | class MissingResourceException extends RuntimeException { | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Constructs a MissingResourceException with the specified information. | ||
| 45 | * A detail message is a String that describes this particular exception. | ||
| 46 | * @param s the detail message | ||
| 47 | * @param classname the name of the resource class | ||
| 48 | * @param key the key for the missing resource. | ||
| 49 | */ | ||
| 50 | public MissingResourceException(String s, String className, String key) { | ||
| 51 | super(s); | ||
| 52 | this.className = className; | ||
| 53 | this.key = key; | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Gets parameter passed by constructor. | ||
| 58 | */ | ||
| 59 | public String getClassName() { | ||
| 60 | return className; | ||
| 61 | } | ||
| 62 | |||
| 63 | /** | ||
| 64 | * Gets parameter passed by constructor. | ||
| 65 | */ | ||
| 66 | public String getKey() { | ||
| 67 | return key; | ||
| 68 | } | ||
| 69 | |||
| 70 | //============ privates ============ | ||
| 71 | private String className; | ||
| 72 | private String key; | ||
| 73 | } | ||
Empty file added.
Empty file added.
Empty file added.
Empty file added.
| @@ -0,0 +1,121 @@ | |||
| 1 | /* | ||
| 2 | * @(#)PropertyResourceBundle.java 1.7 97/01/29 | ||
| 3 | * | ||
| 4 | * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved | ||
| 5 | * (C) Copyright IBM Corp. 1996 - All Rights Reserved | ||
| 6 | * | ||
| 7 | * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * The original version of this source code and documentation is copyrighted | ||
| 10 | * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These | ||
| 11 | * materials are provided under terms of a License Agreement between Taligent | ||
| 12 | * and Sun. This technology is protected by multiple US and International | ||
| 13 | * patents. This notice and attribution to Taligent may not be removed. | ||
| 14 | * Taligent is a registered trademark of Taligent, Inc. | ||
| 15 | * | ||
| 16 | * Permission to use, copy, modify, and distribute this software | ||
| 17 | * and its documentation for NON-COMMERCIAL purposes and without | ||
| 18 | * fee is hereby granted provided that this copyright notice | ||
| 19 | * appears in all copies. Please refer to the file "copyright.html" | ||
| 20 | * for further important copyright and licensing information. | ||
| 21 | * | ||
| 22 | * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF | ||
| 23 | * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 24 | * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 25 | * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR | ||
| 26 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | ||
| 27 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. | ||
| 28 | * | ||
| 29 | */ | ||
| 30 | package java.util; | ||
| 31 | |||
| 32 | import java.util.Properties; | ||
| 33 | import java.io.InputStream; | ||
| 34 | import java.io.IOException; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * <code>PropertyResourceBundle</code> is an abstract subclass of | ||
| 38 | * <code>ResourceBundle</code> that manages resources for a locale | ||
| 39 | * using a set of static strings from a property file. See | ||
| 40 | * <code>ResourceBundle</code> for more information about resource | ||
| 41 | * bundles in general. | ||
| 42 | * | ||
| 43 | * <p> | ||
| 44 | * The property file contains the keys that you use in your source code | ||
| 45 | * in calls to <code>ResourceBundle.getString</code> and similar methods, | ||
| 46 | * and their corresponding values, etc. | ||
| 47 | * The name of the property file indicates the resource bundle's family | ||
| 48 | * and locale. | ||
| 49 | * | ||
| 50 | * <p> | ||
| 51 | * In the following example, the keys are of the form "s1"... The actual | ||
| 52 | * keys are entirely up to your choice, so long as they are the same as | ||
| 53 | * the keys you use in your program to retrieve the objects from the bundle. | ||
| 54 | * Keys are case-sensitive. | ||
| 55 | * <blockquote> | ||
| 56 | * <pre> | ||
| 57 | * s1=3 | ||
| 58 | * s2=MeinDisk | ||
| 59 | * s3=3 Mar 96 | ||
| 60 | * s4=Der disk '{1}' a {0} a {2}. | ||
| 61 | * s5=0 | ||
| 62 | * s6=keine Datein | ||
| 63 | * s7=1 | ||
| 64 | * s8=ein Datei | ||
| 65 | * s9=2 | ||
| 66 | * s10={0}|3 Datein | ||
| 67 | * s11=Der Format worf ein Exception: {0} | ||
| 68 | * s12=ERROR | ||
| 69 | * s14=Resulte | ||
| 70 | * s13=Dialogue | ||
| 71 | * s15=Pattern | ||
| 72 | * s16=1,3 | ||
| 73 | * </pre> | ||
| 74 | * </blockquote> | ||
| 75 | * | ||
| 76 | * @see ResourceBundle | ||
| 77 | * @see ListResourceBundle | ||
| 78 | */ | ||
| 79 | public class PropertyResourceBundle extends ResourceBundle { | ||
| 80 | /** | ||
| 81 | * Creates a property resource | ||
| 82 | * @param file property file to read from. | ||
| 83 | */ | ||
| 84 | public PropertyResourceBundle (InputStream stream) throws IOException { | ||
| 85 | lookup.load(stream); | ||
| 86 | } | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Override of ResourceBundle, same semantics | ||
| 90 | */ | ||
| 91 | public Object handleGetObject(String key) { | ||
| 92 | Object obj = lookup.get(key); | ||
| 93 | return obj; // once serialization is in place, you can do non-strings | ||
| 94 | } | ||
| 95 | |||
| 96 | /** | ||
| 97 | * Implementation of ResourceBundle.getKeys. | ||
| 98 | */ | ||
| 99 | public Enumeration getKeys() { | ||
| 100 | Enumeration result = null; | ||
| 101 | if (parent != null) { | ||
| 102 | Hashtable temp = new Hashtable(); | ||
| 103 | for (Enumeration parentKeys = parent.getKeys() ; | ||
| 104 | parentKeys.hasMoreElements() ; /* nothing */) { | ||
| 105 | temp.put(parentKeys.nextElement(), this); | ||
| 106 | } | ||
| 107 | for (Enumeration thisKeys = lookup.keys(); | ||
| 108 | thisKeys.hasMoreElements() ; /* nothing */) { | ||
| 109 | temp.put(thisKeys.nextElement(), this); | ||
| 110 | } | ||
| 111 | result = temp.keys(); | ||
| 112 | } else { | ||
| 113 | result = lookup.keys(); | ||
| 114 | } | ||
| 115 | return result; | ||
| 116 | } | ||
| 117 | |||
| 118 | // ==================privates==================== | ||
| 119 | |||
| 120 | private Properties lookup = new Properties(); | ||
| 121 | } | ||
Empty file added.
| @@ -0,0 +1,536 @@ | |||
| 1 | /* | ||
| 2 | * @(#)ResourceBundle.java 1.15 97/01/29 | ||
| 3 | * | ||
| 4 | * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved | ||
| 5 | * (C) Copyright IBM Corp. 1996 - All Rights Reserved | ||
| 6 | * | ||
| 7 | * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * The original version of this source code and documentation is copyrighted | ||
| 10 | * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These | ||
| 11 | * materials are provided under terms of a License Agreement between Taligent | ||
| 12 | * and Sun. This technology is protected by multiple US and International | ||
| 13 | * patents. This notice and attribution to Taligent may not be removed. | ||
| 14 | * Taligent is a registered trademark of Taligent, Inc. | ||
| 15 | * | ||
| 16 | * Permission to use, copy, modify, and distribute this software | ||
| 17 | * and its documentation for NON-COMMERCIAL purposes and without | ||
| 18 | * fee is hereby granted provided that this copyright notice | ||
| 19 | * appears in all copies. Please refer to the file "copyright.html" | ||
| 20 | * for further important copyright and licensing information. | ||
| 21 | * | ||
| 22 | * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF | ||
| 23 | * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 24 | * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 25 | * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR | ||
| 26 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | ||
| 27 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. | ||
| 28 | * | ||
| 29 | */ | ||
| 30 | package java.util; | ||
| 31 | |||
| 32 | import java.io.InputStream; | ||
| 33 | import java.io.FileInputStream; | ||
| 34 | import java.util.Hashtable; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * | ||
| 38 | * Resource bundles contain locale-specific objects. | ||
| 39 | * When your program needs a locale-specific resource, | ||
| 40 | * a <code>String</code> for example, your program can load it | ||
| 41 | * from the resource bundle that is appropriate for the | ||
| 42 | * current user's locale. In this way, you can write | ||
| 43 | * program code that is largely independent of the user's | ||
| 44 | * locale isolating most, if not all, of the locale-specific | ||
| 45 | * information in resource bundles. | ||
| 46 | * | ||
| 47 | * <p> | ||
| 48 | * This allows you to write programs that can: | ||
| 49 | * <UL type=SQUARE> | ||
| 50 | * <LI> be easily localized, or translated, into different languages | ||
| 51 | * <LI> handle multiple locales at once | ||
| 52 | * <LI> be easily modified later to support even more locales | ||
| 53 | * </UL> | ||
| 54 | * | ||
| 55 | * <P> | ||
| 56 | * One resource bundle is, conceptually, a set of related classes that | ||
| 57 | * inherit from <code>ResourceBundle</code>. Each related subclass of | ||
| 58 | * <code>ResourceBundle</code> has the same base name plus an additional | ||
| 59 | * component that identifies its locale. For example, suppose your resource | ||
| 60 | * bundle is named <code>MyResources</code>. The first class you are likely | ||
| 61 | * to write is the default resource bundle which simply has the same name as | ||
| 62 | * its family--<code>MyResources</code>. You can also provide as | ||
| 63 | * many related locale-specific classes as you need: for example, perhaps | ||
| 64 | * you would provide a German one named <code>MyResources_de</code>. | ||
| 65 | * | ||
| 66 | * <P> | ||
| 67 | * Each related subclass of <code>ResourceBundle</code> contains the same | ||
| 68 | * items, but the items have been translated for the locale represented by that | ||
| 69 | * <code>ResourceBundle</code> subclass. For example, both <code>MyResources</code> | ||
| 70 | * and <code>MyResources_de</code> may have a <code>String</code> that's used | ||
| 71 | * on a button for confirming operations. In <code>MyResources</code> the | ||
| 72 | * <code>String</code> may contain <code>OK</code> and in | ||
| 73 | * <code>MyResources_de</code> it may contain <code>Gut</code>. | ||
| 74 | * | ||
| 75 | * <P> | ||
| 76 | * If there are different resources for different countries, you | ||
| 77 | * can make specializations: for example, <code>MyResources_de_CH</code> | ||
| 78 | * for Switzerland. If you want to only modify some of the resources | ||
| 79 | * in the specialization, you can do so. | ||
| 80 | * | ||
| 81 | * <P> | ||
| 82 | * When your program needs a locale-specific object, it loads | ||
| 83 | * the <code>ResourceBundle</code> class using the <code>getBundle</code> | ||
| 84 | * method: | ||
| 85 | * <blockquote> | ||
| 86 | * <pre> | ||
| 87 | * ResourceBundle myResources = | ||
| 88 | * ResourceBundle.getBundle("MyResources", currentLocale); | ||
| 89 | * </pre> | ||
| 90 | * </blockquote> | ||
| 91 | * The first argument specifies the family name of the resource | ||
| 92 | * bundle that contains the object in question. The second argument | ||
| 93 | * indicates the desired locale. <code>getBundle</code> | ||
| 94 | * uses these two arguments to construct the name of the | ||
| 95 | * <code>ResourceBundle</code> subclass it should load as follows. | ||
| 96 | * | ||
| 97 | * <P> | ||
| 98 | * The resource bundle lookup searches for classes with various suffixes | ||
| 99 | * on the basis of (1) the desired locale and (2) the default locale (baseclass), | ||
| 100 | * in the following order from lower-level (more specific) to parent-level | ||
| 101 | * (less specific): | ||
| 102 | * <p> baseclass + "_" + language1 + "_" + country1 + "_" + variant1 | ||
| 103 | * <BR> baseclass + "_" + language1 + "_" + country1 | ||
| 104 | * <BR> baseclass + "_" + language1 | ||
| 105 | * <BR> baseclass | ||
| 106 | * <BR> baseclass + "_" + language2 + "_" + country2 + "_" + variant2 | ||
| 107 | * <BR> baseclass + "_" + language2 + "_" + country2 | ||
| 108 | * <BR> baseclass + "_" + language2 | ||
| 109 | * | ||
| 110 | * <P> | ||
| 111 | * The result of the lookup is a class, but that class may be | ||
| 112 | * backed by a property file on disk. If a lookup fails, | ||
| 113 | * <code>getBundle()</code> throws a <code>MissingResourceException</code>. | ||
| 114 | * | ||
| 115 | * <P> | ||
| 116 | * The baseclass <strong>must</strong> be fully | ||
| 117 | * qualified (for example, <code>myPackage.MyResources</code>, not just | ||
| 118 | * <code>MyResources</code>). It must | ||
| 119 | * also be accessable by your code; it cannot be a class that is private | ||
| 120 | * to the package where <code>ResourceBundle.getBundle</code> is called. | ||
| 121 | * | ||
| 122 | * <P> | ||
| 123 | * Note: <code>ResourceBundle</code> are used internally in accessing | ||
| 124 | * <code>NumberFormat</code>s, <code>Collation</code>s, and so on. | ||
| 125 | * The lookup strategy is the same. | ||
| 126 | * | ||
| 127 | * <P> | ||
| 128 | * Resource bundles contain key/value pairs. The keys uniquely | ||
| 129 | * identify a locale-specific object in the bundle. Here's an | ||
| 130 | * example of a <code>ListResourceBundle</code> that contains | ||
| 131 | * two key/value pairs: | ||
| 132 | * <blockquote> | ||
| 133 | * <pre> | ||
| 134 | * class MyResource extends ListResourceBundle { | ||
| 135 | * public Object[][] getContents() { | ||
| 136 | * return contents; | ||
| 137 | * } | ||
| 138 | * static final Object[][] contents = { | ||
| 139 | * // LOCALIZE THIS | ||
| 140 | * {"OkKey", "OK"}, | ||
| 141 | * {"CancelKey", "Cancel"}, | ||
| 142 | * // END OF MATERIAL TO LOCALIZE | ||
| 143 | * }; | ||
| 144 | * } | ||
| 145 | * </pre> | ||
| 146 | * </blockquote> | ||
| 147 | * Keys are always <code>String</code>s. | ||
| 148 | * In this example, the keys are <code>OkKey</code> and <code>CancelKey</code>. | ||
| 149 | * In the above example, the values | ||
| 150 | * are also <code>String</code>s--<code>OK</code> and <code>Cancel</code>--but | ||
| 151 | * they don't have to be. The values can be any type of object. | ||
| 152 | * | ||
| 153 | * <P> | ||
| 154 | * You retrieve an object from resource bundle using the appropriate | ||
| 155 | * getter method. Because <code>OkKey</code> and <code>CancelKey</code> | ||
| 156 | * are both strings, you would use <code>getString</code> to retrieve them: | ||
| 157 | * <blockquote> | ||
| 158 | * <pre> | ||
| 159 | * button1 = new Button(myResourceBundle.getString("OkKey")); | ||
| 160 | * button2 = new Button(myResourceBundle.getString("CancelKey")); | ||
| 161 | * </pre> | ||
| 162 | * </blockquote> | ||
| 163 | * The getter methods all require the key as an argument and return | ||
| 164 | * the object if found. If the object is not found, the getter method | ||
| 165 | * throws a <code>MissingResourceException</code>. | ||
| 166 | * | ||
| 167 | * <P> | ||
| 168 | * Besides <code>getString</code>; ResourceBundle supports a number | ||
| 169 | * of other methods for getting different types of objects such as | ||
| 170 | * <code>getStringArray</code>. If you don't have an object that | ||
| 171 | * matches one of these methods, you can use <code>getObject</code> | ||
| 172 | * and cast the result to the appropriate type. For example: | ||
| 173 | * <blockquote> | ||
| 174 | * <pre> | ||
| 175 | * int[] myIntegers = (int[]) myResources.getObject("intList"); | ||
| 176 | * </pre> | ||
| 177 | * </blockquote> | ||
| 178 | * | ||
| 179 | * <P> | ||
| 180 | * <STRONG>NOTE:</STRONG> You should always supply a baseclass with | ||
| 181 | * no suffixes. This will be the class of "last resort", if a locale | ||
| 182 | * is requested that does not exist. For example, below we have a class | ||
| 183 | * <code>MyResources</code>. It happens to contain US strings, | ||
| 184 | * so we don't have to have an explicit <code>MyResource_en</code> or | ||
| 185 | * <code>MyResource_en_US</code>. | ||
| 186 | * | ||
| 187 | * <P> | ||
| 188 | * The JDK provides two subclasses of <code>ResourceBundle</code>, | ||
| 189 | * <code>ListResourceBundle</code> and <code>PropertyResourceBundle</code>, | ||
| 190 | * that provide a fairly simple way to create resources. (Once serialization | ||
| 191 | * is fully integrated, we will provide another | ||
| 192 | * way.) As you saw briefly in a prevous example, <code>ListResourceBundle</code> | ||
| 193 | * manages its resource as a List of key/value pairs. | ||
| 194 | * <code>PropertyResourceBundle</code> uses a properties file to manage | ||
| 195 | * its resources. | ||
| 196 | * | ||
| 197 | * <p> | ||
| 198 | * If <code>ListResourceBundle</code> or <code>PropertyResourceBundle</code> | ||
| 199 | * do not suit your needs, you can write your own <code>ResourceBundle</code> | ||
| 200 | * subclass. Your subclasses must overrde two methods: <code>handleGetObject</code> | ||
| 201 | * and <code>getKeys()</code>. | ||
| 202 | * | ||
| 203 | * <P> | ||
| 204 | * The following is a very simple example of a <code>ResourceBundle</code> subclass | ||
| 205 | * that manages only a few resources (for a larger number of resources | ||
| 206 | * you would probably use a <code>Hashtable</code>). Notice that if the key | ||
| 207 | * is not found, <code>handleGetObject</code> must return null. Notice also | ||
| 208 | * that you don't need to supply a value if a "parent-level" | ||
| 209 | * <code>ResourceBundle</code> handles the same | ||
| 210 | * key with the same value (look at uk below). | ||
| 211 | * <strong><p>Example:</strong> | ||
| 212 | * <blockquote> | ||
| 213 | * <pre> | ||
| 214 | * abstract class MyResources extends ResourceBundle { | ||
| 215 | * public Object handleGetObject(String key) { | ||
| 216 | * if (key.equals("okKey")) return "Ok"; | ||
| 217 | * if (key.equals("cancelKey")) return "Cancel"; | ||
| 218 | * return null; | ||
| 219 | * } | ||
| 220 | * } | ||
| 221 | * | ||
| 222 | * abstract class MyResources_de extends MyResources { | ||
| 223 | * public Object handleGetObject(String key) { | ||
| 224 | * if (key.equals("okKey")) return "Gut"; | ||
| 225 | * if (key.equals("cancelKey")) return "Vernichten"; | ||
| 226 | * return null; | ||
| 227 | * } | ||
| 228 | * } | ||
| 229 | * | ||
| 230 | * abstract class MyResources_uk extends MyResources { | ||
| 231 | * public Object handleGetObject(String key) { | ||
| 232 | * // don't need okKey, since parent level handles it. | ||
| 233 | * if (key.equals("cancelKey")) return "Dispose"; | ||
| 234 | * return null; | ||
| 235 | * } | ||
| 236 | * } | ||
| 237 | * </pre> | ||
| 238 | * </blockquote> | ||
| 239 | * You do not have to restrict yourself to using a single family of | ||
| 240 | * <code>ResourceBundle</code>s. For example, you could have a set of bundles for | ||
| 241 | * exception messages, <code>ExceptionResources</code> | ||
| 242 | * (<code>ExceptionResources_fr</code>, <code>ExceptionResources_de</code>, ...), | ||
| 243 | * and one for widgets, <code>WidgetResource</code> (<code>WidgetResources_fr</code>, | ||
| 244 | * <code>WidgetResources_de</code>, ...); breaking up the resources however you like. | ||
| 245 | * | ||
| 246 | * @see ListResourceBundle | ||
| 247 | * @see PropertyResourceBundle | ||
| 248 | * @see MissingResourceException | ||
| 249 | */ | ||
| 250 | abstract public class ResourceBundle { | ||
| 251 | |||
| 252 | /** | ||
| 253 | * Get an object from a ResourceBundle. | ||
| 254 | * <BR>Convenience method to save casting. | ||
| 255 | * @param key see class description. | ||
| 256 | */ | ||
| 257 | public final String getString(String key) throws MissingResourceException { | ||
| 258 | return (String) getObject(key); | ||
| 259 | } | ||
| 260 | |||
| 261 | /** | ||
| 262 | * Get an object from a ResourceBundle. | ||
| 263 | * <BR>Convenience method to save casting. | ||
| 264 | * @param key see class description. | ||
| 265 | */ | ||
| 266 | public final String[] getStringArray(String key) | ||
| 267 | throws MissingResourceException { | ||
| 268 | return (String[]) getObject(key); | ||
| 269 | } | ||
| 270 | |||
| 271 | /** | ||
| 272 | * Get an object from a ResourceBundle. | ||
| 273 | * @param key see class description. | ||
| 274 | */ | ||
| 275 | public final Object getObject(String key) throws MissingResourceException { | ||
| 276 | Object obj = handleGetObject(key); | ||
| 277 | if (obj == null) { | ||
| 278 | if (parent != null) { | ||
| 279 | obj = parent.getObject(key); | ||
| 280 | } | ||
| 281 | if (obj == null) | ||
| 282 | throw new MissingResourceException("Can't find resource", | ||
| 283 | this.getClass().getName(), | ||
| 284 | key); | ||
| 285 | } | ||
| 286 | return obj; | ||
| 287 | } | ||
| 288 | |||
| 289 | |||
| 290 | /** | ||
| 291 | * Get the appropriate ResourceBundle subclass. | ||
| 292 | * @param baseName see class description. | ||
| 293 | */ | ||
| 294 | public static final ResourceBundle getBundle(String baseName) | ||
| 295 | throws MissingResourceException | ||
| 296 | { | ||
| 297 | return getBundle(baseName, Locale.getDefault(), | ||
| 298 | /* must determine loader here, else we break stack invariant */ | ||
| 299 | getLoader()); | ||
| 300 | } | ||
| 301 | |||
| 302 | |||
| 303 | /** | ||
| 304 | * Get the appropriate ResourceBundle subclass. | ||
| 305 | * @param baseName see class description. | ||
| 306 | * @param locale see class description. | ||
| 307 | */ | ||
| 308 | public static final ResourceBundle getBundle(String baseName, | ||
| 309 | Locale locale) | ||
| 310 | { | ||
| 311 | return getBundle(baseName, locale, getLoader()); | ||
| 312 | } | ||
| 313 | |||
| 314 | /* | ||
| 315 | * Automatic determination of the ClassLoader to be used to load | ||
| 316 | * resources on behalf of the client. N.B. The client is getLoader's | ||
| 317 | * caller's caller. | ||
| 318 | */ | ||
| 319 | private static ClassLoader getLoader() { | ||
| 320 | Class[] stack = getClassContext(); | ||
| 321 | /* Magic number 2 identifies our caller's caller */ | ||
| 322 | Class c = stack[2]; | ||
| 323 | ClassLoader cl = (c == null) ? null : c.getClassLoader(); | ||
| 324 | return (cl == null) ? systemClassLoader : cl; | ||
| 325 | } | ||
| 326 | private static native Class[] getClassContext(); | ||
| 327 | private static SystemClassLoader systemClassLoader = | ||
| 328 | new SystemClassLoader(); | ||
| 329 | |||
| 330 | /** | ||
| 331 | * Get the appropriate ResourceBundle subclass. | ||
| 332 | * @param baseName see class description. | ||
| 333 | * @param locale see class description. | ||
| 334 | */ | ||
| 335 | private static synchronized ResourceBundle | ||
| 336 | getBundle(String baseName, Locale locale, ClassLoader loader) | ||
| 337 | throws MissingResourceException | ||
| 338 | { | ||
| 339 | StringBuffer localeName | ||
| 340 | = new StringBuffer("_").append(locale.toString()); | ||
| 341 | |||
| 342 | ResourceBundle lookup = findBundle(baseName,localeName,loader,false); | ||
| 343 | if(lookup == null) { | ||
| 344 | localeName.setLength(0); | ||
| 345 | localeName.append("_").append( Locale.getDefault().toString() ); | ||
| 346 | lookup = findBundle(baseName, localeName, loader, true); | ||
| 347 | if( lookup == null ) { | ||
| 348 | throw new MissingResourceException("can't find resource for " | ||
| 349 | + baseName + "_" + locale, | ||
| 350 | baseName + "_" + locale,""); | ||
| 351 | } | ||
| 352 | } | ||
| 353 | |||
| 354 | // Setup lookup's ancestry. If we find an ancestor whose parent is null, | ||
| 355 | // we set up the ancestor's parent as well. | ||
| 356 | ResourceBundle child = lookup; | ||
| 357 | while( (child != null) && (child.parent == null) ) { | ||
| 358 | // Chop off the last component of the locale name and search for that | ||
| 359 | // as the parent locale. Use it to set the parent of current child. | ||
| 360 | int lastUnderbar = localeName.toString().lastIndexOf('_'); | ||
| 361 | if( lastUnderbar != -1 ) { | ||
| 362 | localeName.setLength(lastUnderbar); | ||
| 363 | debug("Searching for parent " + baseName + localeName); | ||
| 364 | child.setParent( findBundle(baseName,localeName,loader,true) ); | ||
| 365 | } | ||
| 366 | child = child.parent; | ||
| 367 | } | ||
| 368 | |||
| 369 | return lookup; | ||
| 370 | } | ||
| 371 | |||
| 372 | |||
| 373 | /** | ||
| 374 | * Set the parent bundle of this bundle. The parent bundle is | ||
| 375 | * searched by getObject when this bundle does not contain a | ||
| 376 | * particular resource. | ||
| 377 | * @param parent this bundle's parent bundle. | ||
| 378 | */ | ||
| 379 | protected void setParent( ResourceBundle parent ) { | ||
| 380 | this.parent = parent; | ||
| 381 | } | ||
| 382 | |||
| 383 | |||
| 384 | /** | ||
| 385 | * The internal routine that does the real work of finding and loading | ||
| 386 | * the right ResourceBundle for a given name and locale. | ||
| 387 | */ | ||
| 388 | private static ResourceBundle findBundle(String baseName, | ||
| 389 | StringBuffer localeName, | ||
| 390 | ClassLoader loader, | ||
| 391 | boolean includeBase) | ||
| 392 | { | ||
| 393 | String localeStr = localeName.toString(); | ||
| 394 | String baseFileName = baseName.replace('.', '/'); | ||
| 395 | Object lookup = null; | ||
| 396 | String searchName; | ||
| 397 | Vector cacheCandidates = new Vector(); | ||
| 398 | int lastUnderbar; | ||
| 399 | InputStream stream; | ||
| 400 | |||
| 401 | searchLoop: | ||
| 402 | while (true) { | ||
| 403 | searchName = baseName + localeStr; | ||
| 404 | String cacheName = | ||
| 405 | "["+Integer.toString(loader.hashCode())+"]" + searchName; | ||
| 406 | |||
| 407 | // First, look in the cache. We may either find the bundle we're | ||
| 408 | // looking for or we may find that the bundle was not found by a | ||
| 409 | // previous search. | ||
| 410 | lookup = cacheList.get(cacheName); | ||
| 411 | if( lookup == NOTFOUND ) { | ||
| 412 | debug("Found " + searchName + " in cache as NOTFOUND"); | ||
| 413 | localeName.setLength(0); | ||
| 414 | break searchLoop; | ||
| 415 | } | ||
| 416 | if( lookup != null ) { | ||
| 417 | debug("Found " + searchName + " in cache"); | ||
| 418 | localeName.setLength(0); | ||
| 419 | break searchLoop; | ||
| 420 | } | ||
| 421 | cacheCandidates.addElement( cacheName ); | ||
| 422 | |||
| 423 | // Next search for a class | ||
| 424 | debug("Searching for " + searchName ); | ||
| 425 | try { | ||
| 426 | lookup = loader.loadClass(searchName).newInstance(); | ||
| 427 | break searchLoop; | ||
| 428 | } catch( Exception e ){} | ||
| 429 | |||
| 430 | // Next search for a Properties file. | ||
| 431 | searchName = baseFileName + localeStr + ".properties"; | ||
| 432 | debug("Searching for " + searchName ); | ||
| 433 | stream = loader.getResourceAsStream(searchName); | ||
| 434 | if( stream != null ) { | ||
| 435 | // make sure it is buffered | ||
| 436 | stream = new java.io.BufferedInputStream(stream); | ||
| 437 | try { | ||
| 438 | lookup = (Object)new PropertyResourceBundle( stream ); | ||
| 439 | break searchLoop; | ||
| 440 | } catch (Exception e) {} | ||
| 441 | } | ||
| 442 | |||
| 443 | //Chop off the last part of the locale name string and try again. | ||
| 444 | lastUnderbar = localeStr.lastIndexOf('_'); | ||
| 445 | if( ((lastUnderbar==0)&&(!includeBase)) || (lastUnderbar == -1) ) { | ||
| 446 | break; | ||
| 447 | } | ||
| 448 | localeStr = localeStr.substring(0,lastUnderbar); | ||
| 449 | localeName.setLength(lastUnderbar); | ||
| 450 | } | ||
| 451 | |||
| 452 | |||
| 453 | if( lookup != null ) { | ||
| 454 | // Add a positive result to the cache. The result may include | ||
| 455 | // NOTFOUND | ||
| 456 | for( int i=0; i<cacheCandidates.size(); i++ ) { | ||
| 457 | cacheList.put(cacheCandidates.elementAt(i), lookup); | ||
| 458 | debug("Adding " + cacheCandidates.elementAt(i) + " to cache" | ||
| 459 | + ((lookup == NOTFOUND)?" as NOTFOUND.":".")); | ||
| 460 | } | ||
| 461 | } | ||
| 462 | else { | ||
| 463 | // If we searched all the way to the base, then we can add | ||
| 464 | // the NOTFOUND result to the cache. Otherwise we can say | ||
| 465 | // nothing. | ||
| 466 | if( includeBase == true ) { | ||
| 467 | for( int i=0; i<cacheCandidates.size(); i++ ) { | ||
| 468 | cacheList.put(cacheCandidates.elementAt(i), NOTFOUND); | ||
| 469 | debug("Adding " + cacheCandidates.elementAt(i) | ||
| 470 | + " to cache as NOTFOUND."); | ||
| 471 | } | ||
| 472 | } | ||
| 473 | } | ||
| 474 | |||
| 475 | if( (lookup == NOTFOUND) || (lookup == null) ) | ||
| 476 | return null; | ||
| 477 | else | ||
| 478 | return (ResourceBundle)lookup; | ||
| 479 | } | ||
| 480 | |||
| 481 | |||
| 482 | /** Get an object from a ResourceBundle. | ||
| 483 | * <STRONG>NOTE: </STRONG>Subclasses must override. | ||
| 484 | * @param key see class description. | ||
| 485 | */ | ||
| 486 | protected abstract Object handleGetObject(String key) | ||
| 487 | throws MissingResourceException; | ||
| 488 | |||
| 489 | /** | ||
| 490 | * Return an enumeration of the keys. | ||
| 491 | * <STRONG>NOTE: </STRONG>Subclasses must override. | ||
| 492 | */ | ||
| 493 | public abstract Enumeration getKeys(); | ||
| 494 | |||
| 495 | /** | ||
| 496 | * For printf debugging. | ||
| 497 | */ | ||
| 498 | private static boolean debugFlag = false; | ||
| 499 | private static void debug(String str) { | ||
| 500 | if( debugFlag ) { | ||
| 501 | System.out.println("ResourceBundle: " + str); | ||
| 502 | } | ||
| 503 | } | ||
| 504 | |||
| 505 | /** | ||
| 506 | * The parent bundle is consulted by getObject when this bundle | ||
| 507 | * does not contain a particular resource. | ||
| 508 | */ | ||
| 509 | protected ResourceBundle parent = null; | ||
| 510 | |||
| 511 | private static final Integer NOTFOUND = new Integer(-1); | ||
| 512 | private static Hashtable cacheList = new Hashtable(); | ||
| 513 | } | ||
| 514 | |||
| 515 | |||
| 516 | /** | ||
| 517 | * The SystemClassLoader loads system classes (those in your classpath). | ||
| 518 | * This is an attempt to unify the handling of system classes and ClassLoader | ||
| 519 | * classes. | ||
| 520 | */ | ||
| 521 | class SystemClassLoader extends java.lang.ClassLoader { | ||
| 522 | |||
| 523 | protected Class loadClass( String name, boolean resolve ) | ||
| 524 | throws ClassNotFoundException | ||
| 525 | { | ||
| 526 | return findSystemClass( name ); | ||
| 527 | } | ||
| 528 | |||
| 529 | public InputStream getResourceAsStream(String name) { | ||
| 530 | return ClassLoader.getSystemResourceAsStream(name); | ||
| 531 | } | ||
| 532 | |||
| 533 | public java.net.URL getResource(String name) { | ||
| 534 | return ClassLoader.getSystemResource(name); | ||
| 535 | } | ||
| 536 | } | ||
| @@ -0,0 +1,48 @@ | |||
| 1 | implement ResourceBundle_L; | ||
| 2 | |||
| 3 | # javal v1.3 generated file: edit with care | ||
| 4 | |||
| 5 | include "jni.m"; | ||
| 6 | jni : JNI; | ||
| 7 | ClassModule, | ||
| 8 | JString, | ||
| 9 | JArray, | ||
| 10 | JArrayI, | ||
| 11 | JArrayC, | ||
| 12 | JArrayB, | ||
| 13 | JArrayS, | ||
| 14 | JArrayJ, | ||
| 15 | JArrayF, | ||
| 16 | JArrayD, | ||
| 17 | JArrayZ, | ||
| 18 | JArrayJObject, | ||
| 19 | JArrayJClass, | ||
| 20 | JArrayJString, | ||
| 21 | JClass, | ||
| 22 | JThread, | ||
| 23 | JObject : import jni; | ||
| 24 | |||
| 25 | #>> extra pre includes here | ||
| 26 | |||
| 27 | #<< | ||
| 28 | |||
| 29 | include "ResourceBundle_L.m"; | ||
| 30 | |||
| 31 | #>> extra post includes here | ||
| 32 | |||
| 33 | #<< | ||
| 34 | |||
| 35 | init( jni_p : JNI ) | ||
| 36 | { | ||
| 37 | # save java native inteface mod instance | ||
| 38 | jni = jni_p; | ||
| 39 | #>>extra initialization here | ||
| 40 | #<< | ||
| 41 | } | ||
| 42 | |||
| 43 | getClassContext_aClass( ) : JArrayJClass | ||
| 44 | {#>> | ||
| 45 | jni->FatalError( "getClassContext() not implemented" ); | ||
| 46 | return(nil); | ||
| 47 | }#<< | ||
| 48 | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | # javal v1.3 generated file: edit with care | ||
| 2 | |||
| 3 | ResourceBundle_L : module | ||
| 4 | { | ||
| 5 | ResourceBundle_obj : adt | ||
| 6 | { | ||
| 7 | cl_mod : ClassModule; | ||
| 8 | parent : cyclic ref ResourceBundle_obj; | ||
| 9 | }; | ||
| 10 | |||
| 11 | init : fn( jni_p : JNI ); | ||
| 12 | getClassContext_aClass : fn( ) : JArrayJClass; | ||
| 13 | |||
| 14 | }; | ||
| @@ -0,0 +1,246 @@ | |||
| 1 | /* | ||
| 2 | * @(#)SimpleTimeZone.java 1.12 97/03/05 | ||
| 3 | * | ||
| 4 | * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved | ||
| 5 | * (C) Copyright IBM Corp. 1996 - All Rights Reserved | ||
| 6 | * | ||
| 7 | * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * The original version of this source code and documentation is copyrighted | ||
| 10 | * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These | ||
| 11 | * materials are provided under terms of a License Agreement between Taligent | ||
| 12 | * and Sun. This technology is protected by multiple US and International | ||
| 13 | * patents. This notice and attribution to Taligent may not be removed. | ||
| 14 | * Taligent is a registered trademark of Taligent, Inc. | ||
| 15 | * | ||
| 16 | * Permission to use, copy, modify, and distribute this software | ||
| 17 | * and its documentation for NON-COMMERCIAL purposes and without | ||
| 18 | * fee is hereby granted provided that this copyright notice | ||
| 19 | * appears in all copies. Please refer to the file "copyright.html" | ||
| 20 | * for further important copyright and licensing information. | ||
| 21 | * | ||
| 22 | * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF | ||
| 23 | * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 24 | * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 25 | * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR | ||
| 26 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | ||
| 27 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. | ||
| 28 | * | ||
| 29 | */ | ||
| 30 | |||
| 31 | package java.util; | ||
| 32 | |||
| 33 | import java.io.ObjectInputStream; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code> | ||
| 37 | * that represents a time zone for use with a Gregorian | ||
| 38 | * calendar. This simple class does not handle historical | ||
| 39 | * changes, and has limited rules. | ||
| 40 | * | ||
| 41 | * <P> | ||
| 42 | * Use a negative value for <code>dayOfWeekInMonth</code> to indicate that | ||
| 43 | * <code>SimpleTimeZone</code> should count from the end of the month backwards. | ||
| 44 | * For example, Daylight Savings Time ends at the last | ||
| 45 | * (dayOfWeekInMonth = -1) Sunday in October, at 2 AM in standard time. | ||
| 46 | * | ||
| 47 | * @see Calendar | ||
| 48 | * @see GregorianCalendar | ||
| 49 | * @see TimeZone | ||
| 50 | * @version 1.12 03/05/97 | ||
| 51 | * @author David Goldsmith, Mark Davis, Chen-Lieh Huang | ||
| 52 | */ | ||
| 53 | public class SimpleTimeZone extends TimeZone { | ||
| 54 | /** | ||
| 55 | * Constructs a SimpleTimeZone with the given base time zone offset | ||
| 56 | * from GMT and time zone ID. Timezone IDs can be obtained from | ||
| 57 | * TimeZone.getAvailableIDs. Normally you should use TimeZone.getDefault | ||
| 58 | * to construct a TimeZone. | ||
| 59 | * @param rawOffset the given base time zone offset to GMT. | ||
| 60 | * @param ID the time zone ID which is obtained from | ||
| 61 | * TimeZone.getAvailableIDs. | ||
| 62 | */ | ||
| 63 | public SimpleTimeZone(int rawOffset, String ID) | ||
| 64 | { | ||
| 65 | throw new NoSuchElementException(); | ||
| 66 | } | ||
| 67 | |||
| 68 | /** | ||
| 69 | * Constructs a SimpleTimeZone with the given base time zone offset | ||
| 70 | * from GMT, time zone ID, time to start and end the daylight time. | ||
| 71 | * Timezone IDs can be obtained from TimeZone.getAvailableIDs. | ||
| 72 | * Normally you should use TimeZone.getDefault to create a TimeZone. | ||
| 73 | * For a time zone that does not use daylight saving time, do not | ||
| 74 | * use this constructor; instead you should use | ||
| 75 | * SimpleTimeZone(rawOffset, ID). | ||
| 76 | * @param rawOffset the given base time zone offset to GMT. | ||
| 77 | * @param ID the time zone ID which is obtained from | ||
| 78 | * TimeZone.getAvailableIDs. | ||
| 79 | * @param startMonth the daylight savings starting month. Month is 0-based. | ||
| 80 | * eg, 0 for January. | ||
| 81 | * @param startDayOfWeekInMonth the daylight savings starting | ||
| 82 | * day-of-week-in-month. Please see the member description for an example. | ||
| 83 | * @param startDayOfWeek the daylight savings starting day-of-week. | ||
| 84 | * Please see the member description for an example. | ||
| 85 | * @param startTime the daylight savings starting time. Please see the | ||
| 86 | * member description for an example. | ||
| 87 | * @param endMonth the daylight savings ending month. Month is 0-based. | ||
| 88 | * eg, 0 for January. | ||
| 89 | * @param endDayOfWeekInMonth the daylight savings ending | ||
| 90 | * day-of-week-in-month. Please see the member description for an example. | ||
| 91 | * @param endDayOfWeek the daylight savings ending day-of-week. Please see | ||
| 92 | * the member description for an example. | ||
| 93 | * @param endTime the daylight savings ending time. Please see the member | ||
| 94 | * description for an example. | ||
| 95 | */ | ||
| 96 | public SimpleTimeZone(int rawOffset, String ID, int startMonth, | ||
| 97 | int startDayOfWeekInMonth, int startDayOfWeek, int startTime, | ||
| 98 | int endMonth, int endDayOfWeekInMonth, int endDayOfWeek, int endTime) | ||
| 99 | { | ||
| 100 | throw new NoSuchElementException(); | ||
| 101 | } | ||
| 102 | |||
| 103 | /** | ||
| 104 | * Sets the daylight savings starting year. | ||
| 105 | * @param year the daylight savings starting year. | ||
| 106 | */ | ||
| 107 | public void setStartYear(int year) | ||
| 108 | { | ||
| 109 | throw new NoSuchElementException(); | ||
| 110 | } | ||
| 111 | |||
| 112 | /** | ||
| 113 | * Sets the daylight savings starting rule. For example, Daylight Savings | ||
| 114 | * Time starts at the first Sunday in April, at 2 AM in standard time. | ||
| 115 | * Therefore, you can set the start rule by calling: | ||
| 116 | * setStartRule(TimeFields.APRIL, 1, TimeFields.SUNDAY, 2*60*60*1000); | ||
| 117 | * @param month the daylight savings starting month. Month is 0-based. | ||
| 118 | * eg, 0 for January. | ||
| 119 | * @param dayOfWeekInMonth the daylight savings starting | ||
| 120 | * day-of-week-in-month. Please see the member description for an example. | ||
| 121 | * @param dayOfWeek the daylight savings starting day-of-week. Please see | ||
| 122 | * the member description for an example. | ||
| 123 | * @param time the daylight savings starting time. Please see the member | ||
| 124 | * description for an example. | ||
| 125 | */ | ||
| 126 | public void setStartRule(int month, int dayOfWeekInMonth, int dayOfWeek, | ||
| 127 | int time) | ||
| 128 | { | ||
| 129 | throw new NoSuchElementException(); | ||
| 130 | } | ||
| 131 | |||
| 132 | /** | ||
| 133 | * Sets the daylight savings ending rule. For example, Daylight Savings | ||
| 134 | * Time ends at the last (-1) Sunday in October, at 2 AM in standard time. | ||
| 135 | * Therefore, you can set the end rule by calling: | ||
| 136 | * setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000); | ||
| 137 | * @param month the daylight savings ending month. Month is 0-based. | ||
| 138 | * eg, 0 for January. | ||
| 139 | * @param dayOfWeekInMonth the daylight savings ending | ||
| 140 | * day-of-week-in-month. Please see the member description for an example. | ||
| 141 | * @param dayOfWeek the daylight savings ending day-of-week. Please see | ||
| 142 | * the member description for an example. | ||
| 143 | * @param time the daylight savings ending time. Please see the member | ||
| 144 | * description for an example. | ||
| 145 | */ | ||
| 146 | public void setEndRule(int month, int dayOfWeekInMonth, int dayOfWeek, | ||
| 147 | int time) | ||
| 148 | { | ||
| 149 | throw new NoSuchElementException(); | ||
| 150 | } | ||
| 151 | |||
| 152 | /** | ||
| 153 | * Overrides TimeZone | ||
| 154 | * Gets offset, for current date, modified in case of daylight savings. | ||
| 155 | * This is the offset to add *to* UTC to get local time. | ||
| 156 | * Please see TimeZone.getOffset for descriptions on parameters. | ||
| 157 | */ | ||
| 158 | public int getOffset(int era, int year, int month, int day, int dayOfWeek, | ||
| 159 | int millis) | ||
| 160 | { | ||
| 161 | throw new NoSuchElementException(); | ||
| 162 | } | ||
| 163 | |||
| 164 | /** | ||
| 165 | * Overrides TimeZone | ||
| 166 | * Gets the GMT offset for this time zone. | ||
| 167 | */ | ||
| 168 | public int getRawOffset() | ||
| 169 | { | ||
| 170 | throw new NoSuchElementException(); | ||
| 171 | } | ||
| 172 | |||
| 173 | /** | ||
| 174 | * Overrides TimeZone | ||
| 175 | * Sets the base time zone offset to GMT. | ||
| 176 | * This is the offset to add *to* UTC to get local time. | ||
| 177 | * Please see TimeZone.setRawOffset for descriptions on the parameter. | ||
| 178 | */ | ||
| 179 | public void setRawOffset(int offsetMillis) | ||
| 180 | { | ||
| 181 | throw new NoSuchElementException(); | ||
| 182 | } | ||
| 183 | |||
| 184 | /** | ||
| 185 | * Overrides TimeZone | ||
| 186 | * Queries if this time zone uses Daylight Savings Time. | ||
| 187 | */ | ||
| 188 | public boolean useDaylightTime() | ||
| 189 | { | ||
| 190 | throw new NoSuchElementException(); | ||
| 191 | } | ||
| 192 | |||
| 193 | /** | ||
| 194 | * Overrides TimeZone | ||
| 195 | * Queries if the given date is in Daylight Savings Time. | ||
| 196 | */ | ||
| 197 | public boolean inDaylightTime(Date date) { | ||
| 198 | throw new NoSuchElementException(); | ||
| 199 | } | ||
| 200 | |||
| 201 | /** | ||
| 202 | * Overrides Cloneable | ||
| 203 | */ | ||
| 204 | public Object clone() | ||
| 205 | { | ||
| 206 | throw new NoSuchElementException(); | ||
| 207 | } | ||
| 208 | |||
| 209 | /** | ||
| 210 | * Override hashCode. | ||
| 211 | * Generates the hash code for the SimpleDateFormat object | ||
| 212 | */ | ||
| 213 | public synchronized int hashCode() | ||
| 214 | { | ||
| 215 | throw new NoSuchElementException(); | ||
| 216 | } | ||
| 217 | |||
| 218 | /** | ||
| 219 | * Compares the equality of two SimpleTimeZone objects. | ||
| 220 | * @param obj the SimpleTimeZone object to be compared with. | ||
| 221 | * @return true if the given obj is the same as this SimpleTimeZone | ||
| 222 | * object; false otherwise. | ||
| 223 | */ | ||
| 224 | public boolean equals(Object obj) | ||
| 225 | { | ||
| 226 | throw new NoSuchElementException(); | ||
| 227 | } | ||
| 228 | |||
| 229 | // =======================privates=============================== | ||
| 230 | |||
| 231 | private int startMonth, startDay, startDayOfWeek, startTime; | ||
| 232 | private int endMonth, endDay, endDayOfWeek, endTime; | ||
| 233 | private int startYear; | ||
| 234 | private int rawOffset; | ||
| 235 | private boolean useDaylight=false; // indicate if this time zone uses DST | ||
| 236 | private static final int millisPerHour = 60*60*1000; | ||
| 237 | // WARNING: assumes that no rule is measured from the end of February, | ||
| 238 | // since we don't handle leap years. Could handle assuming always | ||
| 239 | // Gregorian, since we know they didn't have daylight time when | ||
| 240 | // Gregorian calendar started. | ||
| 241 | private final byte monthLength[] = {31,28,31,30,31,30,31,31,30,31,30,31}; | ||
| 242 | |||
| 243 | private void readObject(ObjectInputStream s) { | ||
| 244 | throw new NoSuchElementException(); | ||
| 245 | } | ||
| 246 | } | ||
Empty file added.
Empty file added.
| @@ -0,0 +1,193 @@ | |||
| 1 | /* | ||
| 2 | * @(#)TimeZone.java 1.17 97/01/29 | ||
| 3 | * | ||
| 4 | * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved | ||
| 5 | * (C) Copyright IBM Corp. 1996 - All Rights Reserved | ||
| 6 | * | ||
| 7 | * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * The original version of this source code and documentation is copyrighted | ||
| 10 | * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These | ||
| 11 | * materials are provided under terms of a License Agreement between Taligent | ||
| 12 | * and Sun. This technology is protected by multiple US and International | ||
| 13 | * patents. This notice and attribution to Taligent may not be removed. | ||
| 14 | * Taligent is a registered trademark of Taligent, Inc. | ||
| 15 | * | ||
| 16 | * Permission to use, copy, modify, and distribute this software | ||
| 17 | * and its documentation for NON-COMMERCIAL purposes and without | ||
| 18 | * fee is hereby granted provided that this copyright notice | ||
| 19 | * appears in all copies. Please refer to the file "copyright.html" | ||
| 20 | * for further important copyright and licensing information. | ||
| 21 | * | ||
| 22 | * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF | ||
| 23 | * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 24 | * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 25 | * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR | ||
| 26 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | ||
| 27 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. | ||
| 28 | * | ||
| 29 | */ | ||
| 30 | |||
| 31 | package java.util; | ||
| 32 | |||
| 33 | import java.io.Serializable; | ||
| 34 | import java.io.ObjectInputStream; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * <code>TimeZone</code> represents a time zone offset, and also figures out daylight | ||
| 38 | * savings. | ||
| 39 | * | ||
| 40 | * <p> | ||
| 41 | * Typically, you get a <code>TimeZone</code> using <code>getDefault</code> | ||
| 42 | * which creates a <code>TimeZone</code> based on the time zone where the program | ||
| 43 | * is running. For example, for a program running in Japan, <code>getDefault</code> | ||
| 44 | * creates a <code>TimeZone</code> object based on Japanese Standard Time. | ||
| 45 | * | ||
| 46 | * <p> | ||
| 47 | * You can also get a <code>TimeZone</code> using <code>getTimeZone</code> along | ||
| 48 | * with a time zone ID. For instance, the time zone ID for the Pacific | ||
| 49 | * Standard Time zone is "PST". So, you can get a PST <code>TimeZone</code> object | ||
| 50 | * with: | ||
| 51 | * <blockquote> | ||
| 52 | * <pre> | ||
| 53 | * TimeZone tz = TimeZone.getTimeZone("PST"); | ||
| 54 | * </pre> | ||
| 55 | * </blockquote> | ||
| 56 | * You can use <code>getAvailableIDs</code> method to iterate through | ||
| 57 | * all the supported time zone IDs. You can then choose a | ||
| 58 | * supported ID to get a favorite <code>TimeZone</code>. | ||
| 59 | * | ||
| 60 | * @see Calendar | ||
| 61 | * @see GregorianCalendar | ||
| 62 | * @see SimpleTimeZone | ||
| 63 | * @version 1.17 01/29/97 | ||
| 64 | * @author Mark Davis, David Goldsmith, Chen-Lieh Huang | ||
| 65 | */ | ||
| 66 | abstract public class TimeZone implements Serializable, Cloneable { | ||
| 67 | |||
| 68 | public TimeZone() { | ||
| 69 | throw new NoSuchElementException(); | ||
| 70 | } | ||
| 71 | |||
| 72 | /** | ||
| 73 | * Gets the time zone offset, for current date, modified in case of | ||
| 74 | * daylight savings. This is the offset to add *to* UTC to get local time. | ||
| 75 | * @param era the era of the given date. | ||
| 76 | * @param year the year in the given date. | ||
| 77 | * @param month the month in the given date. | ||
| 78 | * Month is 0-based. e.g., 0 for January. | ||
| 79 | * @param day the day-in-month of the given date. | ||
| 80 | * @param dayOfWeek the day-of-week of the given date. | ||
| 81 | * @param milliseconds the millis in day. | ||
| 82 | * @return the offset to add *to* GMT to get local time. | ||
| 83 | */ | ||
| 84 | abstract public int getOffset(int era, int year, int month, int day, | ||
| 85 | int dayOfWeek, int milliseconds); | ||
| 86 | |||
| 87 | /** | ||
| 88 | * Sets the base time zone offset to GMT. | ||
| 89 | * This is the offset to add *to* UTC to get local time. | ||
| 90 | * @param offsetMillis the given base time zone offset to GMT. | ||
| 91 | */ | ||
| 92 | abstract public void setRawOffset(int offsetMillis); | ||
| 93 | |||
| 94 | /** | ||
| 95 | * Gets unmodified offset, NOT modified in case of daylight savings. | ||
| 96 | * This is the offset to add *to* UTC to get local time. | ||
| 97 | * @return the unmodified offset to add *to* UTC to get local time. | ||
| 98 | */ | ||
| 99 | abstract public int getRawOffset(); | ||
| 100 | |||
| 101 | /** | ||
| 102 | * Gets the ID of this time zone. | ||
| 103 | * @return the ID of this time zone. | ||
| 104 | */ | ||
| 105 | public String getID() | ||
| 106 | { | ||
| 107 | throw new NoSuchElementException(); | ||
| 108 | } | ||
| 109 | |||
| 110 | /** | ||
| 111 | * Sets the time zone ID. This does not change any other data in | ||
| 112 | * the time zone object. | ||
| 113 | * @param ID the new time zone ID. | ||
| 114 | */ | ||
| 115 | public void setID(String ID) | ||
| 116 | { | ||
| 117 | throw new NoSuchElementException(); | ||
| 118 | } | ||
| 119 | |||
| 120 | /** | ||
| 121 | * Queries if this time zone uses Daylight Savings Time. | ||
| 122 | * @return true if this time zone uses Daylight Savings Time, | ||
| 123 | * false, otherwise. | ||
| 124 | */ | ||
| 125 | abstract public boolean useDaylightTime(); | ||
| 126 | |||
| 127 | /** | ||
| 128 | * Queries if the given date is in Daylight Savings Time in | ||
| 129 | * this time zone. | ||
| 130 | * @param date the given Date. | ||
| 131 | * @return true if the given date is in Daylight Savings Time, | ||
| 132 | * false, otherwise. | ||
| 133 | */ | ||
| 134 | abstract public boolean inDaylightTime(Date date); | ||
| 135 | |||
| 136 | /** | ||
| 137 | * Gets the TimeZone for the given ID. | ||
| 138 | * @param ID the given ID. | ||
| 139 | * @return a TimeZone. | ||
| 140 | */ | ||
| 141 | public static synchronized TimeZone getTimeZone(String ID) | ||
| 142 | { | ||
| 143 | throw new NoSuchElementException(); | ||
| 144 | } | ||
| 145 | |||
| 146 | /** | ||
| 147 | * Gets the available IDs according to the given time zone offset. | ||
| 148 | * @param rawOffset the given time zone GMT offset. | ||
| 149 | * @return an array of IDs, where the time zone for that ID has | ||
| 150 | * the specified GMT offset. For example, {"Phoenix", "Denver"}, | ||
| 151 | * since both have GMT-07:00, but differ in daylight savings behavior. | ||
| 152 | */ | ||
| 153 | public static synchronized String[] getAvailableIDs(int rawOffset) { | ||
| 154 | throw new NoSuchElementException(); | ||
| 155 | } | ||
| 156 | |||
| 157 | /** | ||
| 158 | * Gets all the available IDs supported. | ||
| 159 | * @return an array of IDs. | ||
| 160 | */ | ||
| 161 | public static synchronized String[] getAvailableIDs() { | ||
| 162 | throw new NoSuchElementException(); | ||
| 163 | } | ||
| 164 | |||
| 165 | /** | ||
| 166 | * Gets the default TimeZone for this host. | ||
| 167 | * @return a default TimeZone. | ||
| 168 | */ | ||
| 169 | public static synchronized TimeZone getDefault() { | ||
| 170 | throw new NoSuchElementException(); | ||
| 171 | } | ||
| 172 | |||
| 173 | /** | ||
| 174 | * Sets time zone to using the given TimeZone. | ||
| 175 | * @param zone the given time zone. | ||
| 176 | */ | ||
| 177 | public static synchronized void setDefault(TimeZone zone) | ||
| 178 | { | ||
| 179 | throw new NoSuchElementException(); | ||
| 180 | } | ||
| 181 | |||
| 182 | /** | ||
| 183 | * Overrides Cloneable | ||
| 184 | */ | ||
| 185 | public Object clone() | ||
| 186 | { | ||
| 187 | throw new NoSuchElementException(); | ||
| 188 | } | ||
| 189 | |||
| 190 | private void readObject(ObjectInputStream s) { | ||
| 191 | throw new NoSuchElementException(); | ||
| 192 | } | ||
| 193 | } | ||
| @@ -0,0 +1,65 @@ | |||
| 1 | /* | ||
| 2 | * @(#)TooManyListenersException.java 1.1 96/10/10 | ||
| 3 | * | ||
| 4 | * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved. | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software | ||
| 7 | * and its documentation for NON-COMMERCIAL purposes and without | ||
| 8 | * fee is hereby granted provided that this copyright notice | ||
| 9 | * appears in all copies. Please refer to the file "copyright.html" | ||
| 10 | * for further important copyright and licensing information. | ||
| 11 | * | ||
| 12 | * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF | ||
| 13 | * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 14 | * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 15 | * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR | ||
| 16 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | ||
| 17 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. | ||
| 18 | */ | ||
| 19 | |||
| 20 | package java.util; | ||
| 21 | |||
| 22 | /** | ||
| 23 | * <p> | ||
| 24 | * The <code> TooManyListenersException </code> Exception is used as part of | ||
| 25 | * the Java Event model to annotate and implement a unicast special case of | ||
| 26 | * a multicast Event Source. | ||
| 27 | * </p> | ||
| 28 | * <p> | ||
| 29 | * The presence of a <code> throws TooManyListenersException </code> clause | ||
| 30 | * on any given concrete implementation of the normally multicast semantic | ||
| 31 | * <italic> void add < EventListenerType > () </italic> event listener | ||
| 32 | * registration pattern is used to annotate that interface as implementing | ||
| 33 | * a unicast Listener special case, that is, that one and only one Listener | ||
| 34 | * may be registered on the particular event listener source concurrently. | ||
| 35 | * </p> | ||
| 36 | * | ||
| 37 | * @see java.util.EventObject | ||
| 38 | * @see java.util.EventListener | ||
| 39 | * | ||
| 40 | * @version 1.1 96/10/10 | ||
| 41 | * @author Laurence P. G. Cable | ||
| 42 | */ | ||
| 43 | |||
| 44 | public class TooManyListenersException extends Exception { | ||
| 45 | |||
| 46 | /** | ||
| 47 | * Constructs a TooManyListenersException with no detail message. | ||
| 48 | * A detail message is a String that describes this particular exception. | ||
| 49 | */ | ||
| 50 | |||
| 51 | public TooManyListenersException() { | ||
| 52 | super(); | ||
| 53 | } | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Constructs a TooManyListenersException with the specified detail message. | ||
| 57 | * A detail message is a String that describes this particular exception. | ||
| 58 | * @param s the detail message | ||
| 59 | */ | ||
| 60 | |||
| 61 | public TooManyListenersException(String s) { | ||
| 62 | super(s); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
Empty file added.
| @@ -0,0 +1,88 @@ | |||
| 1 | <../../../../mkconfig | ||
| 2 | |||
| 3 | DIRS=\ | ||
| 4 | zip\ | ||
| 5 | |||
| 6 | TARG=\ | ||
| 7 | BitSet.dis\ | ||
| 8 | Calendar.dis\ | ||
| 9 | Date.dis\ | ||
| 10 | Dictionary.dis\ | ||
| 11 | EmptyStackException.dis\ | ||
| 12 | Enumeration.dis\ | ||
| 13 | EventListener.dis\ | ||
| 14 | EventObject.dis\ | ||
| 15 | GregorianCalendar.dis\ | ||
| 16 | Hashtable.dis\ | ||
| 17 | HashtableEntry.dis\ | ||
| 18 | HashtableEnumerator.dis\ | ||
| 19 | ListResourceBundle.dis\ | ||
| 20 | Locale.dis\ | ||
| 21 | # for MissingResourceException.dis\ | ||
| 22 | PyLHKaRk2knKuXdPtclNZ.dis\ | ||
| 23 | # for NoSuchElementException.dis\ | ||
| 24 | FgHgFAyr+lOIx-Hx5tg1g.dis\ | ||
| 25 | Observable.dis\ | ||
| 26 | Observer.dis\ | ||
| 27 | Properties.dis\ | ||
| 28 | # for PropertyResourceBundle.dis\ | ||
| 29 | hXReUGvcTPP+3SdqzAFLN.dis\ | ||
| 30 | Random.dis\ | ||
| 31 | ResourceBundle.dis\ | ||
| 32 | SimpleTimeZone.dis\ | ||
| 33 | Stack.dis\ | ||
| 34 | StringTokenizer.dis\ | ||
| 35 | SystemClassLoader.dis\ | ||
| 36 | TimeZone.dis\ | ||
| 37 | # for TooManyListenersException.dis\ | ||
| 38 | ofB3vewCQyrpHPDk+jZyy.dis\ | ||
| 39 | Vector.dis\ | ||
| 40 | VectorEnumerator.dis\ | ||
| 41 | # Limbo code\ | ||
| 42 | Date_L.dis\ | ||
| 43 | ResourceBundle_L.dis\ | ||
| 44 | |||
| 45 | MODULES=\ | ||
| 46 | $ROOT/java/module/classloader.m\ | ||
| 47 | $ROOT/java/module/jni.m\ | ||
| 48 | $ROOT/java/module/cast.m\ | ||
| 49 | Date_L.m\ | ||
| 50 | ResourceBundle_L.m\ | ||
| 51 | |||
| 52 | SYSMODULES=\ | ||
| 53 | draw.m\ | ||
| 54 | hash.m\ | ||
| 55 | keyring.m\ | ||
| 56 | loader.m\ | ||
| 57 | math.m\ | ||
| 58 | string.m\ | ||
| 59 | sys.m\ | ||
| 60 | |||
| 61 | DISBIN=$ROOT/java/dis/java/java/util | ||
| 62 | |||
| 63 | <$ROOT/mkfiles/mkjava | ||
| 64 | <$ROOT/mkfiles/mksubdirs | ||
| 65 | |||
| 66 | HashtableEntry.dis: Hashtable.class | ||
| 67 | j2d HashtableEntry.class | ||
| 68 | |||
| 69 | HashtableEnumerator.dis: Hashtable.class | ||
| 70 | j2d HashtableEnumerator.class | ||
| 71 | |||
| 72 | VectorEnumerator.dis: Vector.class | ||
| 73 | j2d VectorEnumerator.class | ||
| 74 | |||
| 75 | PyLHKaRk2knKuXdPtclNZ.dis: MissingResourceException.class | ||
| 76 | j2d MissingResourceException.class | ||
| 77 | |||
| 78 | FgHgFAyr+lOIx-Hx5tg1g.dis: NoSuchElementException.class | ||
| 79 | j2d NoSuchElementException.class | ||
| 80 | |||
| 81 | SystemClassLoader.dis: ResourceBundle.class | ||
| 82 | j2d SystemClassLoader.class | ||
| 83 | |||
| 84 | hXReUGvcTPP+3SdqzAFLN.dis: PropertyResourceBundle.class | ||
| 85 | j2d PropertyResourceBundle.class | ||
| 86 | |||
| 87 | ofB3vewCQyrpHPDk+jZyy.dis: TooManyListenersException.class | ||
| 88 | j2d TooManyListenersException.class | ||
Empty file added.
| @@ -0,0 +1,51 @@ | |||
| 1 | implement CRC32_L; | ||
| 2 | |||
| 3 | # javal v1.4 generated file: edit with care | ||
| 4 | |||
| 5 | include "jni.m"; | ||
| 6 | jni : JNI; | ||
| 7 | ClassModule, | ||
| 8 | JString, | ||
| 9 | JArray, | ||
| 10 | JArrayI, | ||
| 11 | JArrayC, | ||
| 12 | JArrayB, | ||
| 13 | JArrayS, | ||
| 14 | JArrayJ, | ||
| 15 | JArrayF, | ||
| 16 | JArrayD, | ||
| 17 | JArrayZ, | ||
| 18 | JArrayJObject, | ||
| 19 | JArrayJClass, | ||
| 20 | JArrayJString, | ||
| 21 | JClass, | ||
| 22 | JThread, | ||
| 23 | JObject : import jni; | ||
| 24 | |||
| 25 | #>> extra pre includes here | ||
| 26 | |||
| 27 | #<< | ||
| 28 | |||
| 29 | include "CRC32_L.m"; | ||
| 30 | |||
| 31 | #>> extra post includes here | ||
| 32 | |||
| 33 | #<< | ||
| 34 | |||
| 35 | init( jni_p : JNI ) | ||
| 36 | { | ||
| 37 | # save java native inteface mod instance | ||
| 38 | jni = jni_p; | ||
| 39 | #>>extra initialization here | ||
| 40 | #<< | ||
| 41 | } | ||
| 42 | |||
| 43 | update_aB_I_I_V( this : ref CRC32_obj, p0 : JArrayB,p1 : int,p2 : int) | ||
| 44 | {#>> | ||
| 45 | }#<< | ||
| 46 | |||
| 47 | update1_I_V( this : ref CRC32_obj, p0 : int) | ||
| 48 | {#>> | ||
| 49 | }#<< | ||
| 50 | |||
| 51 | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | # javal v1.4 generated file: edit with care | ||
| 2 | |||
| 3 | CRC32_L : module | ||
| 4 | { | ||
| 5 | CRC32_obj : adt | ||
| 6 | { | ||
| 7 | cl_mod : ClassModule; | ||
| 8 | crc : int; | ||
| 9 | }; | ||
| 10 | |||
| 11 | init : fn( jni_p : JNI ); | ||
| 12 | update_aB_I_I_V : fn( this : ref CRC32_obj, p0 : JArrayB,p1 : int,p2 : int); | ||
| 13 | update1_I_V : fn( this : ref CRC32_obj, p0 : int); | ||
| 14 | |||
| 15 | }; | ||
Empty file added.
Empty file added.
Empty file added.
Empty file added.
Empty file added.
Empty file added.
Empty file added.
| @@ -0,0 +1,77 @@ | |||
| 1 | implement Inflater_L; | ||
| 2 | |||
| 3 | # javal v1.4 generated file: edit with care | ||
| 4 | |||
| 5 | include "jni.m"; | ||
| 6 | jni : JNI; | ||
| 7 | ClassModule, | ||
| 8 | JString, | ||
| 9 | JArray, | ||
| 10 | JArrayI, | ||
| 11 | JArrayC, | ||
| 12 | JArrayB, | ||
| 13 | JArrayS, | ||
| 14 | JArrayJ, | ||
| 15 | JArrayF, | ||
| 16 | JArrayD, | ||
| 17 | JArrayZ, | ||
| 18 | JArrayJObject, | ||
| 19 | JArrayJClass, | ||
| 20 | JArrayJString, | ||
| 21 | JClass, | ||
| 22 | JThread, | ||
| 23 | JObject : import jni; | ||
| 24 | |||
| 25 | #>> extra pre includes here | ||
| 26 | |||
| 27 | #<< | ||
| 28 | |||
| 29 | include "Inflater_L.m"; | ||
| 30 | |||
| 31 | #>> extra post includes here | ||
| 32 | |||
| 33 | #<< | ||
| 34 | |||
| 35 | init( jni_p : JNI ) | ||
| 36 | { | ||
| 37 | # save java native inteface mod instance | ||
| 38 | jni = jni_p; | ||
| 39 | #>>extra initialization here | ||
| 40 | #<< | ||
| 41 | } | ||
| 42 | |||
| 43 | inflate_aB_I_I_I( this : ref Inflater_obj, p0 : JArrayB,p1 : int,p2 : int) : int | ||
| 44 | {#>> | ||
| 45 | junk1 := (this, p0); | ||
| 46 | junk2 := (p1, p2); | ||
| 47 | return 0; | ||
| 48 | }#<< | ||
| 49 | |||
| 50 | getTotalIn_I( this : ref Inflater_obj) : int | ||
| 51 | {#>> | ||
| 52 | junk := this; | ||
| 53 | return 0; | ||
| 54 | }#<< | ||
| 55 | |||
| 56 | getTotalOut_I( this : ref Inflater_obj) : int | ||
| 57 | {#>> | ||
| 58 | junk := this; | ||
| 59 | return 0; | ||
| 60 | }#<< | ||
| 61 | |||
| 62 | reset_V( this : ref Inflater_obj) | ||
| 63 | {#>> | ||
| 64 | junk := this; | ||
| 65 | }#<< | ||
| 66 | |||
| 67 | end_V( this : ref Inflater_obj) | ||
| 68 | {#>> | ||
| 69 | junk := this; | ||
| 70 | }#<< | ||
| 71 | |||
| 72 | init_Z_V( this : ref Inflater_obj, p0 : int) | ||
| 73 | {#>> | ||
| 74 | junk := (this, p0); | ||
| 75 | }#<< | ||
| 76 | |||
| 77 | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | # javal v1.6 generated file: edit with care | ||
| 2 | |||
| 3 | Inflater_L : module | ||
| 4 | { | ||
| 5 | Inflater_obj : adt | ||
| 6 | { | ||
| 7 | cl_mod : ClassModule; | ||
| 8 | strm : int; | ||
| 9 | buf : JArrayB; | ||
| 10 | off : int; | ||
| 11 | len_j : int; | ||
| 12 | finished : byte; | ||
| 13 | needsDictionary : byte; | ||
| 14 | }; | ||
| 15 | |||
| 16 | init : fn( jni_p : JNI ); | ||
| 17 | inflate_aB_I_I_I : fn( this : ref Inflater_obj, p0 : JArrayB,p1 : int,p2 : int) : int; | ||
| 18 | getTotalIn_I : fn( this : ref Inflater_obj) : int; | ||
| 19 | getTotalOut_I : fn( this : ref Inflater_obj) : int; | ||
| 20 | reset_V : fn( this : ref Inflater_obj); | ||
| 21 | end_V : fn( this : ref Inflater_obj); | ||
| 22 | init_Z_V : fn( this : ref Inflater_obj, p0 : int); | ||
| 23 | |||
| 24 | }; | ||
Empty file added.
Empty file added.
Empty file added.
Empty file added.
| @@ -0,0 +1,38 @@ | |||
| 1 | <../../../../../mkconfig | ||
| 2 | |||
| 3 | TARG=\ | ||
| 4 | CRC32.dis\ | ||
| 5 | CheckedInputStream.dis\ | ||
| 6 | CheckedOutputStream.dis\ | ||
| 7 | Checksum.dis\ | ||
| 8 | DataFormatException.dis\ | ||
| 9 | GZIPInputStream.dis\ | ||
| 10 | Inflater.dis\ | ||
| 11 | InflaterInputStream.dis\ | ||
| 12 | ZipConstants.dis\ | ||
| 13 | ZipEntry.dis\ | ||
| 14 | ZipException.dis\ | ||
| 15 | ZipInputStream.dis\ | ||
| 16 | # Limbo code\ | ||
| 17 | CRC32_L.dis\ | ||
| 18 | Inflater_L.dis\ | ||
| 19 | |||
| 20 | MODULES=\ | ||
| 21 | $ROOT/java/module/classloader.m\ | ||
| 22 | $ROOT/java/module/jni.m\ | ||
| 23 | $ROOT/java/module/cast.m\ | ||
| 24 | CRC32_L.m\ | ||
| 25 | Inflater_L.m\ | ||
| 26 | |||
| 27 | SYSMODULES=\ | ||
| 28 | draw.m\ | ||
| 29 | hash.m\ | ||
| 30 | keyring.m\ | ||
| 31 | loader.m\ | ||
| 32 | math.m\ | ||
| 33 | string.m\ | ||
| 34 | sys.m\ | ||
| 35 | |||
| 36 | DISBIN=$ROOT/java/dis/java/java/util/zip | ||
| 37 | |||
| 38 | <$ROOT/mkfiles/mkjava | ||