org.directwebremoting.impl
Class StartupUtil

java.lang.Object
  extended by org.directwebremoting.impl.StartupUtil

public class StartupUtil
extends java.lang.Object

Some utilities to help get DWR up and running

Author:
Joe Walker [joe at getahead dot ltd dot uk]

Field Summary
static java.lang.String ATTRIBUTE_CONTAINER_LIST
          The name under which we publish all Containers.
static java.lang.String INIT_CONFIG
          Init parameter: Set a dwr.xml config file.
static java.lang.String INIT_CUSTOM_CONFIGURATOR
          Init parameter: If you wish to use a custom configurator, place its class name here
static java.lang.String INIT_LOGLEVEL
          Init parameter: If we are doing Servlet.log logging, to what level?
static java.lang.String INIT_SKIP_DEFAULT
          Init parameter: Skip reading the default config file if none are specified.
 
Constructor Summary
StartupUtil()
           
 
Method Summary
static void configure(Container container, java.util.List<Configurator> configurators)
          Allow all the configurators to have a go at the container in turn
static void configureContainerFully(Container container, javax.servlet.ServletConfig servletConfig)
          Run all the default configuration options on a Container
static void configureFromAnnotations(Container container)
          Configure using Annotations.
static void configureFromDefaultDwrXml(Container container, javax.servlet.ServletConfig servletConfig)
          Configure using the users dwr.xml that sits next in WEB-INF
static boolean configureFromInitParams(Container container, javax.servlet.ServletConfig servletConfig)
          Add configurators from init params to the end of the list of configurators.
static void configureFromSystemDwrXml(Container container)
          Configure using the system dwr.xml from within the JAR file.
static Container createAndSetupDefaultContainer(javax.servlet.ServletConfig servletConfig)
          A combination of createDefaultContainer(ServletConfig) and setupDefaultContainer(DefaultContainer, ServletConfig).
static DefaultContainer createDefaultContainer(javax.servlet.ServletConfig servletConfig)
          Create a DefaultContainer, allowing users to upgrade to a child of DefaultContainer using an ServletConfig init parameter of org.directwebremoting.Container.
static void createPathMapping(DefaultContainer container, java.lang.String url, java.lang.Class<? extends Handler> handler)
          Creates entries in the Container so 1 lookup is possible.
static void createPathMapping(DefaultContainer container, java.lang.String url, java.lang.Class<? extends Handler> handler, java.lang.String propertyName)
          Creates entries in the Container so 2 lookups are possible.
static void debugConfig(Container container)
          Create a bunch of debug information about a container
static java.util.List<Container> getAllPublishedContainers(javax.servlet.ServletContext servletContext)
          Get a list of all known Containers for the given ServletContext
static java.util.Collection<ServerContext> getAllServerContexts()
          If there is only once instance of DWR defined in a ServletContext then we can get at it using this method.
static ServerContext getSingletonServerContext()
          If there is only once instance of DWR defined in a ServletContext then we can get at it using this method.
static void logStartup(java.lang.String name, javax.servlet.ServletConfig config)
          Some logging so we have a good clue what we are working with.
static void outOfContainerDestroy(Container container)
          Clean up the current thread when outOfContainerInit() has been called.
static Container outOfContainerInit()
          A way to setup DWR outside of any Containers.
static void resolveListenerImplementations(DefaultContainer container, javax.servlet.ServletConfig servletConfig)
          We need to add all the ScriptSessionListeners to the ScriptSessionManager.
static void resolveMultipleImplementations(DefaultContainer container, javax.servlet.ServletConfig servletConfig)
          We need to decide which ContainerAbstraction should be the default for this Container, also we should prepare the default ServerLoadMonitor.
static void setupDefaultContainer(DefaultContainer container, javax.servlet.ServletConfig servletConfig)
          Setup a DefaultContainer.
static void setupDefaults(DefaultContainer container)
          Take a DefaultContainer and setup the default beans
static void setupFromServletConfig(DefaultContainer container, javax.servlet.ServletConfig servletConfig)
          Take a DefaultContainer and setup the default beans
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INIT_CONFIG

public static final java.lang.String INIT_CONFIG
Init parameter: Set a dwr.xml config file. This is only a prefix since we might have more than 1 config file.

See Also:
Constant Field Values

INIT_SKIP_DEFAULT

public static final java.lang.String INIT_SKIP_DEFAULT
Init parameter: Skip reading the default config file if none are specified.

See Also:
Constant Field Values

INIT_LOGLEVEL

