public.javadoc.org.spincast.core.guice.GuiceModuleUtils.html Maven / Gradle / Ivy
Show all versions of spincast-website Show documentation
GuiceModuleUtils (org.spincast:spincast-framework 1.0.0 API)
org.spincast.core.guice
Class GuiceModuleUtils
- java.lang.Object
-
- org.spincast.core.guice.GuiceModuleUtils
-
public class GuiceModuleUtils
extends Object
Utilities to inspect/manipulate
Guice modules.
-
-
Field Summary
Fields
Modifier and Type
Field and Description
protected static org.slf4j.Logger
logger
-
Constructor Summary
Constructors
Constructor and Description
GuiceModuleUtils(com.google.inject.Module... modules)
GuiceModuleUtils(com.google.inject.Module module)
GuiceModuleUtils(Set<com.google.inject.Module> modules)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
Modifier and Type
Method and Description
static SpincastGuiceModuleBase
createInterceptorModule(Class<?> toIntercept,
Class<?> implementationClass,
boolean ignoreMethodsAnnotatedWithInject)
Creates a module that is going to intercept the calls to all methods defined in
an object implementing toIntercept
and will call those of
implementationClass
instead, if available.
protected static String
createMethodeSignatureKey(Method method)
<T> Class<? extends T>
getBindingTarget(Class<T> specificClass)
Returns the target of the binding with the specified class/interface.
<T> Class<? extends T>
getBindingTarget(com.google.inject.Key<T> specificKey)
Returns the target of the binding with the specified key.
protected <T> Set<Class<? extends T>>
getBoundClasses(Class<? extends T> parentType,
com.google.inject.Key<?> specificKey)
<T> Set<Class<? extends T>>
getBoundClassesExtending(Class<? extends T> parentType)
Returns the bound classes that extend or implement the specified
parentType
.
protected List<com.google.inject.spi.Element>
getElements()
protected com.google.inject.Module
getModule()
boolean
isKeyBound(Class<?> clazz)
Checks if a class is bound in the Module
boolean
isKeyBound(com.google.inject.Key<?> keyToCheck)
Checks if a key is bound in the Module
static com.google.inject.Module
removeBindings(com.google.inject.Module module,
Set<com.google.inject.Key<?>> keysToRemove)
Remove bindings from a Module.
-
-
Constructor Detail
-
GuiceModuleUtils
public GuiceModuleUtils(com.google.inject.Module module)
-
GuiceModuleUtils
public GuiceModuleUtils(Set<com.google.inject.Module> modules)
-
GuiceModuleUtils
public GuiceModuleUtils(com.google.inject.Module... modules)
-
Method Detail
-
getModule
protected com.google.inject.Module getModule()
-
getElements
protected List<com.google.inject.spi.Element> getElements()
-
isKeyBound
public boolean isKeyBound(Class<?> clazz)
Checks if a class is bound in the Module
-
isKeyBound
public boolean isKeyBound(com.google.inject.Key<?> keyToCheck)
Checks if a key is bound in the Module
-
getBindingTarget
public <T> Class<? extends T> getBindingTarget(com.google.inject.Key<T> specificKey)
Returns the target of the binding with the specified key.
This won't work if a Provider
is used!
- Returns:
- the class or
null
if not found.
-
getBindingTarget
public <T> Class<? extends T> getBindingTarget(Class<T> specificClass)
Returns the target of the binding with the specified class/interface.
This won't work if a Provider
is used!
- Returns:
- the class or
null
if not found.
-
getBoundClassesExtending
public <T> Set<Class<? extends T>> getBoundClassesExtending(Class<? extends T> parentType)
Returns the bound classes that extend or implement the specified
parentType
.
IMPORTANT : This doesn't mean that the parentType
is actually used as a key in a binding, but that there is a binding for an
class that extends/implements parentType
.
This won't work if a Provider
is used!
-
getBoundClasses
protected <T> Set<Class<? extends T>> getBoundClasses(Class<? extends T> parentType,
com.google.inject.Key<?> specificKey)
-
createInterceptorModule
public static SpincastGuiceModuleBase createInterceptorModule(Class<?> toIntercept,
Class<?> implementationClass,
boolean ignoreMethodsAnnotatedWithInject)
Creates a module that is going to intercept the calls to all methods defined in
an object implementing toIntercept
and will call those of
implementationClass
instead, if available.
This allows you, for example, to use a specific implementation for a
toIntercept
binding, even if an existing binding is done for a
class extending toIntercept
. This existing binding will still
continue to use its original implementation for the methods that are not
defined on toIntercept
but will use the implementation speficied
here for those that are.
You can annotate a method with DontIntercept
to prevent
it to be intercepted.
Note that the implementationClass
binding must have been done in other
module.
- Parameters:
ignoreMethodsAnnotatedWithInject
- if true
, methods from the intercepted
class annotated with Inject
or with Inject
will be ignored
(they won't be intercepted).
-
removeBindings
public static com.google.inject.Module removeBindings(com.google.inject.Module module,
Set<com.google.inject.Key<?>> keysToRemove)
Remove bindings from a Module.
Copyright © 2019. All rights reserved.