org.directwebremoting.impl
Class DefaultContainer

java.lang.Object
  extended by org.directwebremoting.impl.AbstractContainer
      extended by org.directwebremoting.impl.DefaultContainer
All Implemented Interfaces:
Container
Direct Known Subclasses:
SpringContainer

public class DefaultContainer
extends AbstractContainer
implements Container

DefaultContainer is like a mini-IoC container for DWR. At least it is an IoC container by interface (check: no params that have anything to do with DWR), but it is hard coded specifically for DWR. If we want to make more of it we can later, but this is certainly not going to become a full blown IoC container.

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

Constructor Summary
DefaultContainer()
           
 
Method Summary
<T> void
addBean(java.lang.Class<T> base, T bean)
          Set the class that should be used to implement the given interface
<T> void
addImplementation(java.lang.Class<T> base, java.lang.Class<? extends T> implementation)
          Set the class that should be used to implement the given interface
<T> void
addImplementationOption(java.lang.Class<T> base, java.lang.Class<? extends T> implementation)
          Set the class that should be used to implement the given interface
 void addParameter(java.lang.String askFor, java.lang.Object valueParam)
          Add a parameter to the container as a possibility for injection
 void destroy()
          Closes down all parts of DWR in a timely way, stops threads, and performs tidy-up.
 void destroy(java.util.Collection<java.lang.String> beanNames)
           
 java.lang.Object getBean(java.lang.String id)
          Get the contained instance of a bean/setting of a given name.
 java.util.Collection<java.lang.String> getBeanNames()
          Get a list of all the available beans.
 java.lang.String getParameter(java.lang.String name)
          Retrieve a previously set parameter
 void initializeBean(java.lang.Object bean)
          Sometimes we need to take a bean not created by the container, and inject it with the data that it would contain if it was created by the container.
<T> T
newInstance(java.lang.Class<T> type)
          Sometimes we need to create a bean as a one-off object and have it injected with settings by the container.
 void setupFinished()
          Called to indicate that we finished adding parameters.
 
Methods inherited from class org.directwebremoting.impl.AbstractContainer
getBean
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.directwebremoting.Container
getBean
 

Constructor Detail

DefaultContainer

public DefaultContainer()
Method Detail

addBean

public <T> void addBean(java.lang.Class<T> base,
                        T bean)
Set the class that should be used to implement the given interface

Parameters:
base - The interface to implement
bean - The new implementation
Throws:
ContainerConfigurationException - If the specified beans could not be used

addImplementation

public <T> void addImplementation(java.lang.Class<T> base,
                                  java.lang.Class<? extends T> implementation)
Set the class that should be used to implement the given interface

Parameters:
base - The interface to implement
implementation - The new implementation
Throws:
ContainerConfigurationException - If the specified beans could not be used

addImplementationOption

public <T> void addImplementationOption(java.lang.Class<T> base,
                                        java.lang.Class<? extends T> implementation)
Set the class that should be used to implement the given interface

Parameters:
base - The interface to implement
implementation - The new implementation
Throws:
ContainerConfigurationException - If the specified beans could not be used

addParameter

public void addParameter(java.lang.String askFor,
                         java.lang.Object valueParam)
                  throws ContainerConfigurationException
Add a parameter to the container as a possibility for injection

Parameters:
askFor - The key that will be looked up
valueParam - The value to be returned from the key lookup
Throws:
ContainerConfigurationException - If the specified beans could not be used

getParameter

public java.lang.String getParameter(java.lang.String name)
Retrieve a previously set parameter

Parameters:
name - The parameter name to retrieve
Returns:
The value of the specified parameter, or null if one is not set

setupFinished

public void setupFinished()
Called to indicate that we finished adding parameters. The thread safety of a large part of DWR depends on this function only being called from Servlet.init(javax.servlet.ServletConfig), where all the setup is done, and where we depend on the undocumented feature of all servlet containers that they complete the init process of a Servlet before they begin servicing requests.

See Also:
addParameter(String, Object)

newInstance

public <T> T newInstance(java.lang.Class<T> type)
              throws java.lang.InstantiationException,
                     java.lang.IllegalAccessException
Description copied from interface: Container
Sometimes we need to create a bean as a one-off object and have it injected with settings by the container. This does not make the object part of the container.

Specified by:
newInstance in interface Container
Parameters:
type - The type to get an instance of
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

initializeBean

public void initializeBean(java.lang.Object bean)
Description copied from interface: Container
Sometimes we need to take a bean not created by the container, and inject it with the data that it would contain if it was created by the container. This does not make the object part of the container.

Specified by:
initializeBean in interface Container
Parameters:
bean - The object to inject.

getBean

public java.lang.Object getBean(java.lang.String id)
Description copied from interface: Container
Get the contained instance of a bean/setting of a given name.

Specified by:
getBean in interface Container
Parameters:
id - The type to get an instance of
Returns:
The object of the given type, or null if the object does not exist

getBeanNames

public java.util.Collection<java.lang.String> getBeanNames()
Description copied from interface: Container
Get a list of all the available beans. Implementation of this method is optional so it is valid for this method to return an empty collection, but to return Objects when queried directly using Container.getBean(String). This method should only be used for debugging purposes.

Specified by:
getBeanNames in interface Container
Returns:
A collection containing all the available bean names.

destroy

public void destroy()
Description copied from interface: Container
Closes down all parts of DWR in a timely way, stops threads, and performs tidy-up.

Specified by:
destroy in interface Container

destroy

public void destroy(java.util.Collection<java.lang.String> beanNames)

Copyright ยจ 2008