Methods Summary |
---|
public ResourceManager | getManager(java.lang.String baseName)Get manager for system locale. It's never used. {@link
AppResourceManagerFactory#getManager(String)} replaces this call.
return null;
|
private ResourceManager | getManager(java.lang.String baseName, java.lang.String locale, com.sun.j2me.global.AppResourceManagerFactory$MetaFile mf, ResourceBundleReader rbr)Instantiates ResourceManager for a given locale, going
through all parent locales and creating respective
{@link ResourceBundleReader}s for them.
// locales
Vector l = new Vector(5);
// readers
Vector r = new Vector(5);
l.addElement(locale);
r.addElement(rbr);
locale = LocaleHelpers.getParentLocale(locale);
/*
* Go through all parent locales,
* e.g. "en-US-var", "en-US", "en", "", null
*/
while (locale != null) {
if (mf.containsLocale(locale)) {
try {
ResourceBundleReader reader =
getResourceBundleReaderForName(
getResourceUrl(baseName, locale));
l.addElement(locale);
r.addElement(reader);
} catch (ResourceException re_ignore) {
/* intentionally ignored */
/* For parent locales it does not throw exception in case any */
/* problems. The exception is thrown for the current locale */
/* only in the public getManager methods. */
}
}
locale = LocaleHelpers.getParentLocale(locale);
}
String[] locales = new String[l.size()];
ResourceBundleReader[] readers = new ResourceBundleReader[r.size()];
l.copyInto(locales);
r.copyInto(readers);
// instantiate ResourceManager with supported locales
return newResourceManagerInstance(baseName, locales, readers);
|
public ResourceManager | getManager(java.lang.String baseName, java.lang.String locale)Creates ResourceManager for given base name and locale.
Locale inheritance is resolved here. All parent locales are found and
ResourceManager is instantiated for the first locale that
is supported and contains any resources. Metafile is read for base name
and parent locales are matched with locales from the metafile.
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
classname + ": " + "getManager (" +
baseName + "," + locale + ")");
}
Vector l = new Vector(4);
while (locale != null) {
l.addElement(locale);
locale = LocaleHelpers.getParentLocale(locale);
}
String[] locales = new String[l.size()];
l.copyInto(locales);
return getManager(baseName, locales);
|
public ResourceManager | getManager(java.lang.String baseName, java.lang.String[] locales)Create ResourceManager for given base name and list of locales. No
locale inheritance used here. Metafile is read for base name and locales
in array are matched with locales from metafile. Only those that match
are used.
// read metafile
MetaFile mf = getMetafileForBaseName(baseName);
// match locales with those read from metafile
for (int i = 0; i < locales.length; i++) {
if (mf.containsLocale(locales[i])) {
ResourceBundleReader reader = getResourceBundleReaderForName(
getResourceUrl(baseName, locales[i]));
return getManager(baseName, locales[i], mf, reader);
}
}
throw new UnsupportedLocaleException();
|
protected com.sun.j2me.global.AppResourceManagerFactory$MetaFile | getMetafileForBaseName(java.lang.String baseName)Read metafile {@link MetaFile} for givane base name. Metafiles are
stored under global directory in form _<base name>.
MetaFile mf;
int hcode = resourceCache.getHashCodeForResource("_" + baseName, "", 0);
Resource r = resourceCache.lookup(hcode);
if (r == null) {
try {
mf = new MetaFile(GLOBAL_PREFIX + "_" + baseName);
} catch (IOException ioe) {
throw new ResourceException(
ResourceException.METAFILE_NOT_FOUND,
"Not found metafile for base name \""
+ baseName + "\"");
}
resourceCache.addResource(new Resource(hcode, mf.getSize(), mf));
} else {
mf = (MetaFile) r.getValue();
}
return (MetaFile)mf.clone();
|
protected ResourceBundleReader | getResourceBundleReaderForName(java.lang.String name)Creates initialized instance of ResourceBundleReader for given name.
It opens resource file and reads header.
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
classname + ": getResourceBundleReaderForName (" +
name + ")");
}
return AppResourceBundleReader.getInstance(name);
|
protected java.lang.String | getResourceUrl(java.lang.String baseName, java.lang.String locale)Gives resource URL that can be used for method {@link
Class#getResourceAsStream}.
String resourceUrl;
resourceUrl = (locale != null && locale.length() > 0)
? GLOBAL_PREFIX + locale + "/" + baseName
: GLOBAL_PREFIX + baseName;
String url = resourceUrl + RESOURCE_FILE_EXTENSION;
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
classname + ": url=" + url);
}
return url;
|
public java.lang.String[] | getSupportedLocales(java.lang.String baseName)Get array of supported locales for given base name. It reads metafile
for the base name.
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
classname + ": getSupportedLocales");
}
if (baseName == null)
throw new NullPointerException("Basename is null.");
MetaFile mf = getMetafileForBaseName(baseName);
String[] locales = mf.toArray();
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
for (int i = 0; i < locales.length; i++) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
locales[i]);
}
}
return locales;
|
protected ResourceManager | newResourceManagerInstance(java.lang.String baseName, java.lang.String[] locales, ResourceBundleReader[] readers)Creates a new instance of AppResourceManager . The new
instance can be used to get application resources of the given base name
and locale. The resource files will be accessed through the given
resource bundle reader.
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
classname + ": " +
"Creating new AppResourceManager for \"" +
baseName + "\" with cache: " + this.resourceCache +
"\nwith readers:");
for (int i = 0; i < readers.length; i++) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
readers[i].toString());
}
}
return new AppResourceManager(baseName,
locales,
readers,
this.resourceCache);
|