3 *******************************************************************************
4 * Copyright (C) 2004-2009, International Business Machines Corporation and *
5 * others. All Rights Reserved. *
6 *******************************************************************************
9 package com.ibm.icu.util;
11 import java.lang.ref.SoftReference;
12 import java.util.Enumeration;
13 import java.util.HashMap;
14 import java.util.Locale;
16 import java.util.MissingResourceException;
17 import java.util.ResourceBundle;
18 import java.util.Vector;
20 import com.ibm.icu.impl.ICUCache;
21 import com.ibm.icu.impl.ICUResourceBundle;
22 import com.ibm.icu.impl.ICUResourceBundleReader;
23 import com.ibm.icu.impl.ResourceBundleWrapper;
24 import com.ibm.icu.impl.SimpleCache;
25 import com.ibm.icu.util.ULocale;
27 //#if defined(FOUNDATION10) || defined(J2SE13) || defined(ECLIPSE_FRAGMENT)
28 //##import com.ibm.icu.impl.ByteBuffer;
30 import java.nio.ByteBuffer;
34 * A class representing a collection of resource information pertaining to a given
35 * locale. A resource bundle provides a way of accessing locale- specific information in
36 * a data file. You create a resource bundle that manages the resources for a given
37 * locale and then ask it for individual resources.
39 * In ResourceBundle class, an object is created
40 * and the sub items are fetched using getString, getObject methods.
41 * In UResourceBundle,each individual element of a resource is a resource by itself.
44 * Resource bundles in ICU are currently defined using text files which conform to the following
45 * <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt">BNF definition</a>.
46 * More on resource bundle concepts and syntax can be found in the
47 * <a href="http://www.icu-project.org/userguide/ResourceManagement.html">Users Guide</a>.
50 * The packaging of ICU *.res files can be of two types
69 * LocaleElements_fr.res LocaleElements_en.res
71 * ---------------------------
73 * LocaleElements_fr_CA.res LocaleElements_fr_FR.res
75 * Depending on the organization of your resources, the syntax to getBundleInstance will change.
76 * To open ICU style organization use:
78 * UResourceBundle bundle = UResourceBundle.getBundleInstance("com/mycompany/resources", "en_US", myClassLoader);
80 * To open Java/JDK style organization use:
82 * UResourceBundle bundle = UResourceBundle.getBundleInstance("com.mycompany.resources.LocaleElements", "en_US", myClassLoader);
85 * Please use pass a class loader for loading non-ICU resources. Java security does not
86 * allow loading of resources across jar files. You must provide your class loader
87 * to load the resources
92 public abstract class UResourceBundle extends ResourceBundle{
96 * Creates a resource bundle using the specified base name and locale.
97 * ICU_DATA_CLASS is used as the default root.
98 * @param baseName the base name of the resource bundle, a fully qualified class name
99 * @param localeName the locale for which a resource bundle is desired
100 * @exception MissingResourceException
101 * if no resource bundle for the specified base name can be found
102 * @return a resource bundle for the given base name and locale
105 public static UResourceBundle getBundleInstance(String baseName, String localeName){
106 return getBundleInstance(baseName, localeName, ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
110 * Creates a resource bundle using the specified base name, locale, and class root.
112 * @param baseName the base name of the resource bundle, a fully qualified class name
113 * @param localeName the locale for which a resource bundle is desired
114 * @param root the class object from which to load the resource bundle
115 * @exception MissingResourceException
116 * if no resource bundle for the specified base name can be found
117 * @return a resource bundle for the given base name and locale
120 public static UResourceBundle getBundleInstance(String baseName, String localeName, ClassLoader root){
121 return getBundleInstance(baseName, localeName, root, false);
125 * Creates a resource bundle using the specified base name, locale, and class root.
127 * @param baseName the base name of the resource bundle, a fully qualified class name
128 * @param localeName the locale for which a resource bundle is desired
129 * @param root the class object from which to load the resource bundle
130 * @param disableFallback Option to disable locale inheritence.
131 * If true the fallback chain will not be built.
132 * @exception MissingResourceException
133 * if no resource bundle for the specified base name can be found
134 * @return a resource bundle for the given base name and locale
138 protected static UResourceBundle getBundleInstance(String baseName, String localeName, ClassLoader root, boolean disableFallback) {
139 return instantiateBundle(baseName, localeName, root, disableFallback);
143 * Sole constructor. (For invocation by subclass constructors, typically
144 * implicit.) This is public for compatibility with Java, whose compiler
145 * will generate public default constructors for an abstract class.
148 public UResourceBundle() {
152 * Creates a UResourceBundle for the locale specified, from which users can extract resources by using
153 * their corresponding keys.
154 * @param locale specifies the locale for which we want to open the resource.
155 * If null the bundle for default locale is opened.
156 * @return a resource bundle for the given locale
159 public static UResourceBundle getBundleInstance(ULocale locale) {
161 locale = ULocale.getDefault();
163 return getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale.toString(), ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
167 * Creates a UResourceBundle for the default locale and specified base name,
168 * from which users can extract resources by using their corresponding keys.
169 * @param baseName specifies the locale for which we want to open the resource.
170 * If null the bundle for default locale is opened.
171 * @return a resource bundle for the given base name and default locale
174 public static UResourceBundle getBundleInstance(String baseName) {
175 if (baseName == null) {
176 baseName = ICUResourceBundle.ICU_BASE_NAME;
178 ULocale uloc = ULocale.getDefault();
179 return getBundleInstance(baseName, uloc.toString(), ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
183 * Creates a UResourceBundle for the specified locale and specified base name,
184 * from which users can extract resources by using their corresponding keys.
185 * @param baseName specifies the locale for which we want to open the resource.
186 * If null the bundle for default locale is opened.
187 * @param locale specifies the locale for which we want to open the resource.
188 * If null the bundle for default locale is opened.
189 * @return a resource bundle for the given base name and locale
193 public static UResourceBundle getBundleInstance(String baseName, Locale locale) {
194 if (baseName == null) {
195 baseName = ICUResourceBundle.ICU_BASE_NAME;
197 ULocale uloc = locale == null ? ULocale.getDefault() : ULocale.forLocale(locale);
199 return getBundleInstance(baseName, uloc.toString(), ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
203 * Creates a UResourceBundle, from which users can extract resources by using
204 * their corresponding keys.
205 * @param baseName string containing the name of the data package.
206 * If null the default ICU package name is used.
207 * @param locale specifies the locale for which we want to open the resource.
208 * If null the bundle for default locale is opened.
209 * @return a resource bundle for the given base name and locale
212 public static UResourceBundle getBundleInstance(String baseName, ULocale locale) {
213 if (baseName == null) {
214 baseName = ICUResourceBundle.ICU_BASE_NAME;
216 if (locale == null) {
217 locale = ULocale.getDefault();
219 return getBundleInstance(baseName, locale.toString(), ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
223 * Creates a UResourceBundle for the specified locale and specified base name,
224 * from which users can extract resources by using their corresponding keys.
225 * @param baseName specifies the locale for which we want to open the resource.
226 * If null the bundle for default locale is opened.
227 * @param locale specifies the locale for which we want to open the resource.
228 * If null the bundle for default locale is opened.
229 * @param loader the loader to use
230 * @return a resource bundle for the given base name and locale
233 public static UResourceBundle getBundleInstance(String baseName, Locale locale, ClassLoader loader) {
234 if (baseName == null) {
235 baseName = ICUResourceBundle.ICU_BASE_NAME;
237 ULocale uloc = locale == null ? ULocale.getDefault() : ULocale.forLocale(locale);
238 return getBundleInstance(baseName, uloc.toString(), loader, false);
242 * Creates a UResourceBundle, from which users can extract resources by using
243 * their corresponding keys.<br><br>
244 * Note: Please use this API for loading non-ICU resources. Java security does not
245 * allow loading of resources across jar files. You must provide your class loader
246 * to load the resources
247 * @param baseName string containing the name of the data package.
248 * If null the default ICU package name is used.
249 * @param locale specifies the locale for which we want to open the resource.
250 * If null the bundle for default locale is opened.
251 * @param loader the loader to use
252 * @return a resource bundle for the given base name and locale
255 public static UResourceBundle getBundleInstance(String baseName, ULocale locale, ClassLoader loader) {
256 if (baseName == null) {
257 baseName = ICUResourceBundle.ICU_BASE_NAME;
259 if (locale == null) {
260 locale = ULocale.getDefault();
262 return getBundleInstance(baseName, locale.toString(), loader, false);
266 * Returns the RFC 3066 conformant locale id of this resource bundle.
267 * This method can be used after a call to getBundleInstance() to
268 * determine whether the resource bundle returned really
269 * corresponds to the requested locale or is a fallback.
271 * @return the locale of this resource bundle
274 public abstract ULocale getULocale();
278 * @return The string representation of the localeID
281 protected abstract String getLocaleID();
283 * Gets the base name of the resource bundle
284 * @return The string representation of the base name
287 protected abstract String getBaseName();
290 * Gets the parent bundle
291 * @return The parent bundle
294 protected abstract UResourceBundle getParent();
298 * Get the locale of this bundle
299 * @return the locale of this resource bundle
302 public Locale getLocale(){
303 return getULocale().toLocale();
306 // Cache for ResourceBundle instantiation
307 private static ICUCache BUNDLE_CACHE = new SimpleCache();
312 public static void resetBundleCache()
316 * Currently if a resourcebundle with fallback turned ON is added to the cache
317 * and then a getBundleInstance() is called for a bundle with fallback turned OFF
318 * it will actually search the cache for any bundle of the same locale
319 * regaurdless of fallback status. This method has been created so that if
320 * The calling method KNOWS that instances of the other fallback state may be in the
321 * cache, the calling method may call this method to clear out the cache.
324 //TODO figure a way around this method(see method comment)
325 BUNDLE_CACHE = new SimpleCache();
328 private static void addToCache(ResourceCacheKey key, UResourceBundle b) {
329 BUNDLE_CACHE.put(key, b);
333 * Method used by subclasses to add the a particular resource bundle object to the managed cache
334 * @internal revisit for ICU 3.6
335 * @deprecated This API is ICU internal only.
337 protected static void addToCache(ClassLoader cl, String fullName, ULocale defaultLocale, UResourceBundle b){
338 synchronized(cacheKey){
339 cacheKey.setKeyValues(cl, fullName, defaultLocale);
340 addToCache((ResourceCacheKey)cacheKey.clone(), b);
344 * Method used by sub classes to load a resource bundle object from the managed cache
345 * @internal revisit for ICU 3.6
346 * @deprecated This API is ICU internal only.
348 protected static UResourceBundle loadFromCache(ClassLoader cl, String fullName, ULocale defaultLocale){
349 synchronized(cacheKey){
350 cacheKey.setKeyValues(cl, fullName, defaultLocale);
351 return loadFromCache(cacheKey);
354 private static UResourceBundle loadFromCache(ResourceCacheKey key) {
355 return (UResourceBundle)BUNDLE_CACHE.get(key);
359 * Key used for cached resource bundles. The key checks
360 * the resource name, the class root, and the default
361 * locale to determine if the resource is a match to the
362 * requested one. The root may be null, but the
363 * searchName and the default locale must have a non-null value.
364 * Note that the default locale may change over time, and
365 * lookup should always be based on the current default
366 * locale (if at all).
368 private static final class ResourceCacheKey implements Cloneable {
369 private SoftReference loaderRef;
370 private String searchName;
371 private ULocale defaultLocale;
372 private int hashCodeCache;
374 public boolean equals(Object other) {
379 final ResourceCacheKey otherEntry = (ResourceCacheKey) other;
380 //quick check to see if they are not equal
381 if (hashCodeCache != otherEntry.hashCodeCache) {
384 //are the names the same?
385 if (!searchName.equals(otherEntry.searchName)) {
388 // are the default locales the same?
389 if (defaultLocale == null) {
390 if (otherEntry.defaultLocale != null) {
394 if (!defaultLocale.equals(otherEntry.defaultLocale)) {
398 //are refs (both non-null) or (both null)?
399 if (loaderRef == null) {
400 return otherEntry.loaderRef == null;
402 return (otherEntry.loaderRef != null)
403 && (loaderRef.get() == otherEntry.loaderRef.get());
405 } catch (NullPointerException e) {
407 } catch (ClassCastException e) {
411 public int hashCode() {
412 return hashCodeCache;
414 public Object clone() {
416 return super.clone();
417 } catch (CloneNotSupportedException e) {
418 //this should never happen
419 throw new IllegalStateException();
423 private synchronized void setKeyValues(ClassLoader root, String searchName, ULocale defaultLocale) {
424 this.searchName = searchName;
425 hashCodeCache = searchName.hashCode();
426 this.defaultLocale = defaultLocale;
427 if (defaultLocale != null) {
428 hashCodeCache ^= defaultLocale.hashCode();
431 this.loaderRef = null;
433 loaderRef = new SoftReference(root);
434 hashCodeCache ^= root.hashCode();
437 /*private void clear() {
438 setKeyValues(null, "", null);
442 private static final ResourceCacheKey cacheKey = new ResourceCacheKey();
444 private static final int ROOT_MISSING = 0;
445 private static final int ROOT_ICU = 1;
446 private static final int ROOT_JAVA = 2;
448 private static SoftReference ROOT_CACHE;
450 private static int getRootType(String baseName, ClassLoader root)
455 if (ROOT_CACHE != null) {
456 m = (Map) ROOT_CACHE.get();
461 ROOT_CACHE = new SoftReference(m);
464 rootType = (Integer) m.get(baseName);
466 if (rootType == null) {
467 String rootLocale = (baseName.indexOf('.')==-1) ? "root" : "";
468 int rt = ROOT_MISSING; // value set on success
470 ICUResourceBundle.getBundleInstance(baseName, rootLocale, root, true);
472 }catch(MissingResourceException ex){
474 ResourceBundleWrapper.getBundleInstance(baseName, rootLocale, root, true);
476 }catch(MissingResourceException e){
477 //throw away the exception
481 rootType = new Integer(rt);
482 m.put(baseName, rootType);
485 return rootType.intValue();
488 private static void setRootType(String baseName, int rootType)
490 Integer rt = new Integer(rootType);
493 if (ROOT_CACHE != null) {
494 m = (Map) ROOT_CACHE.get();
497 ROOT_CACHE = new SoftReference(m);
504 * Loads a new resource bundle for the give base name, locale and class loader.
505 * Optionally will disable loading of fallback bundles.
506 * @param baseName the base name of the resource bundle, a fully qualified class name
507 * @param localeName the locale for which a resource bundle is desired
508 * @param root the class object from which to load the resource bundle
509 * @param disableFallback disables loading of fallback lookup chain
510 * @exception MissingResourceException
511 * if no resource bundle for the specified base name can be found
512 * @return a resource bundle for the given base name and locale
515 protected static UResourceBundle instantiateBundle(String baseName, String localeName,
516 ClassLoader root, boolean disableFallback){
517 UResourceBundle b = null;
518 int rootType = getRootType(baseName, root);
520 ULocale defaultLocale = ULocale.getDefault();
525 if(disableFallback) {
526 String fullName = ICUResourceBundleReader.getFullName(baseName, localeName);
527 synchronized(cacheKey){
528 cacheKey.setKeyValues(root, fullName, defaultLocale);
529 b = loadFromCache(cacheKey);
533 b = ICUResourceBundle.getBundleInstance(baseName, localeName, root, disableFallback);
534 //cacheKey.setKeyValues(root, fullName, defaultLocale);
535 addToCache(cacheKey, b);
538 b = ICUResourceBundle.getBundleInstance(baseName, localeName, root, disableFallback);
544 return ResourceBundleWrapper.getBundleInstance(baseName, localeName, root, disableFallback);
548 b = ICUResourceBundle.getBundleInstance(baseName, localeName, root, disableFallback);
549 setRootType(baseName, ROOT_ICU);
550 }catch(MissingResourceException ex){
551 b = ResourceBundleWrapper.getBundleInstance(baseName, localeName, root, disableFallback);
552 setRootType(baseName, ROOT_JAVA);
560 * Returns a binary data from a binary resource.
562 * @return a pointer to a chuck of unsigned bytes which live in a memory mapped/DLL file.
565 * @throws MissingResourceException
566 * @throws UResourceTypeMismatchException
569 public ByteBuffer getBinary() {
570 throw new UResourceTypeMismatchException("");
574 * Returns a string from a string resource type
580 * @throws MissingResourceException
581 * @throws UResourceTypeMismatchException
584 public String getString() {
585 throw new UResourceTypeMismatchException("");
589 * Returns a string array from a array resource type
594 * @throws MissingResourceException
595 * @throws UResourceTypeMismatchException
598 public String[] getStringArray() {
599 throw new UResourceTypeMismatchException("");
603 * Returns a binary data from a binary resource.
605 * @param ba The byte array to write the bytes to. A null variable is OK.
606 * @return an array bytes containing the binary data from the resource.
609 * @throws MissingResourceException
610 * @throws UResourceTypeMismatchException
613 public byte[] getBinary(byte[] ba) {
614 throw new UResourceTypeMismatchException("");
618 * Returns a 32 bit integer array from a resource.
620 * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
623 * @throws MissingResourceException
624 * @throws UResourceTypeMismatchException
627 public int[] getIntVector() {
628 throw new UResourceTypeMismatchException("");
632 * Returns a signed integer from a resource.
634 * @return an integer value
637 * @throws MissingResourceException
638 * @throws UResourceTypeMismatchException
641 public int getInt() {
642 throw new UResourceTypeMismatchException("");
646 * Returns a unsigned integer from a resource.
647 * This integer is originally 28 bit and the sign gets propagated.
649 * @return an integer value
652 * @throws MissingResourceException
653 * @throws UResourceTypeMismatchException
656 public int getUInt() {
657 throw new UResourceTypeMismatchException("");
661 * Returns a resource in a given resource that has a given key.
663 * @param aKey a key associated with the wanted resource
664 * @return a resource bundle object representing the resource
665 * @throws MissingResourceException
668 public UResourceBundle get(String aKey) {
669 UResourceBundle obj = handleGet(aKey, null, this);
671 UResourceBundle res = this;
672 while ((res = res.getParent()) != null && obj == null) {
673 //call the get method to recursively fetch the resource
674 obj = res.handleGet(aKey, null, this);
677 String fullName = ICUResourceBundleReader.getFullName(
678 getBaseName(), getLocaleID());
679 throw new MissingResourceException(
680 "Can't find resource for bundle " + fullName + ", key "
681 + aKey, this.getClass().getName(), aKey);
684 ((ICUResourceBundle)obj).setLoadingStatus(getLocaleID());
689 * Returns the string in a given resource at the specified index.
691 * @param index an index to the wanted string.
692 * @return a string which lives in the resource.
693 * @throws IndexOutOfBoundsException
694 * @throws UResourceTypeMismatchException
697 public String getString(int index) {
698 ICUResourceBundle temp = (ICUResourceBundle)get(index);
699 if (temp.getType() == STRING) {
700 return temp.getString();
702 throw new UResourceTypeMismatchException("");
706 * Returns the resource in a given resource at the specified index.
708 * @param index an index to the wanted resource.
709 * @return the sub resource UResourceBundle object
710 * @throws IndexOutOfBoundsException
711 * @throws MissingResourceException
714 public UResourceBundle get(int index) {
715 UResourceBundle obj = handleGet(index, null, this);
717 obj = (ICUResourceBundle) getParent();
719 obj = obj.get(index);
722 throw new MissingResourceException(
723 "Can't find resource for bundle "
724 + this.getClass().getName() + ", key "
725 + getKey(), this.getClass().getName(), getKey());
727 ((ICUResourceBundle)obj).setLoadingStatus(getLocaleID());
731 * Returns the keys in this bundle as an enumeration
732 * @return an enumeration containing key strings
735 public Enumeration getKeys() {
737 return keys.elements();
740 private Vector keys = null;
741 private synchronized void initKeysVector(){
745 //ICUResourceBundle current = this;
747 Enumeration e = this.handleGetKeys();
748 while(e.hasMoreElements()){
749 String elem = (String)e.nextElement();
750 if(!keys.contains(elem)){
757 * Returns the size of a resource. Size for scalar types is always 1,
758 * and for vector/table types is the number of child resources.
759 * <br><b><font color='red'>Warning: </font></b> Integer array is treated as a scalar type. There are no
760 * APIs to access individual members of an integer array. It
761 * is always returned as a whole.
762 * @return number of resources in a given resource.
765 public int getSize() {
770 * Returns the type of a resource.
771 * Available types are {@link #INT INT}, {@link #ARRAY ARRAY},
772 * {@link #BINARY BINARY}, {@link #INT_VECTOR INT_VECTOR},
773 * {@link #STRING STRING}, {@link #TABLE TABLE}.
775 * @return type of the given resource.
778 public int getType() {
779 int type = ICUResourceBundle.RES_GET_TYPE(resource);
781 return TABLE; //Mask the table32's real type
787 * Return the version number associated with this UResourceBundle as an
788 * VersionInfo object.
789 * @return VersionInfo object containing the version of the bundle
792 public VersionInfo getVersion() {
797 * Returns the iterator which iterates over this
799 * @return UResourceBundleIterator that iterates over the resources in the bundle
802 public UResourceBundleIterator getIterator() {
803 return new UResourceBundleIterator(this);
806 * Returns the key associated with a given resource. Not all the resources have a key - only
807 * those that are members of a table.
808 * @return a key associated to this resource, or null if it doesn't have a key
811 public String getKey() {
815 * Resource type constant for "no resource".
818 public static final int NONE = -1;
821 * Resource type constant for strings.
824 public static final int STRING = 0;
827 * Resource type constant for binary data.
830 public static final int BINARY = 1;
833 * Resource type constant for tables of key-value pairs.
836 public static final int TABLE = 2;
839 * Resource type constant for aliases;
840 * internally stores a string which identifies the actual resource
841 * storing the data (can be in a different resource bundle).
842 * Resolved internally before delivering the actual resource through the API.
844 * @deprecated This API is ICU internal only.
846 protected static final int ALIAS = 3;
850 * Alternative resource type constant for tables of key-value pairs.
851 * Never returned by getType().
853 * @deprecated This API is ICU internal only.
855 protected static final int TABLE32 = 4;
858 * Resource type constant for a single 28-bit integer, interpreted as
859 * signed or unsigned by the getInt() function.
863 public static final int INT = 7;
866 * Resource type constant for arrays of resources.
869 public static final int ARRAY = 8;
872 * Resource type constant for vectors of 32-bit integers.
876 public static final int INT_VECTOR = 14;
878 //====== protected members ==============
880 * Data member where the subclasses store the key
882 * @deprecated This API is ICU internal only.
884 protected String key;
886 * Data member where the subclasses store the size of resources
888 * @deprecated This API is ICU internal only.
890 protected int size = 1;
892 * Data member where the subclasses store the offset within resource data
894 * @deprecated This API is ICU internal only.
896 protected long resource = RES_BOGUS;
898 * Data member where the subclasses store whether the resource is top level
900 * @deprecated This API is ICU internal only.
902 protected boolean isTopLevel = false;
904 private static final long RES_BOGUS = 0xffffffff;
907 * Actual worker method for fetching a resource based on the given key.
908 * Sub classes must override this method if they support resources with keys.
909 * @param aKey the key string of the resource to be fetched
910 * @param table hashtable object to hold references of resources already seen
911 * @param requested the original resource bundle object on which the get method was invoked.
912 * The requested bundle and the bundle on which this method is invoked
913 * are the same, except in the cases where aliases are involved.
914 * @return UResourceBundle a resource associated with the key
917 protected UResourceBundle handleGet(String aKey, HashMap table, UResourceBundle requested) {
922 * Actual worker method for fetching a resource based on the given index.
923 * Sub classes must override this method if they support arrays of resources.
924 * @param index the index of the resource to be fetched
925 * @param table hashtable object to hold references of resources already seen
926 * @param requested the original resource bundle object on which the get method was invoked.
927 * The requested bundle and the bundle on which this method is invoked
928 * are the same, except in the cases where aliases are involved.
929 * @return UResourceBundle a resource associated with the index
932 protected UResourceBundle handleGet(int index, HashMap table, UResourceBundle requested) {
937 * Actual worker method for fetching the array of strings in a resource.
938 * Sub classes must override this method if they support arrays of strings.
939 * @return String[] An array of strings containing strings
942 protected String[] handleGetStringArray() {
947 * Actual worker method for fetching the keys of resources contained in the resource.
948 * Sub classes must override this method if they support keys and associated resources.
950 * @return Enumeration An enumeration of all the keys in this resource.
953 protected Enumeration handleGetKeys(){
954 Vector resKeys = new Vector();
955 UResourceBundle item = null;
956 for (int i = 0; i < size; i++) {
958 resKeys.add(item.getKey());
960 return resKeys.elements();
967 // this method is declared in ResourceBundle class
968 // so cannot change the signature
969 // Override this method
970 protected Object handleGetObject(String aKey) {
971 return handleGetObjectImpl(aKey, this);
975 * Override the superclass method
977 // To facilitate XPath style aliases we need a way to pass the reference
978 // to requested locale. The only way I could figure out is to implement
979 // the look up logic here. This has a disadvantage that if the client
980 // loads an ICUResourceBundle, calls ResourceBundle.getObject method
981 // with a key that does not exist in the bundle then the lookup is
982 // done twice before throwing a MissingResourceExpection.
983 private Object handleGetObjectImpl(String aKey, UResourceBundle requested) {
984 Object obj = resolveObject(aKey, requested);
986 UResourceBundle parentBundle = getParent();
987 if (parentBundle != null) {
988 obj = parentBundle.handleGetObjectImpl(aKey, requested);
991 throw new MissingResourceException(
992 "Can't find resource for bundle "
993 + this.getClass().getName() + ", key " + aKey,
994 this.getClass().getName(), aKey);
999 // Routine for figuring out the type of object to be returned
1000 // string or string array
1001 private Object resolveObject(String aKey, UResourceBundle requested) {
1002 if (getType() == STRING) {
1005 UResourceBundle obj = handleGet(aKey, null, requested);
1007 if (obj.getType() == STRING) {
1008 return obj.getString();
1011 if (obj.getType() == ARRAY) {
1012 return obj.handleGetStringArray();
1014 } catch (UResourceTypeMismatchException ex) {
1022 * This method is for setting the loading status of the resource.
1023 * The status is analogous to the warning status in ICU4C.
1025 * @deprecated This API is ICU internal only.
1027 protected abstract void setLoadingStatus(int newStatus);