com.alogic.xscript.plugins.Throw Maven / Gradle / Ivy
package com.alogic.xscript.plugins;
import org.apache.commons.lang3.StringUtils;
import com.alogic.xscript.AbstractLogiclet;
import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsObject;
import com.anysoft.util.BaseException;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
/**
* Throw
*
*
* Throw is used to throw an exception.
*
* @author duanyy
*
* @version 1.6.8.14 [20170509 duanyy]
* - 增加xscript的中间文档模型,以便支持多种报文协议
*
*/
public class Throw extends AbstractLogiclet{
protected String $id = STMT_EXCEPTION;
protected String $msg;
public Throw(String tag, Logiclet p) {
super(tag, p);
}
@Override
public void configure(Properties p) {
super.configure(p);
$id = PropertiesConstants.getRaw(p,"id",$id);
$msg = PropertiesConstants.getRaw(p,"msg","");
}
@Override
protected void onExecute(XsObject root,XsObject current, LogicletContext ctx, ExecuteWatcher watcher) {
String id = PropertiesConstants.transform(ctx, $id, "");
if (StringUtils.isNotEmpty(id)){
throw new BaseException(id,ctx.transform($msg));
}
}
}