org.directwebremoting.guice
Class DwrGuiceUtil

java.lang.Object
  extended by org.directwebremoting.guice.DwrGuiceUtil

public class DwrGuiceUtil
extends java.lang.Object

Utilities for making Injector and ServletContext instances available.

Author:
Tim Peierls [tim at peierls dot net]

Field Summary
static java.lang.String INJECTOR
          The key under which a provided Injector is stashed in a ServletContext.
 
Constructor Summary
DwrGuiceUtil()
           
 
Method Summary
static com.google.inject.Injector getInjector()
          Returns the Injector instance published in the current servlet context.
static javax.servlet.ServletContext getServletContext()
          Gets the servlet context from the thread-local stash, if any, otherwise from the current web context, if one exists, otherwise from the singleton server context, if it exists, otherwise from the first of all server contexts, if there are any, otherwise null.
static
<T> T
withServletContext(javax.servlet.ServletContext servletContext, java.util.concurrent.Callable<T> callable)
          Executes the given Callable with the thread-locally stashed servlet context set to the given value, and returns the result.
static void withServletContext(javax.servlet.ServletContext servletContext, java.lang.Runnable runnable)
          Executes the given Runnable with the thread-locally stashed servlet context set to the given value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INJECTOR

public static final java.lang.String INJECTOR
The key under which a provided Injector is stashed in a ServletContext. The name is prefixed by the package to avoid conflicting with other listeners using the same technique.

See Also:
Constant Field Values
Constructor Detail

DwrGuiceUtil

public DwrGuiceUtil()
Method Detail

getInjector

public static com.google.inject.Injector getInjector()
Returns the Injector instance published in the current servlet context.


getServletContext

public static javax.servlet.ServletContext getServletContext()
Gets the servlet context from the thread-local stash, if any, otherwise from the current web context, if one exists, otherwise from the singleton server context, if it exists, otherwise from the first of all server contexts, if there are any, otherwise null.


withServletContext

public static void withServletContext(javax.servlet.ServletContext servletContext,
                                      java.lang.Runnable runnable)
Executes the given Runnable with the thread-locally stashed servlet context set to the given value.


withServletContext

public static <T> T withServletContext(javax.servlet.ServletContext servletContext,
                                       java.util.concurrent.Callable<T> callable)
                            throws java.lang.Exception
Executes the given Callable with the thread-locally stashed servlet context set to the given value, and returns the result.

Throws:
java.lang.Exception

Copyright 2008