public Object getComponentInstance(PicoContainer pico)
throws PicoInitializationException, PicoIntrospectionException {
if (instance == null) {
try {
Interpreter i = new Interpreter();
i.set("adapter", this);
i.set("picoContainer", pico);
i.set("componentKey", getComponentKey());
i.set("componentImplementation", getComponentImplementation());
i.set("parameters", parameters != null ? Arrays.asList(parameters) : Collections.EMPTY_LIST);
i.eval("import " + getComponentImplementation().getName() + ";");
String scriptPath = "/" + getComponentImplementation().getName().replace('.', '/') + ".bsh";
// Inside IDEA, this relies on the compilation output path being the same directory as the source path.
// kludge - copy ScriptableDemoBean.bsh to the same location in the test output compile class path.
// the same problem exists for maven, but some custom jelly script will be able to fix that.
URL scriptURL = getComponentImplementation().getResource(scriptPath);
if (scriptURL == null) {
throw new BeanShellScriptInitializationException("Couldn't load script at path " + scriptPath);
}
Reader sourceReader = new InputStreamReader(scriptURL.openStream());
i.eval(sourceReader, i.getNameSpace(), scriptURL.toExternalForm());
instance = i.get("instance");
if (instance == null) {
throw new BeanShellScriptInitializationException("The 'instance' variable was not instantiated");
}
} catch (EvalError e) {
throw new BeanShellScriptInitializationException(e);