001: /*
002: *******************************************************************************
003: * Copyright (C) 2003-2006, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007: package com.ibm.icu.text;
008:
009: import java.text.Format;
010: import com.ibm.icu.util.ULocale;
011:
012: /**
013: * An abstract class that extends {@link java.text.Format} to provide
014: * additional ICU protocol, specifically, the <tt>getLocale()</tt>
015: * API. All ICU format classes are subclasses of this class.
016: *
017: * @see com.ibm.icu.util.ULocale
018: * @author weiv
019: * @author Alan Liu
020: * @draft ICU 2.8 (retain)
021: * @provisional This API might change or be removed in a future release.
022: */
023: public abstract class UFormat extends Format {
024: // jdk1.4.2 serialver
025: private static final long serialVersionUID = -4964390515840164416L;
026:
027: /**
028: * @draft ICU 2.8 (retain)
029: * @provisional This API might change or be removed in a future release.
030: */
031: public UFormat() {
032: }
033:
034: // -------- BEGIN ULocale boilerplate --------
035:
036: /**
037: * Return the locale that was used to create this object, or null.
038: * This may may differ from the locale requested at the time of
039: * this object's creation. For example, if an object is created
040: * for locale <tt>en_US_CALIFORNIA</tt>, the actual data may be
041: * drawn from <tt>en</tt> (the <i>actual</i> locale), and
042: * <tt>en_US</tt> may be the most specific locale that exists (the
043: * <i>valid</i> locale).
044: *
045: * <p>Note: This method will be implemented in ICU 3.0; ICU 2.8
046: * contains a partial preview implementation. The <i>actual</i>
047: * locale is returned correctly, but the <i>valid</i> locale is
048: * not, in most cases.
049: * @param type type of information requested, either {@link
050: * com.ibm.icu.util.ULocale#VALID_LOCALE} or {@link
051: * com.ibm.icu.util.ULocale#ACTUAL_LOCALE}.
052: * @return the information specified by <i>type</i>, or null if
053: * this object was not constructed from locale data.
054: * @see com.ibm.icu.util.ULocale
055: * @see com.ibm.icu.util.ULocale#VALID_LOCALE
056: * @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
057: * @draft ICU 2.8 (retain)
058: * @provisional This API might change or be removed in a future release.
059: */
060: public final ULocale getLocale(ULocale.Type type) {
061: return type == ULocale.ACTUAL_LOCALE ? this .actualLocale
062: : this .validLocale;
063: }
064:
065: /**
066: * Set information about the locales that were used to create this
067: * object. If the object was not constructed from locale data,
068: * both arguments should be set to null. Otherwise, neither
069: * should be null. The actual locale must be at the same level or
070: * less specific than the valid locale. This method is intended
071: * for use by factories or other entities that create objects of
072: * this class.
073: * @param valid the most specific locale containing any resource
074: * data, or null
075: * @param actual the locale containing data used to construct this
076: * object, or null
077: * @see com.ibm.icu.util.ULocale
078: * @see com.ibm.icu.util.ULocale#VALID_LOCALE
079: * @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
080: * @internal
081: */
082: final void setLocale(ULocale valid, ULocale actual) {
083: // Change the following to an assertion later
084: if ((valid == null) != (actual == null)) {
085: ///CLOVER:OFF
086: throw new IllegalArgumentException();
087: ///CLOVER:ON
088: }
089: // Another check we could do is that the actual locale is at
090: // the same level or less specific than the valid locale.
091: this .validLocale = valid;
092: this .actualLocale = actual;
093: }
094:
095: /**
096: * The most specific locale containing any resource data, or null.
097: * @see com.ibm.icu.util.ULocale
098: * @internal
099: */
100: private ULocale validLocale;
101:
102: /**
103: * The locale containing data used to construct this object, or
104: * null.
105: * @see com.ibm.icu.util.ULocale
106: * @internal
107: */
108: private ULocale actualLocale;
109:
110: // -------- END ULocale boilerplate --------
111: }
|