Package bsh

Examples of bsh.Interpreter


    public void resetBshInterpreter(Map<String, Object> context) {
        context.remove("bshInterpreter");
    }

    public Interpreter getBshInterpreter(Map<String, Object> context) throws EvalError {
        Interpreter bsh = (Interpreter) context.get("bshInterpreter");
        if (bsh == null) {
            bsh = BshUtil.makeInterpreter(context);
            context.put("bshInterpreter", bsh);
        }
        return bsh;
View Full Code Here


     */
    public String getStyleAltRowStyle(Map<String, Object> context) {
        String styles = "";
        try {
            // use the same Interpreter (ie with the same context setup) for all evals
            Interpreter bsh = this.getBshInterpreter(context);
            for (AltRowStyle altRowStyle : this.altRowStyles) {
                Object retVal = bsh.eval(altRowStyle.useWhen);
                // retVal should be a Boolean, if not something weird is up...
                if (retVal instanceof Boolean) {
                    Boolean boolVal = (Boolean) retVal;
                    if (boolVal.booleanValue()) {
                        styles += altRowStyle.style;
View Full Code Here

        // used by our BSH script to see if the current deployment's list of object names contains our object name
        String testScriptObjectNameVariable = "ourObjectName";
        String testScriptContainsOurObjectName = "sdi.mbeans.contains(" + testScriptObjectNameVariable + ")";

        // find out which deployment was responsible for deploying our MBean (identified by objectName)
        Interpreter i = new Interpreter();
        for (Iterator it = deployed.iterator(); it.hasNext() && (retDescriptorFile == null);) {
            Object sdi = it.next();
            try {
                i.set("sdi", sdi);

                // this is the deployment descriptor file that we are currently examining;
                // this is what will be returned if the MBean was configured in this file.
                String file = i.eval("sdi.watch").toString();

                if (file.startsWith("file:/")) {
                    file = file.substring(5);
                }

                // get the collection of MBeans that were deployed from the current deployment and
                // see if our MBean object name is among them
                i.set(testScriptObjectNameVariable, ourObjectName);
                Boolean b = (Boolean) i.eval(testScriptContainsOurObjectName);
                if (b) {
                    retDescriptorFile = new File(file); // found it! this is the file where the MBean was configured/deployed
                    break;
                }
            } catch (EvalError evalError) {
View Full Code Here

    return result;
  }
 
  private static Interpreter getInterpreter() {
    if(null == s_interpreter) {
      s_interpreter= new Interpreter();
    }
   
    return s_interpreter;
  }
View Full Code Here

  }
 
  private boolean includeMethodFromExpression(ITestNGMethod tm,  boolean isTestMethod) {
    boolean result = false;

    Interpreter interpreter= getInterpreter();
    try {
      Map<String, String> groups = new HashMap<String, String>();
      for (String group : tm.getGroups()) {
        groups.put(group, group);
      }
      setContext(interpreter, tm.getMethod(), groups, tm);
      Object evalResult = interpreter.eval(m_expression);
      result = ((Boolean) evalResult).booleanValue();
    }
    catch (EvalError evalError) {
      Utils.log("bsh.Interpreter", 2, "Cannot evaluate expression:" + m_expression + ":" + evalError.getMessage());
    }
View Full Code Here

                throw new ContainerException("Invalid telnet-port defined in container configuration; not a valid int");
            }
        }

        // create the interpreter
        bsh = new Interpreter();

        // configure the interpreter
        if (bsh != null) {
            try {
                bsh.set(name, this);
View Full Code Here

            Debug.logVerbose("Evaluating -- " + expression, module);
        if (Debug.verboseOn())
            Debug.logVerbose("Using Context -- " + context, module);

        try {
            Interpreter bsh = makeInterpreter(context);
            // evaluate the expression
            o = bsh.eval(expression);
            if (Debug.verboseOn())
                Debug.logVerbose("Evaluated to -- " + o, module);

            // read back the context info
            NameSpace ns = bsh.getNameSpace();
            String[] varNames = ns.getVariableNames();
            for (String varName: varNames) {
                context.put(varName, bsh.get(varName));
            }
        } catch (EvalError e) {
            Debug.logError(e, "BSH Evaluation error.", module);
            throw e;
        }
View Full Code Here

        }
        return o;
    }

    public static Interpreter makeInterpreter(Map<String, ? extends Object> context) throws EvalError {
        Interpreter bsh = getMasterInterpreter(null);
        // Set the context for the condition
        if (context != null) {
            for (Map.Entry<String, ? extends Object> entry: context.entrySet()) {
                bsh.set(entry.getKey(), entry.getValue());
            }

            // include the context itself in for easier access in the scripts
            bsh.set("context", context);
        }

        return bsh;
    }
View Full Code Here

                }
            }
        }

        if (master != null) {
            Interpreter interpreter = new Interpreter(new StringReader(""), System.out, System.err,
                    false, new NameSpace(master, "global"), null, null);
            return interpreter;
        } else {
            Interpreter interpreter = new Interpreter();
            interpreter.setClassLoader(classLoader);
            return interpreter;
        }
    }
View Full Code Here

        }
    }

    public static Object runBshAtLocation(String location, Map<String, ? extends Object> context) throws GeneralException {
        try {
            Interpreter interpreter = makeInterpreter(context);

            Interpreter.ParsedScript script = null;
            script = parsedScripts.get(location);
            if (script == null) {
                synchronized (OfbizBshBsfEngine.class) {
                    script = parsedScripts.get(location);
                    if (script == null) {
                        URL scriptUrl = FlexibleLocation.resolveLocation(location);
                        if (scriptUrl == null) {
                            throw new GeneralException("Could not find bsh script at [" + location + "]");
                        }
                        Reader scriptReader = new InputStreamReader(scriptUrl.openStream());
                        script = interpreter.parseScript(location, scriptReader);
                        if (Debug.verboseOn()) Debug.logVerbose("Caching BSH script at: " + location, module);
                        parsedScripts.put(location, script);
                    }
                }
            }

            return interpreter.evalParsedScript(script);
        } catch (MalformedURLException e) {
            String errMsg = "Error loading BSH script at [" + location + "]: " + e.toString();
            Debug.logError(e, errMsg, module);
            throw new GeneralException(errMsg, e);
        } catch (ParseException e) {
View Full Code Here

TOP

Related Classes of bsh.Interpreter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.