    001    /*****************************************************************************
    002     * Copyright (C) NanoContainer Organization. All rights reserved.            *
    003     * ------------------------------------------------------------------------- *
    004     * The software in this package is published under the terms of the BSD      *
    005     * style license a copy of which has been included with this distribution in *
    006     * the LICENSE.txt file.                                                     *
    007     *                                                                           *
    008     *                                                                           *
    009     *****************************************************************************/
    010
    011    package org.nanocontainer.webcontainer.groovy;
    012
    013    import org.picocontainer.MutablePicoContainer;
    014    import org.nanocontainer.webcontainer.PicoJettyServer;
    015    import org.nanocontainer.script.groovy.buildernodes.AbstractBuilderNode;
    016    import org.nanocontainer.NanoContainer;
    017
    018    import java.util.Map;
    019
    020    public class WebContainerBuilder extends AbstractBuilderNode {
    021
    022
    023        public WebContainerBuilder() {
    024            super("webContainer");
    025        }
    026
    027        public Object createNewNode(Object current, Map map) {
    028            int port =0;
    029            if (map.containsKey("port")) {
    030                port = ((Integer) map.remove("port")).intValue();
    031            }
    032            String host;
    033            if (map.containsKey("host")) {
    034                host = (String) map.remove("host");
    035            } else {
    036                host = "localhost";
    037            }
    038
    039            NanoContainer parentNano = (NanoContainer) current;
    040            MutablePicoContainer parentContainer = parentNano.getPico();
    041
    042            if (port != 0) {
    043                PicoJettyServer server = new PicoJettyServer(host, port, parentContainer);
    044                parentContainer.addChildContainer(server);
    045                return new ServerBuilder(server, parentContainer);
    046            } else {
    047                PicoJettyServer server = new PicoJettyServer(parentContainer);
    048                parentContainer.addChildContainer(server);
    049                return new ServerBuilder(server, parentContainer);
    050            }
    051        }
    052
    053
    054    }
    055
    056