use of org.apache.camel.guice.support.HasScopeAnnotation 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