DevResourceManagerFactorypublic class DevResourceManagerFactory extends AppResourceManagerFactory This class represents a resource manager factory for creating device
resource managers. |
Fields Summary |
---|
private static final String | BASENAMEDefault resource file name for device resources. | private static final String | classnameClass name. | private static com.sun.midp.security.SecurityToken | classSecurityTokenSecurity token to allow access to implementation APIs |
Constructors Summary |
---|
public DevResourceManagerFactory()Default constructor for SecurityToken initialization.
super(null);
| public DevResourceManagerFactory(ResourceCache cache)Creates a new resource manager factory for creating device resource
managers.
super(cache);
|
Methods Summary |
---|
protected MetaFile | getMetafileForBaseName(java.lang.String baseName)Read metafile {@link
com.sun.j2me.global.AppResourceManagerFactory.MetaFile}
for given base name. Metafiles are stored under global directory
in form _<base name>.
MetaFile mf;
if (baseName != null && baseName.length() == 0) {
baseName = BASENAME;
}
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
classname + ": Get metafile for \"" +
baseName + "\"");
}
int hcode = resourceCache.getHashCodeForResource("_" + baseName, "", 0);
Resource r = resourceCache.lookup(hcode);
if (r == null) {
String mfileName = "_" + baseName;
try {
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
classname + ": " +
"Not found in cache. Reading from store:" +
"\"" + mfileName + "\"");
}
RandomAccessStream storage =
new RandomAccessStream(classSecurityToken);
if (storage == null) {
throw new IOException("Storage is null.");
}
storage.connect(File.getConfigRoot(Constants.INTERNAL_STORAGE_ID)
+ Configuration.getProperty("microedition.global.root")
+ mfileName, Connector.READ);
InputStream is = storage.openInputStream();
mf = new MetaFile(is);
is.close();
} 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)Create new {@link ResourceBundleReader} for reading device
resources.
return DevResourceBundleReader.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 name)}.
String resourceUrl;
if (baseName == null ||
baseName.length() == 0) {
baseName = "common.res";
}
resourceUrl = (locale != null && locale.length() > 0)
? locale + "/" + baseName
: baseName;
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
classname + ": url=" + resourceUrl);
}
return resourceUrl;
| protected ResourceManager | newResourceManagerInstance(java.lang.String baseName, java.lang.String[] locales, ResourceBundleReader[] readers)Creates a new instance of DevResourceManager . The new
instance can be used to get device resources of the given 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 DevResourceManager " +
"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 DevResourceManager(baseName,
locales,
readers,
this.resourceCache);
|
|