1 18 package org.columba.core.scripting.interpreter; 19 20 import java.io.FileNotFoundException ; 21 import java.io.IOException ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 25 import org.columba.core.scripting.model.ColumbaScript; 26 27 import bsh.EvalError; 28 import bsh.Interpreter; 29 30 33 public class BshInterpreter 34 extends ScriptInterpreter 35 { 36 private final static String [] EXTENSIONS = new String []{"bsh", "beanshell"}; 37 38 39 public String getName() 40 { 41 return "Beanshell Interpreter"; 42 } 43 44 public String [] getSupportedExtensions() 45 { 46 return EXTENSIONS; 47 } 48 49 public void execute(ColumbaScript script, Map vars) 50 { 51 55 56 logger.append("Executing bsh: " + script.getPath()); 57 58 Interpreter bsh = new Interpreter(); 59 bsh.setClassLoader(getClass().getClassLoader()); 60 61 try 62 { 63 for (Iterator it = vars.entrySet().iterator(); it.hasNext();) 64 { 65 Map.Entry entry = (Map.Entry ) it.next(); 66 bsh.set(entry.getKey().toString(), entry.getValue()); 67 } 68 69 bsh.source(script.getPath()); 70 } 71 catch (FileNotFoundException ex) 72 { 73 logger.append(String.format("File %s not found", script.getPath()), ex); 74 } 75 catch (IOException ex) 76 { 77 logger.append(String.format("IOException in %s", script.getPath()), ex); 78 } 79 catch (EvalError ex) 80 { 81 logger.append(String.format("Failed to process script %s", script.getPath()), ex); 82 } 83 } 84 85 } 86 | Popular Tags |