Package org.nanocontainer.script.bsh

Source Code of org.nanocontainer.script.bsh.BeanShellContainerBuilder

package org.nanocontainer.script.bsh;

import java.io.IOException;
import java.io.Reader;
import java.net.URL;

import org.nanocontainer.script.NanoContainerMarkupException;
import org.nanocontainer.script.ScriptedContainerBuilder;
import org.picocontainer.PicoContainer;

import bsh.EvalError;
import bsh.Interpreter;

/**
* {@inheritDoc}
* The script has to assign a "pico" variable with an instance of
* {@link org.picocontainer.PicoContainer}.
* There is an implicit variable named "parent" that may contain a reference to a parent
* container. It is recommended to use this as a constructor argument to the instantiated
* PicoContainer.
*
* @author Aslak Hellesøy
* @author Mauro Talevi
* @version $Revision: 2164 $
*/
public class BeanShellContainerBuilder extends ScriptedContainerBuilder {

    public BeanShellContainerBuilder(Reader script, ClassLoader classLoader) {
        super(script, classLoader);
    }

    public BeanShellContainerBuilder(URL script, ClassLoader classLoader) {
        super(script, classLoader);
    }
   
    protected PicoContainer createContainerFromScript(PicoContainer parentContainer, Object assemblyScope) {
        Interpreter i = new Interpreter();
        try {
            i.set("parent", parentContainer);
            i.set("assemblyScope", assemblyScope);
            i.eval(getScriptReader(), i.getNameSpace(), "nanocontainer.bsh");
            return (PicoContainer) i.get("pico");
        } catch (EvalError e) {
            throw new NanoContainerMarkupException(e);
        } catch (IOException e) {
            throw new NanoContainerMarkupException(e);
        }
    }
}
TOP

Related Classes of org.nanocontainer.script.bsh.BeanShellContainerBuilder

TOP
Copyright © 2018 www.massapi.com. 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.