org.guiceyfruit
Class Injectors

java.lang.Object
  extended by org.guiceyfruit.Injectors

public class Injectors
extends java.lang.Object

Version:
$Revision: 1.1 $

Field Summary
static java.lang.String MODULE_CLASS_NAMES
           
 
Constructor Summary
Injectors()
           
 
Method Summary
static void close(com.google.inject.Injector injector)
          Closes any singleton objects in the injector using the currently registered Closer implementations
static void close(com.google.inject.Injector injector, java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotationToClose)
          Closes objects within the given scope using the currently registered Closer implementations
static void close(com.google.inject.Injector injector, java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotationToClose, CloseErrors errors)
          Closes objects within the given scope using the currently registered Closer implementations
static void close(com.google.inject.Injector injector, CloseErrors errors)
          Closes objects within the given scope using the currently registered Closer implementations
static com.google.inject.Injector createInjector(java.util.Map environment, com.google.inject.Module... overridingModules)
          Creates an injector from the given properties, loading any modules define by the MODULE_CLASS_NAMES property value (space separated) along with any other modules passed as an argument.
static com.google.inject.Binding<?> getBinding(com.google.inject.Injector injector, com.google.inject.Key<?> key)
          Returns the binding for the given key or null if there is no such binding
static java.util.Set<com.google.inject.Binding<?>> getBindingsOf(com.google.inject.Injector injector, java.lang.Class<?> baseClass)
          Returns a collection of all bindings of the given base type
static java.util.Set<com.google.inject.Binding<?>> getBindingsOf(com.google.inject.Injector injector, com.google.inject.matcher.Matcher<java.lang.Class> matcher)
          Returns a collection of all of the bindings matching the given matcher
static
<T> T
getInstance(com.google.inject.Injector injector, java.lang.Class<T> type, java.lang.String name)
          Returns an instance of the given type with the Named annotation value.
static
<T> java.util.Set<T>
getInstancesOf(com.google.inject.Injector injector, java.lang.Class<T> baseClass)
          Returns a collection of all instances of the given base type
static
<T> java.util.Set<T>
getInstancesOf(com.google.inject.Injector injector, com.google.inject.matcher.Matcher<java.lang.Class> matcher)
          Returns a collection of all instances matching the given matcher
static
<T> java.lang.Class<?>
getKeyType(com.google.inject.Key<?> key)
          Returns the key type of the given key
static
<T> java.util.Set<com.google.inject.Provider<T>>
getProvidersOf(com.google.inject.Injector injector, java.lang.Class<T> baseClass)
          Returns a collection of all providers of the given base type
static
<T> java.util.Set<com.google.inject.Provider<T>>
getProvidersOf(com.google.inject.Injector injector, com.google.inject.matcher.Matcher<java.lang.Class> matcher)
          Returns a collection of all of the providers matching the given matcher
static java.lang.Class<? extends java.lang.annotation.Annotation> getScopeAnnotation(com.google.inject.Binding<?> binding)
          Returns the scope annotation for the given binding or null if there is no scope
static boolean hasBinding(com.google.inject.Injector injector, java.lang.Class<?> baseClass)
          Returns true if a binding exists for the given base class
static boolean hasBinding(com.google.inject.Injector injector, com.google.inject.Key<?> key)
          Returns true if a binding exists for the given key
static boolean hasBinding(com.google.inject.Injector injector, com.google.inject.matcher.Matcher<java.lang.Class> matcher)
          Returns true if a binding exists for the given matcher
