Search in sources :

Example 1 with CompiledScript

use of net.sourceforge.processdash.data.compiler.CompiledScript in project processdash by dtuma.

the class Nvl method call.

/** Perform a procedure call.
     *
     * This method <b>must</b> be thread-safe.
     */
public Object call(List arguments, ExpressionContext context) {
    ListStack stack = null;
    for (Iterator iter = arguments.iterator(); iter.hasNext(); ) {
        Object arg = iter.next();
        if (arg instanceof CompiledScript) {
            try {
                CompiledScript script = (CompiledScript) arg;
                if (stack == null)
                    stack = new ListStack();
                else
                    stack.clear();
                script.run(stack, context);
                arg = stack.pop();
            } catch (Exception e) {
            }
        }
        if (arg instanceof SimpleData && !isBadValue((SimpleData) arg))
            return arg;
    }
    return null;
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) ListStack(net.sourceforge.processdash.data.compiler.ListStack) Iterator(java.util.Iterator) SimpleData(net.sourceforge.processdash.data.SimpleData)

Example 2 with CompiledScript

use of net.sourceforge.processdash.data.compiler.CompiledScript in project processdash by dtuma.

the class RollupAutoData method debugPrint.

private void debugPrint(Map definitions) {
    String loggerName = RollupAutoData.class.getName() + "." + definesRollupID;
    Logger logger = Logger.getLogger(loggerName);
    if (!logger.isLoggable(Level.FINEST))
        return;
    StringBuffer msg = new StringBuffer();
    msg.append("Definitions for ").append(definesRollupID).append(" Rollup ------------------------------\n");
    Iterator i = definitions.entrySet().iterator();
    Map.Entry e;
    while (i.hasNext()) {
        e = (Map.Entry) i.next();
        msg.append("[").append(e.getKey()).append("] = ");
        if (e.getValue() instanceof CompiledScript)
            msg.append(((CompiledScript) e.getValue()).saveString());
        else
            msg.append(e.getValue());
        msg.append("\n");
    }
    msg.append("----End--------------------------------------");
    logger.finest(msg.toString());
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) Iterator(java.util.Iterator) Logger(java.util.logging.Logger) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with CompiledScript

use of net.sourceforge.processdash.data.compiler.CompiledScript in project processdash by dtuma.

the class Eval method call.

/** Perform a procedure call.
     *
     * This method <b>must</b> be thread-safe.
     */
public Object call(List arguments, ExpressionContext context) {
    String expression = asString(getArg(arguments, 0));
    if (expression == null || expression.length() == 0)
        return null;
    String prefix = asString(getArg(arguments, 1));
    CompiledScript script = Compiler.compile(expression);
    try {
        Stack stack = new ListStack();
        if (prefix != null)
            context = new RelativeExpressionContext(context, prefix);
        script.run(stack, context);
        return stack.pop();
    } catch (ExecutionException ee) {
        return null;
    }
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) RelativeExpressionContext(net.sourceforge.processdash.data.compiler.RelativeExpressionContext) ListStack(net.sourceforge.processdash.data.compiler.ListStack) ExecutionException(net.sourceforge.processdash.data.compiler.ExecutionException) Stack(net.sourceforge.processdash.data.compiler.Stack) ListStack(net.sourceforge.processdash.data.compiler.ListStack)

Example 4 with CompiledScript

use of net.sourceforge.processdash.data.compiler.CompiledScript in project processdash by dtuma.

the class Filter method call.

/** Perform a procedure call.
     *
     * This method <b>must</b> be thread-safe.
     */
public Object call(List arguments, ExpressionContext context) {
    CompiledScript script = null;
    try {
        script = (CompiledScript) arguments.get(0);
    } catch (ClassCastException cce) {
    }
    if (script == null)
        return null;
    ListData result = new ListData();
    LocalExpressionContext lContext = new LocalExpressionContext(context);
    ListStack stack = new ListStack();
    Iterator i = collapseLists(arguments, 1).iterator();
    Object item;
    while (i.hasNext()) try {
        lContext.setLocalValue(item = i.next());
        stack.clear();
        script.run(stack, lContext);
        handleItem(result, item, stack.pop());
    } catch (Exception e) {
    }
    return result;
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) LocalExpressionContext(net.sourceforge.processdash.data.compiler.LocalExpressionContext) ListStack(net.sourceforge.processdash.data.compiler.ListStack) Iterator(java.util.Iterator) ListData(net.sourceforge.processdash.data.ListData)

Example 5 with CompiledScript

use of net.sourceforge.processdash.data.compiler.CompiledScript in project processdash by dtuma.

the class Iff method call.

/** Perform a procedure call.
     *
     * This method <b>must</b> be thread-safe.
     */
public Object call(List arguments, ExpressionContext context) {
    if (arguments.size() < 2)
        return null;
    SimpleData test = getArg(arguments, 0);
    Object result = null;
    if (test != null && test.test())
        result = arguments.get(1);
    else if (arguments.size() > 2)
        result = arguments.get(2);
    if (result instanceof CompiledScript) {
        try {
            CompiledScript script = (CompiledScript) result;
            ListStack stack = new ListStack();
            script.run(stack, context);
            result = stack.pop();
        } catch (Exception e) {
        }
    }
    return result;
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) ListStack(net.sourceforge.processdash.data.compiler.ListStack) SimpleData(net.sourceforge.processdash.data.SimpleData)

Aggregations

CompiledScript (net.sourceforge.processdash.data.compiler.CompiledScript)9 Iterator (java.util.Iterator)6 Map (java.util.Map)4 ListStack (net.sourceforge.processdash.data.compiler.ListStack)4 HashMap (java.util.HashMap)3 DoubleData (net.sourceforge.processdash.data.DoubleData)3 SimpleData (net.sourceforge.processdash.data.SimpleData)3 IOException (java.io.IOException)2 MalformedData (net.sourceforge.processdash.data.MalformedData)2 SaveableData (net.sourceforge.processdash.data.SaveableData)2 EscapeString (net.sourceforge.processdash.util.EscapeString)2 URLConnection (java.net.URLConnection)1 Entry (java.util.Map.Entry)1 WeakHashMap (java.util.WeakHashMap)1 Logger (java.util.logging.Logger)1 Pattern (java.util.regex.Pattern)1 ListData (net.sourceforge.processdash.data.ListData)1 ListFunction (net.sourceforge.processdash.data.ListFunction)1 MalformedValueException (net.sourceforge.processdash.data.MalformedValueException)1 ExecutionException (net.sourceforge.processdash.data.compiler.ExecutionException)1