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.picocontainer.jetty.groovy;
012
013 import org.picocontainer.MutablePicoContainer;
014 import org.picocontainer.script.groovy.nodes.AbstractBuilderNode;
015 import org.picocontainer.jetty.PicoJettyServer;
016
017 import java.util.Map;
018
019 public class WebContainerBuilder extends AbstractBuilderNode {
020
021
022 public WebContainerBuilder() {
023 super("webContainer");
024 }
025
026 public Object createNewNode(Object current, Map map) {
027 int port = 0;
028 if (map.containsKey("port")) {
029 port = (Integer)map.remove("port");
030 }
031 String host;
032 if (map.containsKey("host")) {
033 host = (String) map.remove("host");
034 } else {
035 host = null;
036 }
037 int timeout = 10*1000;
038 if (map.containsKey("timeout")) {
039 timeout = (Integer) map.remove("timeout");
040 }
041
042 MutablePicoContainer parentContainer = (MutablePicoContainer) current;
043
044 PicoJettyServer server;
045 if (port != 0) {
046 server = new PicoJettyServer(host, port, parentContainer, timeout);
047 } else {
048 server = new PicoJettyServer(parentContainer);
049 }
050 parentContainer.addChildContainer(server);
051 return new ServerBuilder(server, parentContainer);
052 }
053
054
055 }
056
057