01: /*****************************************************************************
02: * Copyright (C) NanoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: * *
09: *****************************************************************************/package org.nanocontainer.webcontainer.groovy;
10:
11: import org.picocontainer.MutablePicoContainer;
12: import org.nanocontainer.webcontainer.PicoJettyServer;
13: import org.nanocontainer.script.groovy.buildernodes.AbstractBuilderNode;
14: import org.nanocontainer.NanoContainer;
15:
16: import java.util.Map;
17:
18: public class WebContainerBuilder extends AbstractBuilderNode {
19:
20: public WebContainerBuilder() {
21: super ("webContainer");
22: }
23:
24: public Object createNewNode(Object current, Map map) {
25: int port = 0;
26: if (map.containsKey("port")) {
27: port = ((Integer) map.remove("port")).intValue();
28: }
29: String host;
30: if (map.containsKey("host")) {
31: host = (String) map.remove("host");
32: } else {
33: host = "localhost";
34: }
35:
36: NanoContainer parentNano = (NanoContainer) current;
37: MutablePicoContainer parentContainer = parentNano.getPico();
38:
39: PicoJettyServer server = null;
40: if (port != 0) {
41: server = new PicoJettyServer(host, port, parentContainer);
42: } else {
43: server = new PicoJettyServer(parentContainer);
44: }
45: parentContainer.addChildContainer(server);
46: return new ServerBuilder(server, parentContainer);
47: }
48:
49: }
|