Package dev.orne.i18n.spring
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 ClassLoader
s.
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 Summary
Modifier and TypeFieldDescriptionprotected static final I18nSpringConfigurer
The default I18N context provider configuration customizer. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Sets the configuredI18nContextProvider
for the configuredClassLoader
.protected @NotNull I18nSpringContextProvider
Creates a newI18nSpringContextProvider
based on configured properties.protected @NotNull I18nSpringConfigurer
Determines the I18N context provider configuration customizer to apply.protected org.springframework.context.ApplicationContext
Returns the Spring application context.protected org.springframework.context.MessageSource
Returns the application defaultMessageSource
.protected ClassLoader
Returns theClassLoader
this configuration will be applied to.void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) void
setImportMetadata
(@NotNull org.springframework.core.type.AnnotationMetadata importMetadata) Inherits configuration fromEnableI18N
annotation.void
setMessageSource
(org.springframework.context.MessageSource messageSource) void
setTarget
(ClassLoader target) Sets theClassLoader
this configuration will be applied to.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.orne.i18n.context.I18nContextProvider.Configurer
setI18nConfiguration, setI18nConfiguration, setI18nContextProvider, setI18nContextProvider
-
Field Details
-
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 interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource()Returns the application defaultMessageSource
.- Returns:
- The application default
MessageSource
.
-
setMessageSource
public void setMessageSource(org.springframework.context.MessageSource messageSource) - Specified by:
setMessageSource
in interfaceorg.springframework.context.MessageSourceAware
-
getTarget
Returns theClassLoader
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
Sets theClassLoader
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 fromEnableI18N
annotation.- Specified by:
setImportMetadata
in interfaceorg.springframework.context.annotation.ImportAware
- Parameters:
importMetadata
- The import metadata- See Also:
-
determineConfigurer
Determines the I18N context provider configuration customizer to apply.- Returns:
- The I18N context provider configuration customizer.
- Throws:
IllegalStateException
- If multiple instances ofI18nSpringConfigurer
are present in current Spring context.
-
createContextProvider
Creates a newI18nSpringContextProvider
based on configured properties.This implementation creates an instance of
I18nSpringContextProvider
.- Returns:
- The new configured
I18nSpringContextProvider
-
afterPropertiesSet
public void afterPropertiesSet()Sets the configuredI18nContextProvider
for the configuredClassLoader
.- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-