public abstract class C10NConfigBase extends Object
| Modifier and Type | Class and Description |
|---|---|
protected static class |
C10NConfigBase.C10NAnnotationBinder |
protected static class |
C10NConfigBase.C10NFilterBinder<T>
Filter binding DSL object.
|
protected static class |
C10NConfigBase.C10NImplementationBinder<T> |
| Constructor and Description |
|---|
C10NConfigBase() |
| Modifier and Type | Method and Description |
|---|---|
protected <T> C10NConfigBase.C10NImplementationBinder<T> |
bind(Class<T> c10nInterface)
Create a custom implementation binding for the given c10n interface
|
protected C10NConfigBase.C10NAnnotationBinder |
bindAnnotation(Class<? extends Annotation> annotationClass)
Create a method annotation binding to the specified locale
|
protected C10NBundleBinder |
bindBundle(String baseName) |
protected <T> C10NConfigBase.C10NFilterBinder<T> |
bindFilter(C10NFilter<T> c10nFilter,
Class<T> type)
Create a filter binding for one or more argument types.
|
protected <T> C10NConfigBase.C10NFilterBinder<T> |
bindFilter(C10NFilterProvider<T> c10NFilterProvider,
Class<T> type)
Create a filter binding for one or more argument types.
|
protected abstract void |
configure()
To be implemented by subclasses of
C10NConfigBase. |
protected String |
getConfigurationPackage()
Get the name of the package for which the current
module is responsible.
|
protected void |
install(C10NConfigBase childConfig)
Install the given child c10n configuration module
|
protected void |
setDebug(boolean debug)
If set to 'true', c10n will output debugging information to std-out at configuration and lookup time.
|
protected void |
setKeyPrefix(String key)
Set global key prefix.
|
protected void |
setLocale(Locale locale)
Fixes the
Locale to the specified locale. |
protected void |
setLocaleProvider(LocaleProvider localeProvider)
Sets the
LocaleProvider for this configuration. |
protected void |
setUntranslatedMessageHandler(UntranslatedMessageHandler handler)
Customise placeholder value for unresolved translations.
|
protected abstract void configure()
To be implemented by subclasses of C10NConfigBase.
Configuration methods are as follows:
bindAnnotation(Class) - binds annotation that holds translation for a specific locale.bindBundle(String) - binds a resource bundle containing translated messages.install(C10NConfigBase) - includes configuration from another c10n configuration modulebind(Class) - binds a custom class as an implementation for the given c10n interfacesetLocaleProvider(LocaleProvider) - customises the locale retrieval logicsetUntranslatedMessageHandler(UntranslatedMessageHandler) - customises the placeholder for
unresolved translation mappingssetKeyPrefix(String) - sets global key prefix to auto-prepend to all bundle keysprotected String getConfigurationPackage()
Get the name of the package for which the current module is responsible.
The name of the package is used to determine which c10n interfaces this configuration is responsible for
The default implementation, which returns the string representation of the package of the configuration class, should suffice in most cases
protected void install(C10NConfigBase childConfig)
Install the given child c10n configuration module
This will apply the configuration to all c10n interfaces located in the child configuration package or below.
childConfig - child c10n configuration to install (not-null)protected <T> C10NConfigBase.C10NImplementationBinder<T> bind(Class<T> c10nInterface)
Create a custom implementation binding for the given c10n interface
There are two basic usages:
bind(Messages.class).to(JapaneseMessagesImpl.class, Locale.JAPANESE);
which will use the JapaneseMessagesImpl.class when locale is
set to Locale.JAPANESE
The second usage is:
bind(Messages.class).to(FallbackMessagesImpl.class);
which will use the FallbackMessagesImpl.class when no other
implementation class was matched for the current locale.T - C10N interface typec10nInterface - C10N interface to create an implementation binding for (not-null)protected void setLocaleProvider(LocaleProvider localeProvider)
Sets the LocaleProvider for this configuration.
Locale provider is consulted every time a translation is requested, that is every time a method on an c10n interface is called.
As a rule, there should be only one locale provider per application.
Any locale providers defined in child configurations (see install(C10NConfigBase)
are disregarded.
Because locale provider has to be consulted on every translation request
LocaleProvider.getLocale() should avoid any CPU intensive processing
Default locale provider implementation always returns the same result as
Locale.getDefault()
localeProvider - custom locale provider (not-null)protected void setLocale(Locale locale)
Fixes the Locale to the specified locale.
Generally useful when your application needs to create separate
C10NMsgFactory instances for each locale.
locale - Locale to useprotected void setUntranslatedMessageHandler(UntranslatedMessageHandler handler)
Customise placeholder value for unresolved translations.
The default behaviour is to return a string in format:
[InterfaceName].[MethodName]([ArgumentValues])
handler - custom implementation of untranslated message handler (not-null)protected C10NConfigBase.C10NAnnotationBinder bindAnnotation(Class<? extends Annotation> annotationClass)
Create a method annotation binding to the specified locale
There are two basic usages:
bindAnnotation(Ja.class).to(Locale.JAPANESE);
which will tell c10n to take the value given in the @Ja
annotation whenever the current locale is Locale.JAPANESE
The second usage is:
bindAnnotation(En.class);
which will make c10n always fallback to the value given in the @En
annotation if no other annotation binding matched the current locale.
Note: Some default annotation bindings are defined in DefaultC10NAnnotations.
In order to use install(new DefaultC10NAnnotations()); somewhere in your configuration
(see install(C10NConfigBase)
annotationClass - Class of the annotation to create a local binding for (not-null)protected <T> C10NConfigBase.C10NFilterBinder<T> bindFilter(C10NFilterProvider<T> c10NFilterProvider, Class<T> type)
Create a filter binding for one or more argument types.
All arguments passed to c10n-interfaces with the specified type(s) will
be converted to string using the filter generated by the given filter provider,
instead of the conventional toString() method.
Filter creation (using C10NFilterProvider.get() method) will be
deferred until the first call to a c10n-interface method with a matching
argument type is executed.
c10NFilterProvider - provider of filter implementation (not-null)type - method argument type to which the filter should be appliedC10NConfigBase.C10NFilterBinderprotected <T> C10NConfigBase.C10NFilterBinder<T> bindFilter(C10NFilter<T> c10nFilter, Class<T> type)
Create a filter binding for one or more argument types.
All arguments passed to c10n-interfaces with the specified type(s) will
be converted to string using this filter, instead of the conventional toString()
method.
c10nFilter - filter implementation (not-null)type - method argument type to which the filter should be appliedC10NConfigBase.C10NFilterBinderprotected void setKeyPrefix(String key)
Set global key prefix. All other keys will be automatically prepended with the global key.
Settings key prefix to an empty string resets to default behaviour (no prefix).
key - the key to use at configuration scope (not null)protected void setDebug(boolean debug)
If set to 'true', c10n will output debugging information to std-out at configuration and lookup time.
debug - debug flagprotected C10NBundleBinder bindBundle(String baseName)
Copyright © 2013. All Rights Reserved.