info.magnolia.i18nsystem
Class AbstractI18nKeyGenerator<T>

java.lang.Object
  extended by info.magnolia.i18nsystem.AbstractI18nKeyGenerator<T>
Type Parameters:
T - the type of Object this I18nKeyGenerator generates keys for.
All Implemented Interfaces:
I18nKeyGenerator<T>

public abstract class AbstractI18nKeyGenerator<T>
extends Object
implements I18nKeyGenerator<T>

Abstract implementation of 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 Summary
AbstractI18nKeyGenerator()
           
 
Method Summary
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 I18nKeyGenerators 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 I18nKeyGenerators 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 I18nKeyGenerators 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 has a property that can be used to determine the bundle name (i18nBasename), return that.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractI18nKeyGenerator

public AbstractI18nKeyGenerator()
Method Detail

keysFor

public 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).

Specified by:
keysFor in interface I18nKeyGenerator<T>
Parameters:
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.

messageBundleNameFor

public String messageBundleNameFor(T object)
Description copied from interface: I18nKeyGenerator
If has a property that can be used to determine the bundle name (i18nBasename), return that. The keys will be tried with and without it.

Specified by:
messageBundleNameFor in interface I18nKeyGenerator<T>

resolveMessageBundleNameUpwards

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.


keysFor

protected abstract void keysFor(List<String> keys,
                                T object,
                                AnnotatedElement el)

fieldOrGetterName

protected String fieldOrGetterName(AnnotatedElement el)
Returns the name of the field or method passed to I18nKeyGenerator#keysFor(String, T, java.lang.reflect.AnnotatedElement).


getParentViaCast

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.


getAncestors

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.

See Also:
getParentViaCast(Object)

getRoot

protected <C> Object getRoot(C obj)
Returns the root object that of the I18nParentable hierarchy.

See Also:
getParentViaCast(Object)

getAncestorKeyGenerators

protected <C> List<I18nKeyGenerator> getAncestorKeyGenerators(C obj)
Returns the I18nKeyGenerators corresponding to the parent objects of the given object.

See Also:
getAncestors(Object)

getRootKeyGenerator

protected <C> I18nKeyGenerator getRootKeyGenerator(C obj)
Returns the I18nKeyGenerators corresponding to the root object of the given object.

See Also:
getRoot(Object)

getKeyGenerator

protected <P> I18nKeyGenerator<P> getKeyGenerator(P obj)
Returns the I18nKeyGenerators corresponding to the given object.


addKey

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.

See Also:
keyify(String...)

keyify

protected String keyify(String... parts)
Makes up a key from the given parts.


getIdOrNameForUnknownRoot

protected String getIdOrNameForUnknownRoot(Object obj)
Will try to call either 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-2014 Magnolia International Ltd.. All Rights Reserved.