1 package org.nanocontainer.script.bsh; 2 3 import java.io.IOException ; 4 import java.io.Reader ; 5 import java.net.URL ; 6 7 import org.nanocontainer.script.NanoContainerMarkupException; 8 import org.nanocontainer.script.ScriptedContainerBuilder; 9 import org.picocontainer.PicoContainer; 10 11 import bsh.EvalError; 12 import bsh.Interpreter; 13 14 27 public class BeanShellContainerBuilder extends ScriptedContainerBuilder { 28 29 public BeanShellContainerBuilder(Reader script, ClassLoader classLoader) { 30 super(script, classLoader); 31 } 32 33 public BeanShellContainerBuilder(URL script, ClassLoader classLoader) { 34 super(script, classLoader); 35 } 36 37 protected PicoContainer createContainerFromScript(PicoContainer parentContainer, Object assemblyScope) { 38 Interpreter i = new Interpreter(); 39 try { 40 i.set("parent", parentContainer); 41 i.set("assemblyScope", assemblyScope); 42 i.setClassLoader(this.getClassLoader()); 43 i.eval(getScriptReader(), i.getNameSpace(), "nanocontainer.bsh"); 44 return (PicoContainer) i.get("pico"); 45 } catch (EvalError e) { 46 throw new NanoContainerMarkupException(e); 47 } catch (IOException e) { 48 throw new NanoContainerMarkupException(e); 49 } 50 } 51 } 52 | Popular Tags |