    001    package org.nanocontainer.webcontainer.groovy.adapters;
    002
    003    import org.nanocontainer.webcontainer.PicoContext;
    004    import org.nanocontainer.NanoContainer;
    005    import org.nanocontainer.DefaultNanoContainer;
    006    import org.picocontainer.MutablePicoContainer;
    007    import org.picocontainer.PicoContainer;
    008
    009    import java.util.Map;
    010
    011    import groovy.util.NodeBuilder;
    012
    013    /**
    014     *
    015     * @author Paul Hammant
    016     * @author Mauro Talevi
    017     * @deprecated Use NodeBuilderAdapter
    018     */
    019    public class WaffleAdapter {
    020
    021        private static final String WAFFLE_NODE_BUILDER = "org.codehaus.waffle.groovy.WaffleNodeBuilder";
    022
    023        private final PicoContext context;
    024        private final MutablePicoContainer parentContainer;
    025        private final Map attributes;
    026
    027        public WaffleAdapter(PicoContext context, MutablePicoContainer parentContainer, Map attributes) {
    028            this.context = context;
    029            this.parentContainer = parentContainer;
    030            this.attributes = attributes;
    031        }
    032
    033        public NodeBuilder getNodeBuilder() {
    034            NanoContainer factory = new DefaultNanoContainer();
    035            factory.getPico().registerComponentInstance(PicoContext.class, context);
    036            factory.getPico().registerComponentInstance(PicoContainer.class, parentContainer);
    037            factory.getPico().registerComponentInstance(Map.class, attributes);
    038            try {
    039                factory.registerComponentImplementation("waffleNodeBuilder", WAFFLE_NODE_BUILDER);
    040                return (NodeBuilder) factory.getPico().getComponentInstance("waffleNodeBuilder");
    041            } catch (ClassNotFoundException e) {
    042                throw new org.nanocontainer.script.BuilderClassNotFoundException(WAFFLE_NODE_BUILDER + " class name not found", e);
    043            }
    044        }
    045
    046    }