package foundation.action;
|
|
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.Method;
|
|
import foundation.dao.DataReader;
|
import foundation.dao.DataWriter;
|
import foundation.dao.Domain;
|
import foundation.dao.bizlogic.IActionProvider;
|
import foundation.handler.BaseHandler;
|
import foundation.handler.DataPool;
|
import foundation.handler.ResultPool;
|
import foundation.route.Operation;
|
|
public abstract class ActionProvider extends BaseHandler implements IActionProvider {
|
|
protected ActionContext context;
|
protected IWorkflowRuntime task;
|
protected IWorkStep step;
|
protected Parameters params;
|
protected DataReader dataReader;
|
protected DataWriter dataWriter;
|
|
|
public void exec(ActionContext context, String methodName) throws Exception {
|
Method method = getMethod(methodName);
|
|
if (method == null) {
|
logger.error("method exec error: {} not exists", methodName);
|
return;
|
}
|
|
try {
|
method.invoke(this);
|
}
|
catch (InvocationTargetException e) {
|
e.printStackTrace();
|
Throwable throwable = e.getTargetException();
|
|
if (throwable == null) {
|
throw e;
|
}
|
else {
|
throw (Exception) throwable;
|
}
|
}catch (Exception e) {
|
e.printStackTrace();
|
throw e;
|
}
|
}
|
|
public void test(ActionContext context, String methodName) throws Exception {
|
logger.info("action provider {}.{} test", context.getActionName(), methodName);
|
}
|
|
@Override
|
protected void invokeMethod(Method method, DataPool dataPool, ResultPool resultPool) throws Exception {
|
//1.
|
Operation operation = dataPool.getOperation();
|
DataReader dataReader = new DataReader(operation, dataPool);
|
|
DataWriter dataWriter = new DataWriter(resultPool, dataReader.getDomain());
|
resultPool.setLetterWriter(dataWriter);
|
|
Domain domain = dataReader.getDomain();
|
String dataName = domain != null ? domain.getDataName() : null;
|
String operator = operation.getOperator();
|
|
WorkStep step = new WorkStep(dataName, operation.getOperator());
|
ActionContext context = new ActionContext(dataReader, dataWriter, step);
|
setContext(context);
|
|
//2.
|
exec(context, operator);
|
};
|
|
public void setContext(ActionContext context) {
|
this.context = context;
|
|
this.task = context.getWorkFlow();
|
this.step = context.getStep();
|
this.dataReader = context.getDataReader();
|
this.dataWriter = context.getDataWriter();
|
}
|
|
public void terminateTask(ActionContext context) {
|
IWorkflowRuntime task = context.getWorkFlow();
|
|
if (task != null) {
|
task.terminate();
|
}
|
}
|
}
|