com.dottydingo.hyperion.service.translation.DefaultAuditingTranslator Maven / Gradle / Ivy
package com.dottydingo.hyperion.service.translation;
import com.dottydingo.hyperion.api.AuditableApiObject;
import com.dottydingo.hyperion.service.model.AuditablePersistentObject;
import net.sf.cglib.reflect.FastClass;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
/**
*/
public class DefaultAuditingTranslator extends AuditingTranslator
{
private FastClass clientClass;
private FastClass persistentClass;
private List fieldMappers = new ArrayList();
public DefaultAuditingTranslator(Class clientClass, Class persistentClass)
{
this.clientClass = FastClass.create(clientClass);
this.persistentClass = FastClass.create(persistentClass);
}
public void setFieldMappers(List fieldMappers)
{
this.fieldMappers = fieldMappers;
}
protected C createClientInstance()
{
try
{
return (C) clientClass.newInstance();
}
catch (InvocationTargetException e)
{
throw new RuntimeException(e);
}
}
protected P createPersistentInstance()
{
try
{
return (P) persistentClass.newInstance();
}
catch (InvocationTargetException e)
{
throw new RuntimeException(e);
}
}
@Override
protected List getCustomFieldMappers()
{
List mappers = new ArrayList();
mappers.addAll(super.getCustomFieldMappers());
mappers.addAll(fieldMappers);
return mappers;
}
}