Class I18nSpringConfiguration

java.lang.Object
dev.orne.i18n.spring.I18nSpringConfiguration
All Implemented Interfaces:
I18nContextProvider.Configurer, org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.annotation.ImportAware, org.springframework.context.ApplicationContextAware, org.springframework.context.MessageSourceAware
Direct Known Subclasses:
I18nSpringWebConfiguration

@API(status=STABLE, since="0.1") @Configuration public class I18nSpringConfiguration extends Object implements org.springframework.context.ApplicationContextAware, org.springframework.context.MessageSourceAware, org.springframework.context.annotation.ImportAware, org.springframework.beans.factory.InitializingBean, I18nContextProvider.Configurer
I18N context provider configuration for Spring. Configures a I18nContextProvider (an instance of I18nSpringContextProvider by default).

By default configures the provider for all ClassLoaders. Supports selecting a target class that will configure the provider for the ClassLoader of the given class and all its children ClassLoader, allowing different configurations for each application even when the library is deployed as a shared library or different configurations for each sub-module when the library is deployed at EAR level in JavaEE environments.

Since:
0.1
Version:
1.0, 2023-05
Author:
(w) Iker Hernaez
See Also:
  • Field Details

    • DEFAULT_CONFIGURER

      protected static final I18nSpringConfigurer DEFAULT_CONFIGURER
      The default I18N context provider configuration customizer.
  • Constructor Details

    • I18nSpringConfiguration

      public I18nSpringConfiguration()
      Creates a new instance.
  • Method Details

    • getApplicationContext

      protected org.springframework.context.ApplicationContext getApplicationContext()
      Returns the Spring application context.
      Returns:
      The Spring application context.
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • getMessageSource

      protected org.springframework.context.MessageSource getMessageSource()
      Returns the application default MessageSource.
      Returns:
      The application default MessageSource.
    • setMessageSource

      public void setMessageSource(org.springframework.context.MessageSource messageSource)
      Specified by:
      setMessageSource in interface org.springframework.context.MessageSourceAware
    • getTarget

      protected ClassLoader getTarget()
      Returns the ClassLoader this configuration will be applied to.

      If null the configuration will be applied to current thread's context class loader.

      Returns:
      The target class loader.
    • setTarget

      public void setTarget(ClassLoader target)
      Sets the ClassLoader this configuration will be applied to.

      If null the configuration will be applied to current thread's context class loader.

      Parameters:
      target - The target class loader.
    • setImportMetadata

      public void setImportMetadata(@NotNull @NotNull org.springframework.core.type.AnnotationMetadata importMetadata)
      Inherits configuration from EnableI18N annotation.
      Specified by:
      setImportMetadata in interface org.springframework.context.annotation.ImportAware
      Parameters:
      importMetadata - The import metadata
      See Also:
    • determineConfigurer

      @NotNull protected @NotNull I18nSpringConfigurer determineConfigurer()
      Determines the I18N context provider configuration customizer to apply.
      Returns:
      The I18N context provider configuration customizer.
      Throws:
      IllegalStateException - If multiple instances of I18nSpringConfigurer are present in current Spring context.
    • createContextProvider

      @NotNull protected @NotNull I18nSpringContextProvider createContextProvider()
      Creates a new I18nSpringContextProvider based on configured properties.

      This implementation creates an instance of I18nSpringContextProvider.

      Returns:
      The new configured I18nSpringContextProvider
    • afterPropertiesSet

      public void afterPropertiesSet()
      Sets the configured I18nContextProvider for the configured ClassLoader.
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean