package net.sourceforge.javautil.groovy.cli;
import java.util.LinkedHashMap;
import java.util.Map;
import net.sourceforge.javautil.classloader.boot.EntryPointExceptionHandler;
import net.sourceforge.javautil.classloader.boot.EntryPointType;
import net.sourceforge.javautil.common.io.console.StandardConsole;
import net.sourceforge.javautil.groovy.cli.debug.ExecuteMainCommand;
import net.sourceforge.javautil.groovy.dsl.GroovyDSLContext;
import net.sourceforge.javautil.groovy.dsl.impl.standard.GroovyDSLManagerStandard;
/**
* This will boot up a {@link GroovyCLI} when an exception is caught by the {@link EntryPointType}.
*
* @author elponderador
* @author $Author$
* @version $Id$
*/
public class GroovyCLIExceptionHandler implements EntryPointExceptionHandler {
protected final Map<String, Object> bindings = new LinkedHashMap<String, Object>();
public void bind (String name, Object value) { bindings.put(name, value); }
public void handle(EntryPointType type, Throwable t) {
GroovyDSLContext.setGlobalManager( new GroovyDSLManagerStandard().initialize() );
GroovyCLI cli = new GroovyCLI();
cli.info("Starting GroovyCLI Exception Handler");
cli.getDomain().setVariable("entry", type);
cli.getDomain().setVariable("throwable", t);
for (String name : bindings.keySet()) cli.getDomain().setVariable(name, bindings.get(name));
cli.getSet().add(new ExecuteMainCommand("execute"));
cli.initialize();
cli.run();
}
}