001: package org.directwebremoting.util;
002:
003: import javax.servlet.ServletConfig;
004: import javax.servlet.ServletContext;
005:
006: import org.directwebremoting.Container;
007: import org.directwebremoting.WebContextFactory.WebContextBuilder;
008: import org.directwebremoting.extend.ConverterManager;
009: import org.directwebremoting.impl.ContainerUtil;
010: import org.directwebremoting.impl.DwrXmlConfigurator;
011: import org.directwebremoting.impl.StartupUtil;
012:
013: /**
014: * @author Joe Walker [joe at getahead dot ltd dot uk]
015: */
016: public class SingletonContainer {
017: /**
018: *
019: */
020: public SingletonContainer() throws Exception {
021: try {
022: // Setup the DWR container
023: container = ContainerUtil
024: .createAndSetupDefaultContainer(servletConfig);
025:
026: StartupUtil.initContainerBeans(servletConfig,
027: servletContext, container);
028: webContextBuilder = container
029: .getBean(WebContextBuilder.class);
030: ContainerUtil.prepareForWebContextFilter(servletContext,
031: servletConfig, container, webContextBuilder, null);
032: ContainerUtil.publishContainer(container, servletConfig);
033:
034: ContainerUtil.configureFromSystemDwrXml(container);
035: DwrXmlConfigurator local = new DwrXmlConfigurator();
036: local.setClassResourceName("/dwr-test.xml");
037: local.configure(container);
038: ContainerUtil.configureFromInitParams(container,
039: servletConfig);
040: } finally {
041: if (webContextBuilder != null) {
042: webContextBuilder.unset();
043: }
044: }
045: }
046:
047: /**
048: *
049: */
050: public void engageThread() {
051: webContextBuilder.set(null, null, servletConfig,
052: servletContext, container);
053: }
054:
055: /**
056: *
057: */
058: public void disengageThread() {
059: webContextBuilder.unset();
060: }
061:
062: /**
063: *
064: */
065: public ConverterManager getConverterManager() {
066: return container.getBean(ConverterManager.class);
067: }
068:
069: /**
070: * @return the container
071: */
072: public Container getContainer() {
073: return container;
074: }
075:
076: /**
077: * @return the servletConfig
078: */
079: public ServletConfig getServletConfig() {
080: return servletConfig;
081: }
082:
083: /**
084: * @return the servletContext
085: */
086: public ServletContext getServletContext() {
087: return servletContext;
088: }
089:
090: /**
091: * @return the webContextBuilder
092: */
093: public WebContextBuilder getWebContextBuilder() {
094: return webContextBuilder;
095: }
096:
097: private Container container;
098:
099: private WebContextBuilder webContextBuilder;
100:
101: private ServletContext servletContext = new FakeServletContext();
102:
103: private ServletConfig servletConfig = new FakeServletConfig(
104: "dwr-test", servletContext);
105: }
|