    001    package org.nanocontainer.webcontainer.groovy.adapters;
    002
    003    import org.nanocontainer.webcontainer.PicoContextHandler;
    004    import org.nanocontainer.NanoContainer;
    005    import org.nanocontainer.DefaultNanoContainer;
    006    import org.picocontainer.MutablePicoContainer;
    007
    008    import java.util.Map;
    009
    010    import groovy.util.NodeBuilder;
    011
    012    public class WaffleAdapter {
    013        private final PicoContextHandler context;
    014        private final MutablePicoContainer parentContainer;
    015
    016        public WaffleAdapter(PicoContextHandler context, MutablePicoContainer parentContainer, Map attributes) {
    017            this.context = context;
    018            this.parentContainer = parentContainer;
    019        }
    020        public NodeBuilder getNodeBuilder() {
    021            String className = "com.thoughtworks.waffle.groovy.WaffleBuilder";
    022            NanoContainer factory = new DefaultNanoContainer();
    023            factory.getPico().registerComponentInstance(PicoContextHandler.class, context);
    024            factory.getPico().registerComponentInstance(MutablePicoContainer.class, parentContainer);
    025            try {
    026                factory.registerComponentImplementation("wb", className);
    027                return (NodeBuilder) factory.getPico().getComponentInstance("wb");
    028            } catch (ClassNotFoundException e) {
    029                throw new org.nanocontainer.script.BuilderClassNotFoundException(className + " class name not found", e);
    030            }
    031
    032        }
    033
    034    }