KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > script > bsh > BeanShellContainerBuilder


1 package org.nanocontainer.script.bsh;
2
3 import java.io.IOException JavaDoc;
4 import java.io.Reader JavaDoc;
5 import java.net.URL JavaDoc;
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 /**
15  * {@inheritDoc}
16  * The script has to assign a "pico" variable with an instance of
17  * {@link org.picocontainer.PicoContainer}.
18  * There is an implicit variable named "parent" that may contain a reference to a parent
19  * container. It is recommended to use this as a constructor argument to the instantiated
20  * PicoContainer.
21  *
22  * @author Aslak Hellesøy
23  * @author Michael Rimov
24  * @author Mauro Talevi
25  * @version $Revision: 3144 $
26  */

27 public class BeanShellContainerBuilder extends ScriptedContainerBuilder {
28
29     public BeanShellContainerBuilder(Reader JavaDoc script, ClassLoader JavaDoc classLoader) {
30         super(script, classLoader);
31     }
32
33     public BeanShellContainerBuilder(URL JavaDoc script, ClassLoader JavaDoc classLoader) {
34         super(script, classLoader);
35     }
36
37     protected PicoContainer createContainerFromScript(PicoContainer parentContainer, Object JavaDoc 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 JavaDoc e) {
48             throw new NanoContainerMarkupException(e);
49         }
50     }
51 }
52
Popular Tags