Class ResourceBundleProvider
This class provides static methods for loading and accessing resource bundles to support
internationalization in MCP server applications. It uses the McpI18nEnabled annotation to
configure the resource bundle base name.
The class maintains a singleton ResourceBundle instance that is loaded from the
specified base name using the default locale. The resource bundle can be accessed through a
supplier for lazy evaluation and thread safety.
Key features:
- Loads resource bundles based on
McpI18nEnabledannotation configuration - Provides a supplier for accessing the loaded resource bundle
- Supports default locale for resource bundle resolution
- Follows the utility class pattern with a private constructor
- Author:
- codeboyzhou
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ResourceBundleReturns the loaded resource bundle instance.static voidloadResourceBundle(Class<?> mainClass) Loads a resource bundle based on theMcpI18nEnabledannotation on the main class.
-
Field Details
-
log
public static final org.slf4j.Logger log
-
-
Method Details
-
loadResourceBundle
Loads a resource bundle based on theMcpI18nEnabledannotation on the main class.This method checks if the main class is annotated with
@McpI18nEnabled. If the annotation is present, it loads a resource bundle using the base name specified in the annotation'sresourceBundleBaseNameattribute. The resource bundle is loaded using the default locale.If the annotation is not present, the method logs an info message and returns without loading any resource bundle, effectively disabling i18n support.
- Parameters:
mainClass- the main application class to check for the McpI18nEnabled annotation- Throws:
IllegalArgumentException- if the resourceBundleBaseName is blankMissingResourceException- if no resource bundle is found for the specified base name- See Also:
-
getResourceBundle
Returns the loaded resource bundle instance.This method returns the currently loaded
ResourceBundleinstance, if the main class was not annotated withMcpI18nEnabled, this method returnsnull.- Returns:
- the loaded resource bundle instance, or
nullif not loaded - See Also:
-