public final class EELFResourceManager extends Object
Resource Bundles are pluggable definitions of any type of resource that may be needed by the application and can be externalized. In a typical GUI application, for example, resources may be things like icons, bitmaps, cursors, or other graphic character definitions. In many cases, resources are also the messages that are issued by an application.
By externalizing the resources, and then providing a mechanism to load different versions of the resources, the application can be made to support multiple different languages and formatting customs. This is the essential mechanism in java to support internationalization (i18n). The key concept in the java support is that of a resource bundle. A resource bundle is a set, or collection, of resources identified by a key, and where each bundle represents a set of the same resource keys but with values specific to a particular language or region. For example, a message with the resource key of "ERROR_123" could have an entry in a US-English bundle as well as a France-French bundle. Bundles are usually identified by both a language and region code, although that is not required. For example, a bundle specifying only the French language would be used for Canada French as well as France.
This class supports the loading of multiple types of resource bundles and the formatting of messages from those bundles. A default bundle is loaded based on the server locale for use by server-side implementation. However, for client-side implementations, this resource manager also allows the locale to be specified and a resource obtained from a locale-specific bundle. This allows the code to format messages and resources appropriate to the client, and not just the server.
This ResourceManager also allows for additional bundles to be loaded to support bundles that may be needed for specific providers or extensions that may be loaded dynamically. In these cases, these provider implementations can request that their bundles be loaded and managed as part of the overall resources. It is important to have each provider or extension identify their resources using unique keys, because the resource manager will format the first resource it finds using the specified key by scanning the bundles. If two (or more) bundles define resources with the same key, the first occurrence found will be used.
lastly, this resource manager has the ability to manage multiple different sets of resource bundles, segregated from each other to support different uses. for example, a set of bundles can be loaded for the messages, while another set can be loaded for the resolutions, and yet another set loaded for the descriptions. this support can be extended to support any number of different sets of resource bundles in the future if needed.
| Modifier and Type | Method and Description |
|---|---|
static String |
asList(String... values)
This method is a helper that allows a caller to format a variable set of
strings as a list of the form "[value,...,value]"
|
static String |
format(EELFResolvableResourceEnum resourceId,
String... arguments)
Formats a message identified by the application msg enumeration
|
static String |
format(EELFResolvableResourceEnum resourceId,
Throwable exception,
String... arguments)
Formats a message identified by the application msg enumeration
|
static String |
format(Locale locale,
EELFResolvableResourceEnum resourceId,
String... arguments)
Formats a message identified by the application msg enumeration
|
static String |
format(Locale locale,
EELFResolvableResourceEnum resourceId,
Throwable exception,
String... arguments)
Formats a message identified by the application msg enumeration
|
static String |
format(Throwable t)
This method formats an exception object (throwable) in a standard way and
returns the result as a string.
|
static String |
format(Throwable t,
String contextMsg)
This method formats an exception object (throwable) in a standard way and
returns the result as a string.
|
static String |
formatError(EELFResolvableResourceEnum resourceId,
String... arguments)
Formats a message identified by the application msg enumeration
|
static String |
formatError(EELFResolvableResourceEnum resourceId,
Throwable exception,
String... arguments)
Formats a message identified by the application msg enumeration
|
static String |
formatError(Locale locale,
EELFResolvableResourceEnum resourceId,
String... arguments)
Formats a message identified by the application msg enumeration
|
static String |
formatError(Locale locale,
EELFResolvableResourceEnum resourceId,
Throwable exception,
String... arguments)
Formats a message identified by the application msg enumeration
|
static String |
getDescription(EELFResolvableResourceEnum resourceId)
This is a convenience method that returns the message description
indicated by the specified id, or key, in the resource bundle.
|
static String |
getDescription(Locale locale,
EELFResolvableResourceEnum resourceId)
Obtains the specified description from description resource bundles that
are loaded based on the resource id.
|
static String |
getIdentifier(EELFResolvableResourceEnum resourceId)
This is a convenience method that returns the message error code
indicated by the specified id, or key, in the resource bundle.
|
static String |
getIdentifier(Locale locale,
EELFResolvableResourceEnum resourceId)
Obtains the specified description from description resource bundles that
are loaded based on the resource id.
|
static String |
getMessage(EELFResolvableResourceEnum resourceId)
This is a method that returns the resource indicated by the specified id,
or key, in the resource bundle.
|
static String |
getMessage(EELFResolvableResourceEnum resourceId,
String... arguments)
This is a method that returns the resource indicated by the specified id,
or key, in the resource bundle.
|
static String |
getMessage(Locale locale,
String resourceId)
Returns the message resource indicated by the specified id, or key, in
the first message resource bundle loaded for the locale that contains the
resource.
|
static String |
getMessage(String resourceId)
This is a convenience method that returns the resource indicated by the
specified id, or key, in the resource bundle.
|
static String |
getResolution(EELFResolvableResourceEnum resource)
This is a convenience method that returns the message resolution
indicated by the specified id, or key, in the resource bundle.
|
static String |
getResolution(Locale locale,
EELFResolvableResourceEnum resource)
Obtains the specified resolution from the resource bundles that are
loaded based on the resource id.
|
static void |
loadDescriptionBundle(String baseName)
Called to request that a specified description bundle base name be added
to the set of resources managed by the resource manager.
|
static void |
loadMessageBundle(String baseName)
Called to request that a specified message bundle base name be added to
the set of resources managed by the resource manager.
|
static void |
loadResolutionBundle(String baseName)
Called to request that a specified resolution bundle base name be added
to the set of resources managed by the resource manager.
|
public static String asList(String... values)
values - The variable argument list of string values to be formatted
as a listpublic static String format(Locale locale, EELFResolvableResourceEnum resourceId, String... arguments)
locale - The locale that we want to load the resource forresourceId - The resource to be formattedarguments - The arguments to the messagepublic static String format(Locale locale, EELFResolvableResourceEnum resourceId, Throwable exception, String... arguments)
locale - The locale that we want to load the resource forresourceId - The resource to be formattedexception - The exception to be formattedarguments - The arguments to the messagepublic static String format(EELFResolvableResourceEnum resourceId, String... arguments)
resourceId - The resource to be formattedarguments - The arguments to the messagepublic static String format(EELFResolvableResourceEnum resourceId, Throwable exception, String... arguments)
resourceId - The resource to be formattedexception - the exception to be formattedarguments - The arguments to the messagepublic static String format(Throwable t)
t - The throwable to be formattedpublic static String format(Throwable t, String contextMsg)
t - The throwable to be formattedcontextMsg - Message to provide application context of this
exceptionpublic static String getDescription(Locale locale, EELFResolvableResourceEnum resourceId)
locale - The locale that we want to load the resource forresourceId - The EELFResolvableResourceEnum to be locatedpublic static String getDescription(EELFResolvableResourceEnum resourceId)
resourceId - The EELFResolvableResourceEnum to be locatedpublic static String getMessage(Locale locale, String resourceId)
locale - The locale that we want to load the resource forresourceId - The resource to be locatedpublic static String getMessage(String resourceId)
resourceId - The resource to be locatedpublic static String getMessage(EELFResolvableResourceEnum resourceId)
resourceId - The resource to be locatedpublic static String getMessage(EELFResolvableResourceEnum resourceId, String... arguments)
resourceId - The resource to be locatedarguments - The arguments to the messagepublic static String getResolution(Locale locale, EELFResolvableResourceEnum resource)
locale - The locale that we want to load the resource forresource - The resource to be locatedpublic static String getResolution(EELFResolvableResourceEnum resource)
resource - The resource to be locatedpublic static void loadDescriptionBundle(String baseName)
baseName - The bundle base name to be added to the set of bundle
base names that are being managed.public static void loadMessageBundle(String baseName)
baseName - The bundle base name to be added to the set of bundle
base names that are being managed.public static void loadResolutionBundle(String baseName)
baseName - The bundle base name to be added to the set of bundle
base names that are being managed.public static String getIdentifier(EELFResolvableResourceEnum resourceId)
resourceId - The EELFResolvableResourceEnum to be locatedpublic static String getIdentifier(Locale locale, EELFResolvableResourceEnum resourceId)
locale - The locale that we want to load the resource forresourceId - The EELFResolvableResourceEnum to be locatedpublic static String formatError(EELFResolvableResourceEnum resourceId, String... arguments)
resourceId - The resource to be formattedarguments - The arguments to the messagepublic static String formatError(Locale locale, EELFResolvableResourceEnum resourceId, Throwable exception, String... arguments)
locale - The locale that we want to load the resource forresourceId - The resource to be formattedexception - The exception to be formattedarguments - The arguments to the messagepublic static String formatError(EELFResolvableResourceEnum resourceId, Throwable exception, String... arguments)
resourceId - The resource to be formattedexception - the exception to be formattedarguments - The arguments to the messagepublic static String formatError(Locale locale, EELFResolvableResourceEnum resourceId, String... arguments)
locale - The locale that we want to load the resource forresourceId - The resource to be formattedarguments - The arguments to the messageCopyright © 2019. All rights reserved.