com.googlecode.objectify.impl.translate.ValueTranslatorFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of objectify Show documentation
Show all versions of objectify Show documentation
The simplest convenient interface to the Google App Engine datastore
package com.googlecode.objectify.impl.translate;
import com.googlecode.objectify.impl.Path;
import com.googlecode.objectify.repackaged.gentyref.GenericTypeReflector;
/**
* Provides a little boilerplate for translators that work on simple atomic types.
*
* @author Jeff Schnitzer
*/
abstract public class ValueTranslatorFactory implements TranslatorFactory
{
/** */
Class pojoType;
/** */
protected ValueTranslatorFactory(Class pojoType) {
this.pojoType = pojoType;
}
@Override
final public Translator
create(TypeKey
tk, CreateContext ctx, Path path) {
if (this.pojoType.isAssignableFrom(GenericTypeReflector.erase(tk.getType()))) {
return createValueTranslator(tk, ctx, path);
} else {
return null;
}
}
/**
* Create a translator, knowing that we have the appropriate type. You don't need to check for type matching.
* @param tk type is guaranteed to erase to something assignable to Class
*/
abstract protected ValueTranslator
createValueTranslator(TypeKey
tk, CreateContext ctx, Path path);
}