protected static com.google.inject.Module loadModule(java.lang.String moduleName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODULE_CLASS_NAMES

public static final java.lang.String MODULE_CLASS_NAMES
See Also:
Constant Field Values
Constructor Detail

Injectors

public Injectors()
Method Detail

createInjector

public static com.google.inject.Injector createInjector(java.util.Map environment,
                                                        com.google.inject.Module... overridingModules)
                                                 throws java.lang.ClassNotFoundException,
                                                        java.lang.IllegalAccessException,
                                                        java.lang.InstantiationException
Creates an injector from the given properties, loading any modules define by the MODULE_CLASS_NAMES property value (space separated) along with any other modules passed as an argument.

Parameters:
environment - the properties used to create the injector
overridingModules - any modules which override the modules referenced in the environment such as to provide the actual JNDI context
Throws:
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException

getInstance

public static <T> T getInstance(com.google.inject.Injector injector,
                                java.lang.Class<T> type,
                                java.lang.String name)
Returns an instance of the given type with the Named annotation value. This method allows you to switch this code injector.getInstance(Key.get(type, Names.named(name))); to the more concise Injectors.getInstance(injector, type, name);


getInstancesOf

public static <T> java.util.Set<T> getInstancesOf(com.google.inject.Injector injector,
                                                  java.lang.Class<T> baseClass)
Returns a collection of all instances of the given base type

Type Parameters:
T - the base type
Parameters:
baseClass - the base type of objects required
Returns:
a set of objects returned from this injector

getInstancesOf

public static <T> java.util.Set<T> getInstancesOf(com.google.inject.Injector injector,
                                                  com.google.inject.matcher.Matcher<java.lang.Class> matcher)
Returns a collection of all instances matching the given matcher

Parameters:
matcher - matches the types to return instances
Returns:
a set of objects returned from this injector

getProvidersOf

public static <T> java.util.Set<com.google.inject.Provider<T>> getProvidersOf(com.google.inject.Injector injector,
                                                                              com.google.inject.matcher.Matcher<java.lang.Class> matcher)
Returns a collection of all of the providers matching the given matcher

Parameters:
matcher - matches the types to return instances
Returns:
a set of objects returned from this injector

getProvidersOf

public static <T> java.util.Set<com.google.inject.Provider<T>> getProvidersOf(com.google.inject.Injector injector,
                                                                              java.lang.Class<T> baseClass)
Returns a collection of all providers of the given base type

Type Parameters:
T - the base type
Parameters:
baseClass - the base type of objects required
Returns:
a set of objects returned from this injector

hasBinding

public static boolean hasBinding(com.google.inject.Injector injector,
                                 com.google.inject.matcher.Matcher<java.lang.Class> matcher)
Returns true if a binding exists for the given matcher


hasBinding

public static boolean hasBinding(com.google.inject.Injector injector,
                                 java.lang.Class<?> baseClass)
Returns true if a binding exists for the given base class


hasBinding

public static boolean hasBinding(com.google.inject.Injector injector,
                                 com.google.inject.Key<?> key)
Returns true if a binding exists for the given key


getBinding

public static com.google.inject.Binding<?> getBinding(com.google.inject.Injector injector,
                                                      com.google.inject.Key<?> key)
Returns the binding for the given key or null if there is no such binding


getBindingsOf

public static java.util.Set<com.google.inject.Binding<?>> getBindingsOf(com.google.inject.Injector injector,
                                                                        com.google.inject.matcher.Matcher<java.lang.Class> matcher)
Returns a collection of all of the bindings matching the given matcher

Parameters:
matcher - matches the types to return instances
Returns:
a set of objects returned from this injector

getBindingsOf

public static java.util.Set<com.google.inject.Binding<?>> getBindingsOf(com.google.inject.Injector injector,
                                                                        java.lang.Class<?> baseClass)
Returns a collection of all bindings of the given base type

Parameters:
baseClass - the base type of objects required
Returns:
a set of objects returned from this injector

getKeyType

public static <T> java.lang.Class<?> getKeyType(com.google.inject.Key<?> key)
Returns the key type of the given key


loadModule

protected static com.google.inject.Module loadModule(java.lang.String moduleName)
                                              throws java.lang.ClassNotFoundException,
                                                     java.lang.IllegalAccessException,
                                                     java.lang.InstantiationException
Throws:
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException

close

public static void close(com.google.inject.Injector injector)
                  throws CloseFailedException
Closes any singleton objects in the injector using the currently registered Closer implementations

Throws:
CloseFailedException

close

public static void close(com.google.inject.Injector injector,
                         CloseErrors errors)
                  throws CloseFailedException
Closes objects within the given scope using the currently registered Closer implementations

Throws:
CloseFailedException

close

public static void close(com.google.inject.Injector injector,
                         java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotationToClose)
                  throws CloseFailedException
Closes objects within the given scope using the currently registered Closer implementations

Throws:
CloseFailedException

close

public static void close(com.google.inject.Injector injector,
                         java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotationToClose,
                         CloseErrors errors)
                  throws CloseFailedException
Closes objects within the given scope using the currently registered Closer implementations

Throws:
CloseFailedException

getScopeAnnotation

public static java.lang.Class<? extends java.lang.annotation.Annotation> getScopeAnnotation(com.google.inject.Binding<?> binding)
Returns the scope annotation for the given binding or null if there is no scope



Copyright © 2011. All Rights Reserved.