public static final java.lang.String INIT_LOGLEVEL
Init parameter: If we are doing Servlet.log logging, to what level?

See Also:
Constant Field Values

INIT_CUSTOM_CONFIGURATOR

public static final java.lang.String INIT_CUSTOM_CONFIGURATOR
Init parameter: If you wish to use a custom configurator, place its class name here

See Also:
Constant Field Values

ATTRIBUTE_CONTAINER_LIST

public static final java.lang.String ATTRIBUTE_CONTAINER_LIST
The name under which we publish all Containers.

See Also:
Constant Field Values
Constructor Detail

StartupUtil

public StartupUtil()
Method Detail

outOfContainerInit

public static Container outOfContainerInit()
                                    throws ContainerConfigurationException
A way to setup DWR outside of any Containers. This method can also serve as a template for in container code wanting to get DWR setup. Callers of this method should clean up after themselves by calling outOfContainerDestroy(Container)

Returns:
A new initialized container.
Throws:
ContainerConfigurationException - If we can't use a bean

outOfContainerDestroy

public static void outOfContainerDestroy(Container container)
Clean up the current thread when outOfContainerInit() has been called.

Parameters:
container - The container created by outOfContainerInit().

logStartup

public static void logStartup(java.lang.String name,
                              javax.servlet.ServletConfig config)
Some logging so we have a good clue what we are working with.

Parameters:
name - The servlet name (so we can distinguish implementations)
config - The servlet config

createAndSetupDefaultContainer

public static Container createAndSetupDefaultContainer(javax.servlet.ServletConfig servletConfig)
                                                throws ContainerConfigurationException
A combination of createDefaultContainer(ServletConfig) and setupDefaultContainer(DefaultContainer, ServletConfig).

Parameters:
servletConfig - The source of init parameters
Returns:
A setup implementation of DefaultContainer
Throws:
ContainerConfigurationException - If the specified class could not be found or instantiated

createDefaultContainer

public static DefaultContainer createDefaultContainer(javax.servlet.ServletConfig servletConfig)
                                               throws ContainerConfigurationException
Create a DefaultContainer, allowing users to upgrade to a child of DefaultContainer using an ServletConfig init parameter of org.directwebremoting.Container. Note that while the parameter name is the classname of Container, currently the only this can only be used to create children that inherit from DefaultContainer. This restriction may be relaxed in the future. Unlike setupDefaultContainer(DefaultContainer, ServletConfig), this method does not call any setup methods.

Parameters:
servletConfig - The source of init parameters
Returns:
An un'setup' implementation of DefaultContainer
Throws:
ContainerConfigurationException - If the specified class could not be found
See Also:
ServletConfig.getInitParameter(String)

setupDefaultContainer

public static void setupDefaultContainer(DefaultContainer container,
                                         javax.servlet.ServletConfig servletConfig)
                                  throws ContainerConfigurationException
Setup a DefaultContainer. Using createDefaultContainer(ServletConfig) followed by setupFromServletConfig(DefaultContainer, ServletConfig) before calling DefaultContainer.setupFinished().

Parameters:
container - The container to configure
servletConfig - The source of init parameters
Throws:
ContainerConfigurationException - If we can't use a bean

resolveMultipleImplementations

public static void resolveMultipleImplementations(DefaultContainer container,
                                                  javax.servlet.ServletConfig servletConfig)
                                           throws ContainerConfigurationException
We need to decide which ContainerAbstraction should be the default for this Container, also we should prepare the default ServerLoadMonitor.

Parameters:
container - The container to configure
servletConfig - Information about the environment
Throws:
ContainerConfigurationException - If we can't use a bean

resolveListenerImplementations

public static void resolveListenerImplementations(DefaultContainer container,
                                                  javax.servlet.ServletConfig servletConfig)
                                           throws ContainerConfigurationException
We need to add all the ScriptSessionListeners to the ScriptSessionManager.

Parameters:
container - The container to configure
servletConfig - Information about the environment
Throws:
ContainerConfigurationException - If we can't use a bean

setupDefaults

public static void setupDefaults(DefaultContainer container)
                          throws ContainerConfigurationException
Take a DefaultContainer and setup the default beans

Parameters:
container - The container to configure
Throws:
ContainerConfigurationException - If we can't use a bean

createPathMapping

public static void createPathMapping(DefaultContainer container,
                                     java.lang.String url,
                                     java.lang.Class<? extends Handler> handler,
                                     java.lang.String propertyName)
                              throws ContainerConfigurationException
