com.alogic.ac.loader.acm.ACMFromScript Maven / Gradle / Ivy
package com.alogic.ac.loader.acm;
import com.alogic.ac.AccessControlModel;
import com.alogic.load.Loader;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.Script;
import com.alogic.xscript.doc.XsObject;
import com.alogic.xscript.doc.json.JsonObject;
import com.anysoft.util.*;
import org.w3c.dom.Element;
import java.util.HashMap;
/**
* 从脚本加载ACM
*
* @since 1.6.12.54 [20191219]
*/
public class ACMFromScript extends Loader.Abstract {
/**
* 加载事件脚本
*/
protected Logiclet onLoad = null;
/**
* 对象id
*/
protected String acmObjectId = "$acm-object";
protected String acmId = "$acm-id";
@Override
public void configure(Properties p){
super.configure(p);
acmObjectId = PropertiesConstants.getString(p,"acmObjectId",acmObjectId,true);
acmId = PropertiesConstants.getString(p,"acmId",acmId,true);
}
@Override
public void configure(Element e, Properties p) {
Properties props = new XmlElementProperties(e,p);
Element onLoadElem = XmlTools.getFirstElementByPath(e, "on-load");
if (onLoadElem != null){
onLoad = Script.create(onLoadElem, props);
}
configure(props);
}
@Override
public AccessControlModel load(String id, boolean cacheAllowed) {
AccessControlModel found = null;
if (onLoad != null){
LogicletContext logicletContext = new LogicletContext(Settings.get());
try {
XsObject doc = new JsonObject("root",new HashMap());
logicletContext.SetValue(acmId,id);
onLoad.execute(doc,doc, logicletContext, null);
found = logicletContext.getObject(acmObjectId);
}finally{
logicletContext.removeObject(acmObjectId);
}
}
return found;
}
}