ResourceManagerpublic class ResourceManager extends Object Resource manager functions implemetation. Provides a functionality of
{@link javax.microedition.global.ResourceManager}.
This class is required due to requirement do not have public/protected
constructor in javax.microedition.global.ResourceManager.
More detailed comments see for javax.microedition.global.ResourceManager. |
Fields Summary |
---|
private static com.sun.j2me.global.ResourceAbstractionLayer | abstractionLayerThe instance of ResourceAbstractionLayer. | public static final String | DEVICEConstant to indicate device resources. | private String | baseNameThe base name. | private String | localeThe locale identifier. |
Constructors Summary |
---|
protected ResourceManager()Creates a new instance of ResourceManager .
|
Methods Summary |
---|
public java.lang.String | getBaseName()Gets the base name of this resource manager.
return baseName;
| public byte[] | getData(int id)Gets a resource with the specified resource ID as a byte array
containing arbitrary binary data. If the resource with the specified ID
is not binary data, or the resource does not exist, a ResourceException
is thrown with the appropriate error code.
This method performs a hierarchical lookup of the resource.
throw new ResourceException(ResourceException.UNKNOWN_ERROR, "");
| public java.lang.String | getLocale()Gets current locale of this ResourceManager .
return locale;
| public static final com.sun.j2me.global.ResourceManager | getManager(java.lang.String baseName, java.lang.String locale)Gets a resource manager for the specified base name and locale.
If the base name is {@link #DEVICE} (the empty string), the resource
manager can only retrieve device resources. Other base names retrieve
application resources. The base name must not be null .
If resources for the specified locale are not found, this method
attempts to find resources by hierarchical matching. The matching
proceeds from language-country-variant to language-country
, then on to language , and finally to the empty string.
An empty string can also be used as the locale. It is a shortcut to
using common resources without going through the matching process.
If resources for the combination of the base name and the matching
locale are found, this method returns a manager for those resources. If
no resources are found for the combination, a
ResourceException is thrown.
// DevResourceManager
if (baseName.equals(DEVICE)) {
ResourceManagerFactory devMFactory =
abstractionLayer.getDevResourceManagerFactory();
return devMFactory.getManager(DEVICE, locale);
}
// appResourceManager
else {
ResourceManagerFactory appMFactory =
abstractionLayer.getAppResourceManagerFactory();
return appMFactory.getManager(baseName, locale);
}
| public static final com.sun.j2me.global.ResourceManager | getManager(java.lang.String baseName, java.lang.String[] locales)Gets a resource manager for the specified base name and the first
matching locale in the supplied array.
If the base name is {@link #DEVICE} (the empty string), the resource
manager can only retrieve device resources. Other base names retrieve
application resources. The base name MUST NOT be null .
This method attempts to get a resource manager for a combination of the
base name and one of the locales in the array. The locales are tried
successively, stopping at the first match. This method MUST NOT perform
hierarchical matching. If none of the locales in the array result in a
match, a ResourceException MUST be thrown with the
appropriate error code.
For example , if the array of locales contains { "de-DE",
"fr", "en" } , and resources are not found for "de-DE"
or "fr" , but are found for "en" , then this
method gets a manager for "en" . However, if resources are
not found for "de-DE" , but are found for "fr" ,
then this method gets a manager for "fr" and disregards the
"en" locale. In this case if resources are not found for
"de-DE" , the locale "de" MUST NOT be tried;
instead the matching proceeds to the next locale in the array.
The locales array MUST NOT be null . Each of
the locale identifiers in the array MUST be a valid locale identifier,
otherwise an IllegalArgumentException is thrown. As an
extension, the empty string can be used to use resources common to all
locales.
String[] norm_locs = new String[locales.length];
for (int i = 0; i < locales.length; i++) {
norm_locs[i] = LocaleHelpers.normalizeLocale(locales[i]);
}
// DevResourceManager
if (baseName.equals(DEVICE)) {
ResourceManagerFactory devMFactory =
abstractionLayer.getDevResourceManagerFactory();
return devMFactory.getManager(DEVICE, norm_locs);
}
// appResourceManager
else {
ResourceManagerFactory appMFactory =
abstractionLayer.getAppResourceManagerFactory();
return appMFactory.getManager(baseName, norm_locs);
}
| public java.lang.Object | getResource(int id)Gets a resource with the specified ID. The resource is either an
application-specific resource or a device resource, depending on the
base name of the resource manager.
This method performs a hierarchical lookup of the resource.
throw new ResourceException(ResourceException.UNKNOWN_ERROR, "");
| public java.lang.String | getString(int id)Gets a string with the specified resource ID. This is a convenience
method to avoid typecasting in applications. If the resource with the
specified ID is not a string, or the resource does not exist, a
ResourceException is thrown with the appropriate error code.
This method performs a hierarchical lookup of the resource.
throw new ResourceException(ResourceException.UNKNOWN_ERROR, "");
| public static java.lang.String[] | getSupportedLocales(java.lang.String baseName)Gets the locales supported by this resource manager for the given base
name. Returns an array of valid microedition.locale values.
If there are no supported locales, returns an empty array
(not null ).
The base name is used to distinguish between application and device
resources. If the base name is non-empty, this method returns the list
of locales for which application-specific resources are defined. If the
base name is {@link #DEVICE} (the empty string), the set of supported
device locales is returned instead.
The returned array MAY be empty if no locales are supported for the
specified base name. It MUST NOT be null .
Values in the array MUST be unique. The value null MUST NOT
appear in the returned array. However, if there are resources for this
base name which are common to all locales, the array MUST contain the
empty string. It SHOULD be first element in the array.
The supported locales for an application resource manager require a base
name specific meta-information file described in the "Enumerating
supported locales" section of the specification overview. If the
meta-information file is not found, this method MUST throw
a ResourceException with the error code
METAFILE_NOT_FOUND .
If the content of the meta-information file is not syntactically valid,
this method MUST throw a ResourceException with the error code
DATA_ERROR
The list of locales supported by a resource manager for a base name MAY
be different than in a formatter, i.e. the implementation MAY support
formatting rules for a certain set of locales, but an application can
supply resources for an entirely different (or overlapping) set of
locales.
if (baseName == null) {
throw new NullPointerException("Base name is null");
}
// DevResourceManager
if (baseName.equals(DEVICE)) {
ResourceManagerFactory devMFactory =
abstractionLayer.getDevResourceManagerFactory();
return devMFactory.getSupportedLocales(baseName);
}
// appResourceManager
else {
ResourceManagerFactory appMFactory =
abstractionLayer.getAppResourceManagerFactory();
return appMFactory.getSupportedLocales(baseName);
}
| public boolean | isCaching()Returns the caching status of this resource manager.
return false;
| public boolean | isValidResourceID(int id)Determines if the given resource ID is valid in this implementation. In
this context "valid" means that a resource exists with the given
resource ID, and calling getResource with that ID returns a
non-null object instance.
The method does not discriminate between application and device
resources, since one resource manager can only handle one type of
resource.
return false;
| protected void | setBaseName(java.lang.String baseName)Sets base name for resource files used by this
ResourceManager .
this.baseName = baseName;
| protected void | setLocale(java.lang.String locale)Sets locale code for this ResourceManager .
this.locale = locale;
|
|