
com.venky.swf.db.extensions.BeforeModelSaveExtension Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swf-db Show documentation
Show all versions of swf-db Show documentation
Succinct Web Framework - Db
The newest version!
package com.venky.swf.db.extensions;
import java.lang.reflect.ParameterizedType;
import com.venky.extension.Extension;
import com.venky.extension.Registry;
import com.venky.swf.db.model.Model;
import com.venky.swf.db.model.reflection.ModelReflector;
public abstract class BeforeModelSaveExtension implements Extension{
protected static void registerExtension(BeforeModelSaveExtension instance){
Registry.instance().registerExtension(getModelClass(instance).getSimpleName() +".before.save", instance);
}
protected static void deregisterExtension(BeforeModelSaveExtension instance){
Registry.instance().deregisterExtension(getModelClass(instance).getSimpleName() +".before.save", instance);
}
@SuppressWarnings("unchecked")
protected static Class getModelClass(BeforeModelSaveExtension instance){
ParameterizedType pt = (ParameterizedType)instance.getClass().getGenericSuperclass();
return (Class) pt.getActualTypeArguments()[0];
}
public String getPool(){
return ModelReflector.instance(getModelClass(this)).getPool();
}
@SuppressWarnings("unchecked")
public void invoke(Object... context) {
M model = (M)context[0];
beforeSave(model);
}
public abstract void beforeSave(M model);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy