Class ResourceBundleProvider

java.lang.Object
com.github.thought2code.mcp.annotated.server.component.ResourceBundleProvider

public final class ResourceBundleProvider extends Object
A provider class for managing internationalization (i18n) resource bundles.

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 McpI18nEnabled annotation 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 Details

    • log

      public static final org.slf4j.Logger log
  • Method Details

    • loadResourceBundle

      public static void loadResourceBundle(Class<?> mainClass)
      Loads a resource bundle based on the McpI18nEnabled annotation 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's resourceBundleBaseName attribute. 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 blank
      MissingResourceException - if no resource bundle is found for the specified base name
      See Also:
    • getResourceBundle

      public static ResourceBundle getResourceBundle()
      Returns the loaded resource bundle instance.

      This method returns the currently loaded ResourceBundle instance, if the main class was not annotated with McpI18nEnabled, this method returns null.

      Returns:
      the loaded resource bundle instance, or null if not loaded
      See Also: