KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > getahead > dwrdemo > cli > SingletonContainer


1 package org.getahead.dwrdemo.cli;
2
3 import javax.servlet.ServletConfig JavaDoc;
4 import javax.servlet.ServletContext JavaDoc;
5
6 import org.directwebremoting.WebContextFactory.WebContextBuilder;
7 import org.directwebremoting.impl.ContainerUtil;
8 import org.directwebremoting.impl.DefaultContainer;
9 import org.directwebremoting.impl.DwrXmlConfigurator;
10 import org.directwebremoting.impl.StartupUtil;
11 import org.directwebremoting.util.FakeServletConfig;
12 import org.directwebremoting.util.FakeServletContext;
13
14 /**
15  * An example of how to setup DWR to run from a command line
16  * @author Joe Walker [joe at getahead dot ltd dot uk]
17  */

18 public class SingletonContainer
19 {
20     /**
21      * @param args The command line arguments
22      * @throws Exception If anything goes wrong
23      */

24     public static void main(String JavaDoc[] args) throws Exception JavaDoc
25     {
26         WebContextBuilder webContextBuilder = null;
27
28         try
29         {
30             ServletContext JavaDoc servletContext = new FakeServletContext();
31             ServletConfig JavaDoc servletConfig = new FakeServletConfig("dwr-test", servletContext);
32
33             // Setup the DWR container
34
DefaultContainer container = ContainerUtil.createDefaultContainer(servletConfig);
35             ContainerUtil.setupDefaultContainer(container, servletConfig);
36
37             webContextBuilder = StartupUtil.initWebContext(servletConfig, servletContext, container);
38             StartupUtil.initServerContext(servletConfig, servletContext, container);
39             ContainerUtil.prepareForWebContextFilter(servletContext, servletConfig, container, webContextBuilder, null);
40
41             ContainerUtil.configureFromSystemDwrXml(container);
42
43             DwrXmlConfigurator local = new DwrXmlConfigurator();
44             local.setClassResourceName("/dwr.xml");
45             local.configure(container);
46
47             ContainerUtil.configureFromInitParams(container, servletConfig);
48
49             ContainerUtil.publishContainer(container, servletConfig);
50             webContextBuilder.set(null, null, servletConfig, servletContext, container);
51
52             // Now we have a fully configured DWR we can use it's services
53
/*
54             Remoter remoter = (Remoter) container.getBean(Remoter.class.getName());
55             String script = remoter.generateInterfaceScript("<ExportedClass>", "<Path>");
56             System.out.println(script);
57             */

58         }
59         finally
60         {
61             if (webContextBuilder != null)
62             {
63                 webContextBuilder.unset();
64             }
65         }
66     }
67 }
68
Popular Tags