FileDocCategorySizeDatePackage
DevResourceManagerFactory.javaAPI DocphoneME MR2 API (J2ME)8791Wed May 02 18:00:46 BST 2007com.sun.j2me.global

DevResourceManagerFactory

public class DevResourceManagerFactory extends ResourceManagerFactory
This class represents a resource manager factory for creating device resource managers.

Fields Summary
private static final String
classname
Class name.
protected ResourceCache
resourceCache
Cache instance for device resources.
Constructors Summary
public DevResourceManagerFactory(ResourceCache cache)
Creates a new resource manager factory for creating device resource managers.

param
cache resource cache used



                          
       
        resourceCache = cache;
    
Methods Summary
private static native intgetDevLocaleIndex(java.lang.String locale)
Get index of supported locales for device resources by its name.

param
locale name of locale
return
index of locale

private static native java.lang.StringgetDevLocaleName(int index)
Get one of supported device locales (by number).

param
index index of locale to select
return
locale name

private static native intgetDevLocalesCount()
Get number of supported locales for device resources.

return
number of locales

public ResourceManagergetManager(java.lang.String baseName)
Returns an instance of ResourceManager class for the given base name and system's default locale. This method is never used - default system locale is handled in the {@link javax.microedition.global.ResourceManager} class.

param
baseName the base name
return
the resource manager for the base name
throws
ResourceException if the resources for the base name doesn't exist
throws
UnsupportedLocaleException if the resources of the specified base name aren't available for the system's default locale
see
javax.microedition.global.ResourceManager#getManager(String)

        return null;
    
public ResourceManagergetManager(java.lang.String baseName, java.lang.String locale)
Creates an instance of ResourceManager class for the given base name and locale.

param
baseName the base name
param
locale the locale
return
the resource manager for the base name and locale
throws
ResourceException if the resources for the base name and locale doesn't exist
throws
UnsupportedLocaleException if the resources of the specified base name aren't available for the locale
see
javax.microedition.global.ResourceManager#getManager(String, String)

        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
                           classname + ": getManager (" +
                           baseName + ", " + locale + ")");
        }

        String[] supported_locales = getSupportedLocales(baseName);
        Vector vlocales = new Vector(5);
        Vector vreaders = new Vector(5);

		if (locale == null) locale = "";

        // go through all parent locales match them against supported locales
        for (String alocale = locale; alocale != null;
                 alocale = LocaleHelpers.getParentLocale(alocale)) {
            int index = LocaleHelpers.indexInSupportedLocales(alocale,
                    supported_locales);
            if (index >= 0) {
                ResourceBundleReader reader =
                        new DevResourceBundleReader(index);
                if (null != reader) {
                    vlocales.addElement(alocale);
                    vreaders.addElement(reader);
                } else {
                    throw new ResourceException(
                        ResourceException.NO_RESOURCES_FOR_BASE_NAME,
                        "Device resources for \"" + alocale +
                        "\" are missing.");
                }
            } else {
                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
                    Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
                                   classname + ": " + "locale \"" +
                                   alocale + "\" not supported.");
                }
            }
        }

        if (vlocales.size() == 0) {
            // base name not supported for locale nor for any parent locale
            throw new UnsupportedLocaleException();
        }

        String[] drm_locales = new String[vlocales.size()];
        ResourceBundleReader[] drm_readers =
                new ResourceBundleReader[vreaders.size()];
        vlocales.copyInto(drm_locales);
        vreaders.copyInto(drm_readers);

        // instantiate ResourceManager with supported locales
        return new DevResourceManager(drm_locales, drm_readers, resourceCache);
    
public ResourceManagergetManager(java.lang.String baseName, java.lang.String[] locales)
Creates an instance of ResourceManager class for the given base name and the first matching locale in the supplied array.

param
baseName the base name
param
locales the array of locales
return
the resource manager for the base name and the matched locale
throws
ResourceException if no resources for the base name and any of the locales in the array are found
throws
UnsupportedLocaleException if the resources of the specified base name are available for no locale from the array
see
javax.microedition.global.ResourceManager#getManager(String, String[])

        String[] supported_locales = getSupportedLocales(baseName);
        for (int i = 0; i < locales.length; i++) {
            int index = LocaleHelpers.indexInSupportedLocales(locales[i],
                    supported_locales);
            if (index >= 0) {
                return getManager(baseName, locales[i]);
            }
        }
        throw new UnsupportedLocaleException();
    
public java.lang.String[]getSupportedLocales(java.lang.String baseName)
Returns a list of locales supported by DevResourceManager. Device resource manager can be constructed for each locale from the list.

param
baseName the base name
return
the list of the supported locales

        int lcount = getDevLocalesCount();
        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
                           "Number of supported locales: " + lcount);
        }
        String[] locales = new String[lcount--];
        for (; lcount >= 0; lcount--) {
            locales[lcount] = getDevLocaleName(lcount);
            if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
                Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
                               "Locale #" + lcount + ": " + locales[lcount]);
            }
        }

        return locales;