T
- the type of Object this I18nKeyGenerator
generates keys for.public abstract class AbstractI18nKeyGenerator<T> extends Object implements I18nKeyGenerator<T>
I18nKeyGenerator
which provides a number of helper methods to generate keys.
By casting objects to I18nParentable
(see getParentViaCast(Object)
), implementations are
able to generate context-dependent keys for any given object.Constructor and Description |
---|
AbstractI18nKeyGenerator() |
Modifier and Type | Method and Description |
---|---|
protected void |
addKey(List<String> keys,
String... parts)
Adds a key to the given list; if the last part is "label", adds another key with it.
|
protected String |
fieldOrGetterName(AnnotatedElement el)
Returns the name of the field or method passed to
I18nKeyGenerator#keysFor(String, T, java.lang.reflect.AnnotatedElement) . |
protected <C> List<I18nKeyGenerator> |
getAncestorKeyGenerators(C obj)
Returns the
I18nKeyGenerator s corresponding to the parent objects of the given object. |
protected <C> List<Object> |
getAncestors(C obj)
Returns the list of parent objects as set via the
I18nParentable interface
when the object was decorated by I18nizer . |
protected String |
getIdOrNameForUnknownRoot(Object obj)
Will try to call either
getId() or getName() on a root object of unknown type. |
protected <P> I18nKeyGenerator<P> |
getKeyGenerator(P obj)
Returns the
I18nKeyGenerator s corresponding to the given object. |
protected <P,C> P |
getParentViaCast(C obj)
Returns the parent object that was set via the
I18nParentable interface
when the object was decorated by I18nizer . |
protected <C> Object |
getRoot(C obj)
Returns the root object that of the
I18nParentable hierarchy. |
protected <C> I18nKeyGenerator |
getRootKeyGenerator(C obj)
Returns the
I18nKeyGenerator s corresponding to the root object of the given object. |
protected String |
keyify(String... parts)
Makes up a key from the given parts.
|
protected abstract void |
keysFor(List<String> keys,
T object,
AnnotatedElement el) |
String[] |
keysFor(String undecoratedResult,
T object,
AnnotatedElement el)
Default implementation for
keysFor(String, Object, java.lang.reflect.AnnotatedElement) , which sets
the undecoratedResult value if it is not null, and delegates to keysFor(java.util.List, Object, java.lang.reflect.AnnotatedElement) . |
String |
messageBundleNameFor(T object)
If
|
protected String |
resolveMessageBundleNameUpwards(Object object)
Protected only to be able to test - ancestors should NOT override this method, unless they have very good reason to do this.
|
public String[] keysFor(String undecoratedResult, T object, AnnotatedElement el)
keysFor(String, Object, java.lang.reflect.AnnotatedElement)
, which sets
the undecoratedResult value if it is not null, and delegates to keysFor(java.util.List, Object, java.lang.reflect.AnnotatedElement)
.keysFor
in interface I18nKeyGenerator<T>
undecoratedResult
- the value returned by the undecorated underlying method call. It is generally expected
that this value will be part of the returned keys, such that an object with an explicitly configured key or label
will be translated using that value rather than derived keys.el
- the element being translated - typically a Method
instance.public String messageBundleNameFor(T object)
I18nKeyGenerator
messageBundleNameFor
in interface I18nKeyGenerator<T>
protected String resolveMessageBundleNameUpwards(Object object)
protected abstract void keysFor(List<String> keys, T object, AnnotatedElement el)
protected String fieldOrGetterName(AnnotatedElement el)
I18nKeyGenerator#keysFor(String, T, java.lang.reflect.AnnotatedElement)
.protected <P,C> P getParentViaCast(C obj)
I18nParentable
interface
when the object was decorated by I18nizer
.protected <C> List<Object> getAncestors(C obj)
I18nParentable
interface
when the object was decorated by I18nizer
.getParentViaCast(Object)
protected <C> Object getRoot(C obj)
I18nParentable
hierarchy.getParentViaCast(Object)
protected <C> List<I18nKeyGenerator> getAncestorKeyGenerators(C obj)
I18nKeyGenerator
s corresponding to the parent objects of the given object.getAncestors(Object)
protected <C> I18nKeyGenerator getRootKeyGenerator(C obj)
I18nKeyGenerator
s corresponding to the root object of the given object.getRoot(Object)
protected <P> I18nKeyGenerator<P> getKeyGenerator(P obj)
I18nKeyGenerator
s corresponding to the given object.protected void addKey(List<String> keys, String... parts)
keyify(String...)
protected String getIdOrNameForUnknownRoot(Object obj)
getId()
or getName()
on a root object of unknown type. The result is normalized by replacing colon [:] and slash [/] characters with dots [.].
Should the object not have the above methods, null
is returned. Should the methods both return null
or an empty string, null
is returned.
Copyright © 2003–2016 Magnolia International Ltd.. All rights reserved.