Package bsh

Examples of bsh.Interpreter


        code=new String(buf);

        // create interpreter just-in-time
        if(interpreter == null) {
            interpreter=new Interpreter();

                if(log.isInfoEnabled()) log.info("beanshell interpreter was created");
            try {
                interpreter.set("bsh_prot", this);
View Full Code Here


  public Map<String, Object> eval(Map<String, Object> inputMap, Set<String> outputNames) {
    Map<String, Object> outputMap = new HashMap<String, Object>();

    try {
      log.debug("script input: " + inputMap);
      Interpreter interpreter = new Interpreter();
      for (Map.Entry<String, Object> entry : inputMap.entrySet()) {
        String inputName = entry.getKey();
        Object inputValue = entry.getValue();
        interpreter.set(inputName, inputValue);
      }
      interpreter.eval(expression);
      for (String outputName : outputNames) {
        Object outputValue = interpreter.get(outputName);
        outputMap.put(outputName, outputValue);
      }
      log.debug("script output: " + outputMap);
    }
    catch (ParseException e) {
View Full Code Here

        public EvaluationResult evaluate(EvaluationContext context, Message message)
                throws EvaluationException
        {
            try
            {
                Interpreter _interpreter = new Interpreter();

                // TODO import useful stuff
                // predefine useful functions?
                _interpreter.eval("import org.omg.CORBA.*;");

                _interpreter.set("event", message.toAny());
                _interpreter.set("date", new Date());
                _interpreter.set("constraint", constraint_);
                Object _result = _interpreter.eval(constraint_);

                if (_result == null)
                {
                    return EvaluationResult.BOOL_FALSE;
                }
View Full Code Here

    protected Object executeBeanShellScript(String beanShellScript, Map context) throws EvalError {
        // Ensure there is something to execute.
        if (beanShellScript == null || beanShellScript.trim().equals("")) return null;

        // Initialize the BeanShell interpreter.
        Interpreter bshInterpreter = (Interpreter) _bshIntepreterThread.get();
        if (bshInterpreter == null) {
            bshInterpreter = new Interpreter();
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            if (loader != null) bshInterpreter.setClassLoader(loader);
            _bshIntepreterThread.set(bshInterpreter);
        }

        // Set context.
        Iterator contextIt = context.keySet().iterator();
        while (contextIt.hasNext()) {
            String contextVar = (String) contextIt.next();
            bshInterpreter.set(contextVar, context.get(contextVar));
        }

        // Launch the BeanShell script.
        return bshInterpreter.eval(beanShellScript);
    }
View Full Code Here

            expanderContext = StringUtil.HtmlEncodingMapWrapper.getHtmlEncodingMapWrapper(context, simpleEncoder);
        }

        try {
            // use the same Interpreter (ie with the same context setup) for all evals
            Interpreter bsh = this.getBshInterpreter(context);
            for (AltTarget altTarget: this.altTargets) {
                Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(altTarget.useWhen));
                boolean condTrue = false;
                // retVal should be a Boolean, if not something weird is up...
                if (retVal instanceof Boolean) {
                    Boolean boolVal = (Boolean) retVal;
                    condTrue = boolVal.booleanValue();
View Full Code Here

    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(StringUtil.convertOperatorSubstitutions(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

        public boolean shouldUse(Map<String, Object> context) {
            boolean shouldUse = true;
            String useWhen = this.getUseWhen(context);
            if (UtilValidate.isNotEmpty(useWhen)) {
                try {
                    Interpreter bsh = (Interpreter) context.get("bshInterpreter");
                    if (bsh == null) {
                        bsh = BshUtil.makeInterpreter(context);
                        context.put("bshInterpreter", bsh);
                    }

                    Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhen));

                    // retVal should be a Boolean, if not something weird is up...
                    if (retVal instanceof Boolean) {
                        Boolean boolVal = (Boolean) retVal;
                        shouldUse = boolVal.booleanValue();
View Full Code Here

        String useWhenStr = this.getUseWhen(context);
        if (UtilValidate.isEmpty(useWhenStr)) {
            return true;
        } else {
            try {
                Interpreter bsh = this.modelForm.getBshInterpreter(context);
                Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhenStr));
                boolean condTrue = false;
                // retVal should be a Boolean, if not something weird is up...
                if (retVal instanceof Boolean) {
                    Boolean boolVal = (Boolean) retVal;
                    condTrue = boolVal.booleanValue();
View Full Code Here

            });
            editor.requestFocus();

//            BSHOutputAdapter out = new BSHOutputAdapter(output);
            ConsoleInterface bshConsole = new BSHConsole(output);
            interpreter = new Interpreter(bshConsole);
            interpreter.setClassLoader(Thread.currentThread().getContextClassLoader());

            CharvaBshCommandInvoker shell = new CharvaBshCommandInvoker();
            try {
                interpreter.set("interpreter", interpreter);
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.