Package bsh

Examples of bsh.Interpreter


public class BeanShellHelloWorld {

  public static void main(String[] args) throws FileNotFoundException, IOException, EvalError {
   
    JButton button = new JButton("HelloWorld");
        button.addActionListener((ActionListener)new Interpreter().source("actionHandler.bsh") );

        JFrame f = new JFrame();
        f.setTitle("BeanShell Test");
        f.setSize(200, 100);
        f.getContentPane().add( button );
View Full Code Here


   
    mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());

    JConsole bshConsole = new JConsole();
    Interpreter interpreter = new Interpreter(bshConsole);

    interpreter.println("Hello World");
    Thread t = new Thread(interpreter);
    t.start();
   
    getContentPane().add(new JSplitPane(JSplitPane.VERTICAL_SPLIT, mainPanel, bshConsole));
  }
View Full Code Here

    JSplitPane contentPanel = null;
    if (useConsole) {
      String welcomeMessage = getWelcomeMessage();

      bshConsole = new JConsole();
      Interpreter interpreter = new Interpreter(bshConsole);

      configureInterpreter(interpreter, cacheDelegate);

      interpreter.println(welcomeMessage);
       
      interpreter.setShowResults(!interpreter.getShowResults());// show() in beanShell
      System.setOut(bshConsole.getOut());
      System.setErr(bshConsole.getErr());
      Thread t = new Thread(interpreter);
      t.start();
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

  public Map eval(Map inputMap, Set outputNames) {
    Map outputMap = new HashMap();
   
    try {
      log.debug("script input: "+inputMap);
      Interpreter interpreter = new Interpreter();
      Iterator iter = inputMap.keySet().iterator();
      while (iter.hasNext()) {
        String inputName = (String) iter.next();
        Object inputValue = inputMap.get(inputName);
        if (inputValue!=null) {
          interpreter.set(inputName, inputValue);
        }
      }
      interpreter.eval(expression);
      iter = outputNames.iterator();
      while (iter.hasNext()) {
        String outputName = (String) iter.next();
        Object outputValue = interpreter.get(outputName);
        outputMap.put(outputName, outputValue);
      }
      log.debug("script output: "+outputMap);
    } catch (EvalError e) {
      throw new JbpmException("can't evaluate beanshell script '"+expression+"'", e);
View Full Code Here

              MonitoringPatternBean mpb = list.get(i);
              String object = null;
              ObjectMapper mapper = new ObjectMapper();
              try {
      object = (String) mapper.getObjectFromMessage(message, mpb.getPattern());
      Interpreter inter = new Interpreter();
      inter.eval(BEANSHELL_VARIABLE + " = " + object + mpb.getConditional());
      Boolean b = (Boolean)inter.get(BEANSHELL_VARIABLE);
      if (b.booleanValue()) {
          mvelMonitor.addEvent(message, mpb);
      }
              } catch (ObjectMappingException e1) {
      throw new ActionProcessingException(e1);
View Full Code Here

    public String getBoundaryCommentName() {
        return menuLocation + "#" + name;
    }

    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 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(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(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

            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);
            Iterator altTargetIter = this.altTargets.iterator();
            while (altTargetIter.hasNext()) {
                AltTarget altTarget = (AltTarget) altTargetIter.next();
                Object retVal = bsh.eval(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

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.