1 10 package org.nanocontainer.script.jython; 11 12 import java.io.IOException ; 13 import java.io.Reader ; 14 import java.net.URL ; 15 16 import org.nanocontainer.script.NanoContainerMarkupException; 17 import org.nanocontainer.script.ScriptedContainerBuilder; 18 import org.picocontainer.PicoContainer; 19 import org.python.util.PythonInterpreter; 20 21 35 public class JythonContainerBuilder extends ScriptedContainerBuilder { 36 37 public JythonContainerBuilder(Reader script, ClassLoader classLoader) { 38 super(script, classLoader); 39 } 40 41 public JythonContainerBuilder(URL script, ClassLoader classLoader) { 42 super(script, classLoader); 43 } 44 45 protected PicoContainer createContainerFromScript(PicoContainer parentContainer, Object assemblyScope) { 46 try { 47 PythonInterpreter interpreter = new PythonInterpreter(); 48 interpreter.exec("from org.picocontainer.defaults import *"); 49 interpreter.exec("from org.nanocontainer import *"); 50 interpreter.exec("from org.nanocontainer.reflection import *"); 51 interpreter.exec("from java.net import *"); 52 interpreter.set("parent", parentContainer); 53 interpreter.set("assemblyScope", assemblyScope); 54 interpreter.execfile(getScriptInputStream(), "nanocontainer.py"); 55 return (PicoContainer) interpreter.get("pico", PicoContainer.class); 56 } catch (IOException e) { 57 throw new NanoContainerMarkupException(e); 58 } 59 } 60 } 61 | Popular Tags |