package foundation.icall;
|
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
|
import foundation.action.ActionBucket;
|
import foundation.action.ActionContext;
|
import foundation.action.ActionMeta;
|
import foundation.action.ActionProvider;
|
import foundation.dao.DataPackage;
|
import foundation.dao.bizlogic.IActionProvider;
|
import foundation.data.mapping.Mappings;
|
import foundation.data.mapping.MappingsRuntime;
|
import foundation.icall.callout.CallMethod;
|
import foundation.icall.callout.Fields;
|
import foundation.icall.callout.IRemoteSource;
|
import foundation.icall.callout.RemoteDBCallProvider;
|
import foundation.icall.callout.RemoteSourceBucket;
|
import foundation.icall.log.ICallLogger;
|
import foundation.util.Util;
|
|
|
public class ICall {
|
|
protected static Logger logger;
|
private static RemoteSourceBucket sourceBucket;
|
|
private ICallMeta meta;
|
private IRemoteSource remoteSource;
|
private Class<?> actionClass;
|
private ICallDirection direction;
|
|
|
static {
|
logger = LogManager.getLogger(ICall.class);
|
}
|
|
public ICall(ICallMeta meta) {
|
this.meta = meta;
|
this.direction = ICallDirection.Unknown;
|
|
init();
|
}
|
|
|
public static ICall getInstance(String name) {
|
ICallBucket bucket = ICallBucket.getInstance();
|
return bucket.getOne(name);
|
}
|
|
private void init() {
|
//1. remote source
|
String sourceName = meta.getSourceName();
|
sourceBucket = RemoteSourceBucket.getInstance();
|
remoteSource = sourceBucket.getOne(sourceName);
|
direction = remoteSource.getDirection();
|
}
|
|
public void sendRemoteServerCall(ActionContext context, OutboundResult result) throws Exception {
|
String actionName = meta.getActionName();
|
if (Util.isEmpty(actionName)) {
|
logger.error("iCall send remote server call error, empty action");
|
return;
|
}
|
|
//1. 创建 action provider
|
ActionBucket actionBucket = ActionBucket.getInstance();
|
ActionMeta actionMeta = actionBucket.get(actionName);
|
IActionProvider provider = actionMeta.createProvider();
|
|
//2. 创建 context
|
RemoteContext remoteContext = new RemoteContext(this);
|
ActionContext newContext = context.newInstance();
|
newContext.addContext(remoteContext);
|
|
if (provider instanceof ActionProvider) {
|
ActionProvider actionProvider = (ActionProvider)provider;
|
actionProvider.setContext(newContext);
|
}
|
|
//3. 运行
|
String method = actionMeta.getMethodName();
|
provider.exec(newContext, method);
|
|
}
|
|
public void sendRemoteDBCall(ActionContext context, OutboundResult result) throws Exception {
|
//1. 创建 action provider
|
String actionName = meta.getActionName();
|
IActionProvider provider = null; ActionMeta actionMeta = null;
|
|
if (!Util.isEmpty(actionName)) {
|
ActionBucket actionBucket = ActionBucket.getInstance();
|
actionMeta = actionBucket.get(actionName);
|
provider = actionMeta.createProvider();
|
}
|
else {
|
provider = new RemoteDBCallProvider();
|
}
|
|
//2. 创建 context
|
RemoteContext remoteContext = new RemoteContext(this);
|
remoteContext.setOutboundResult(result);
|
ActionContext newContext = context.newInstance();
|
newContext.addContext(remoteContext);
|
|
if (provider instanceof ActionProvider) {
|
ActionProvider actionProvider = (ActionProvider)provider;
|
actionProvider.setContext(newContext);
|
}
|
|
//3. 运行
|
if (actionMeta != null) {
|
String method = actionMeta.getMethodName();
|
provider.exec(newContext, method);
|
}
|
else {
|
((RemoteDBCallProvider)provider).doExec(newContext);
|
}
|
|
ICallLogger.endAction(remoteContext.getLogRecord(), remoteContext.getResponse());
|
}
|
|
@SuppressWarnings("unchecked")
|
public <T> T getAction() throws InstantiationException, IllegalAccessException {
|
|
if (actionClass == null) {
|
return null;
|
}
|
|
Object obj = actionClass.newInstance();
|
return (T)obj;
|
}
|
|
@SuppressWarnings("unchecked")
|
public <T extends IRemoteSource> T remoteSource() {
|
return (T)remoteSource;
|
}
|
|
public String getId() {
|
return meta.getId();
|
}
|
|
public ICallMeta getMeta() {
|
return meta;
|
}
|
|
public String getURL() {
|
return meta.getURL();
|
}
|
|
public String getRemoteFilter() {
|
return meta.getRemoteFilter();
|
}
|
|
public String getDataName() {
|
return meta.getDataName();
|
}
|
|
public String getName() {
|
return meta.getName();
|
}
|
|
public ICallDirection getType() {
|
return direction;
|
}
|
|
public Mappings getMappings() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
public MappingsRuntime getMappingsRuntime(DataPackage dataPackage) {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
public CallMethod getCallMethod() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
public IRemoteSource getRemoteSource() {
|
return remoteSource;
|
}
|
|
public String getSourceName() {
|
return meta.getSourceName();
|
}
|
|
public boolean isPermitEmptyStamp() {
|
return meta.isPermitEmptyStamp();
|
}
|
|
public String getHistoryTableName() {
|
return meta.getHistoryTableName();
|
}
|
|
public Fields getIdFields() {
|
return meta.getIdFields();
|
}
|
|
public String getStampField() {
|
return meta.getStampField();
|
}
|
|
public String getOrderByField() {
|
return meta.getOrderByField();
|
}
|
|
public String getIOTaskName() {
|
return meta.getIOTaskName();
|
}
|
|
public boolean isPageActive() {
|
return meta.isPageActive();
|
}
|
|
public String getRoute() {
|
return meta.getRoute();
|
}
|
|
public String getMonitorId() {
|
return meta.getMonitorId();
|
}
|
|
public String getTitle() {
|
return meta.getTitle();
|
}
|
|
}
|