All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alogic.xscript.plugins.While Maven / Gradle / Ivy

There is a newer version: 1.6.17
Show newest version
package com.alogic.xscript.plugins;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;

import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsObject;
import com.anysoft.formula.DefaultFunctionHelper;
import com.anysoft.formula.Expression;
import com.anysoft.formula.Parser;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;

/**
 * While语句
 * @author yyduan
 * @since 1.6.12.12 [20181207 duanyy] 
*/ public class While extends Segment{ protected Expression expr = null; public While(String tag, Logiclet p) { super(tag, p); } @Override public void configure(Properties p){ super.configure(p); String formula = PropertiesConstants.getString(p,"expr","",true); if (StringUtils.isNotEmpty(formula)){ Parser parser = new Parser(new DefaultFunctionHelper(null)); expr = parser.parse(formula); } } @Override protected void onExecute(XsObject root,XsObject current, LogicletContext ctx, ExecuteWatcher watcher) { if (expr != null){ try { while (true){ String value = expr.getValue(ctx).toString(); if (!BooleanUtils.toBoolean(value)){ break; } super.onExecute(root, current, ctx, watcher); } }catch (Exception ex){ logger.error(ExceptionUtils.getStackTrace(ex)); } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy