Die Ausführung von eva/3 Application Builder Ausdrücken gliedern sich in zwei Teile. Der ExpressionParser analysiert den Ausdruck und erstellt einen Ausführungsplan. Der ExpressionInterpreter erlaubt die Ausführungs des zuvor vom ExpressionParser erstellten Ausführungsplan. Dies erlaubt die mehrfache Ausführung des gleichen Ausdrucks, ohne das für diesen mehrfach ein Ausführungsplan angelegt werden muß. Wird ein Ausdruck häufig ausgeführt, so bietet sich das Wiederverwenden der jeweiligen ExpressionInterpreter Instanz an.
import com.odc.eva3.rt.se.expression.ExpressionInterpreter; import com.odc.eva3.rt.se.expression.ExpressionParser; public class Test { public static void main(String[] args) { try { //create a new ExpressionParser instance with the desired expression statement ExpressionParser parser = new ExpressionParser("=5+6"); //create a new ExpressionInterpreter instance. With the creation of the //new ExpressionInterpreter, the ExpressionParser starts parsing //the expression statement. ExpressionInterpreter interpreter = new ExpressionInterpreter(parser); //executed the expression statement. Setting the first argument to 'true' allows //preserving the parsed expression for another usage. Otherwise, the expression //won't be calculated again and returns the same result any time without making a //difference if values of reffering beans has changed. Object result = interpreter.compute(true); } catch (Exception e) { System.out.println("Expression has failed"); e.printStackTrace(); } } }
Der wohl einfachste und komfortabelste Weg einen Ausdruck auszuführen ist der Einsatz der Methode eval(String expression, boolean cache). Diese Methode bietet bereits ein vorgefertigtes Caching, das mit dem Parameter cache aktiviert werden kann. Ein einmal ersteller Ausführungsplan wird für jede Ausführung des gleiche Ausdrucks wieder verwendet. Hinweis: Der Ausführungsplan wird nur dann wieder verwendet, wenn die Schreibweise des Ausdrucks exakt gleich ist.
import com.odc.eva3.rt.se.expression.VBUtilFunctions; public class Test { public static void main(String[] args) { try { //Execute the desired expression statement and //automatically cache the parsed expression statement. //The already parsed expression statement will be used //again, if exactly the same expression statement is //requested next time. Object result = VBUtilFunctions.eval("=5+7", true); } catch (Exception e) { System.out.println("Expression has failed"); e.printStackTrace(); } } }