Search in sources :

Example 1 with HasScopeAnnotation

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;
}
Also used : BindingImpl(com.google.inject.internal.BindingImpl) HasScopeAnnotation(org.apache.camel.guice.support.HasScopeAnnotation) Scoping(com.google.inject.internal.Scoping) Scope(com.google.inject.Scope)

Aggregations

Scope (com.google.inject.Scope)1 BindingImpl (com.google.inject.internal.BindingImpl)1 Scoping (com.google.inject.internal.Scoping)1 HasScopeAnnotation (org.apache.camel.guice.support.HasScopeAnnotation)1