use of com.google.inject.internal.BindingImpl in project camel by apache.
the class Injectors method tryCloseJitBindings.
private static void tryCloseJitBindings(Closer closer, Injector injector, Class<? extends Annotation> scopeAnnotationToClose, CloseErrors errors) {
Class<? extends Injector> type = injector.getClass();
Field field;
try {
field = type.getDeclaredField("jitBindings");
field.setAccessible(true);
Object bindings = field.get(injector);
if (bindings != null) {
if (bindings instanceof Map) {
Map<Key<?>, BindingImpl<?>> map = (Map<Key<?>, BindingImpl<?>>) bindings;
Set<Entry<Key<?>, BindingImpl<?>>> entries = map.entrySet();
for (Entry<Key<?>, BindingImpl<?>> entry : entries) {
closeBinding(entry.getKey(), entry.getValue(), scopeAnnotationToClose, closer, errors);
}
}
}
} catch (NoSuchFieldException e) {
// ignore - Guice has refactored so we can't access the jit bindings
// System.out.println("No such field! " + e);
} catch (IllegalAccessException e) {
// ignore - Guice has refactored so we can't access the jit bindings
// System.out.println("Failed to access field: " + field +
// ". Reason: " + e);
}
}
use of com.google.inject.internal.BindingImpl in project camel by apache.
the class Injectors method getScopeAnnotation.
/**
* Returns the scope annotation for the given binding or null if there is no
* scope
*/
public static Class<? extends Annotation> getScopeAnnotation(Binding<?> binding) {
Class<? extends Annotation> scopeAnnotation = null;
if (binding instanceof BindingImpl) {
BindingImpl bindingImpl = (BindingImpl) binding;
Scoping scoping = bindingImpl.getScoping();
if (scoping != null) {
scopeAnnotation = scoping.getScopeAnnotation();
// TODO not sure why we need this hack???
if (scopeAnnotation == null) {
Scope scope = scoping.getScopeInstance();
if (scope instanceof HasScopeAnnotation) {
HasScopeAnnotation hasScopeAnnotation = (HasScopeAnnotation) scope;
scopeAnnotation = hasScopeAnnotation.getScopeAnnotation();
}
if (scopeAnnotation == null && (scoping == Scoping.EAGER_SINGLETON || scoping == Scoping.SINGLETON_ANNOTATION || scoping == Scoping.SINGLETON_INSTANCE)) {
scopeAnnotation = Singleton.class;
}
}
}
}
return scopeAnnotation;
}
Aggregations