Creates entries in the Container so 2 lookups are possible.

Parameters:
container - The container to create the entries in
url - The URL of the new Handler
handler - The class of Handler
propertyName - The property name (for injection and lookup)
Throws:
ContainerConfigurationException - From DefaultContainer.addParameter(String, Object)

createPathMapping

public static void createPathMapping(DefaultContainer container,
                                     java.lang.String url,
                                     java.lang.Class<? extends Handler> handler)
                              throws ContainerConfigurationException
Creates entries in the Container so 1 lookup is possible.

Parameters:
container - The container to create the entries in
url - The URL of the new Handler
handler - The class of Handler
Throws:
ContainerConfigurationException - From DefaultContainer.addParameter(String, Object)

setupFromServletConfig

public static void setupFromServletConfig(DefaultContainer container,
                                          javax.servlet.ServletConfig servletConfig)
                                   throws ContainerConfigurationException
Take a DefaultContainer and setup the default beans

Parameters:
container - The container to configure
servletConfig - The servlet configuration (null to ignore)
Throws:
ContainerConfigurationException - If we can't use a bean

configureFromSystemDwrXml

public static void configureFromSystemDwrXml(Container container)
                                      throws java.io.IOException,
                                             javax.xml.parsers.ParserConfigurationException,
                                             org.xml.sax.SAXException
Configure using the system dwr.xml from within the JAR file.

Parameters:
container - The container to configure
Throws:
javax.xml.parsers.ParserConfigurationException - If the config file parse fails
java.io.IOException - If the config file read fails
org.xml.sax.SAXException - If the config file parse fails

configureFromDefaultDwrXml

public static void configureFromDefaultDwrXml(Container container,
                                              javax.servlet.ServletConfig servletConfig)
                                       throws java.io.IOException,
                                              javax.xml.parsers.ParserConfigurationException,
                                              org.xml.sax.SAXException
Configure using the users dwr.xml that sits next in WEB-INF

Parameters:
container - The container to configure
Throws:
javax.xml.parsers.ParserConfigurationException - If the config file parse fails
java.io.IOException - If the config file read fails
org.xml.sax.SAXException - If the config file parse fails

configureFromInitParams

public static boolean configureFromInitParams(Container container,
                                              javax.servlet.ServletConfig servletConfig)
                                       throws java.io.IOException,
                                              javax.xml.parsers.ParserConfigurationException,
                                              org.xml.sax.SAXException
Add configurators from init params to the end of the list of configurators.

Parameters:
container - The container to configure
servletConfig - The source of init parameters
Returns:
true if any Configurators were read
Throws:
org.xml.sax.SAXException - If the config file parse fails
javax.xml.parsers.ParserConfigurationException - If the config file parse fails
java.io.IOException - If the config file read fails

configureFromAnnotations

public static void configureFromAnnotations(Container container)
Configure using Annotations.

Parameters:
container - The container to configure

configure

public static void configure(Container container,
                             java.util.List<Configurator> configurators)
Allow all the configurators to have a go at the container in turn

Parameters:
container - The container to configure
configurators - A list of configurators to run against the container

configureContainerFully

public static void configureContainerFully(Container container,
                                           javax.servlet.ServletConfig servletConfig)
                                    throws java.io.IOException,
                                           javax.xml.parsers.ParserConfigurationException,
                                           org.xml.sax.SAXException
Run all the default configuration options on a Container

Parameters:
container - The container to configure
servletConfig - The source of init parameters
Throws:
org.xml.sax.SAXException - If the config file parse fails
javax.xml.parsers.ParserConfigurationException - If the config file parse fails
java.io.IOException - If the config file read fails

getSingletonServerContext

public static ServerContext getSingletonServerContext()
If there is only once instance of DWR defined in a ServletContext then we can get at it using this method.

Returns:
The one-and-only ServerContext or null if there are more than 1.

getAllServerContexts

public static java.util.Collection<ServerContext> getAllServerContexts()
If there is only once instance of DWR defined in a ServletContext then we can get at it using this method.

Returns:
The one-and-only ServerContext or null if there are more than 1.

getAllPublishedContainers

public static java.util.List<Container> getAllPublishedContainers(javax.servlet.ServletContext servletContext)
Get a list of all known Containers for the given ServletContext

Parameters:
servletContext - The context in which Containers are stored.
Returns:
a list of published Containers.

debugConfig

public static void debugConfig(Container container)
Create a bunch of debug information about a container

Parameters:
container - The container to print debug information about

Copyright 2008