Class PerLocatorUtilities


  • public class PerLocatorUtilities
    extends java.lang.Object
    These utilities are per service locator. Another service locator may have a different view of the caches stored here
    • Field Detail

      • threadLocalAutoAnalyzerNameCache

        private final Hk2ThreadLocal<java.util.WeakHashMap<java.lang.Class<?>,​java.lang.String>> threadLocalAutoAnalyzerNameCache
        Must not be static, otherwise it can leak when using thread pools
      • threadLocalAnnotationCache

        private final Hk2ThreadLocal<java.util.WeakHashMap<java.lang.reflect.AnnotatedElement,​SoftAnnotatedElementAnnotationInfo>> threadLocalAnnotationCache
        Must not be static, otherwise it can leak when using thread pools
      • hasInjectCache

        private final Hk2ThreadLocal<java.util.WeakHashMap<java.lang.reflect.AnnotatedElement,​java.lang.Boolean>> hasInjectCache
    • Method Detail

      • hasInjectAnnotation

        boolean hasInjectAnnotation​(java.lang.reflect.AnnotatedElement annotated)
        Checks whether an annotated element has any annotation that was used for the injection
        Parameters:
        locator - The service locator to use (as it will get all the annotations that were added on as well as the normal Inject)
        annotated - the annotated element
        checkParams - check the params if true
        Returns:
        True if element contains at least one inject annotation
      • getAutoAnalyzerName

        public java.lang.String getAutoAnalyzerName​(java.lang.Class<?> c)
        Gets the analyzer name from the Service annotation
        Parameters:
        c - The class to get the analyzer name from
        Returns:
        The name of the analyzer (null for default)
      • getInjectionResolver

        public InjectionResolver<?> getInjectionResolver​(ServiceLocatorImpl locator,
                                                         Injectee injectee)
                                                  throws java.lang.IllegalStateException
        Returns an injection resolver for the injectee
        Parameters:
        locator - The locator to use when finding the resolver
        injectee - Injectee from which the annotation should be extracted
        Returns:
        Injection resolver used to resolve the injection for the injectee
        Throws:
        java.lang.IllegalStateException - If we could not find a valid resolver
      • getInjectionResolver

        InjectionResolver<?> getInjectionResolver​(ServiceLocatorImpl locator,
                                                  java.lang.reflect.AnnotatedElement annotatedGuy)
                                           throws java.lang.IllegalStateException
        Returns an injection resolver for this AnnotatedElement. The method cannot be used for constructors or methods.
        Parameters:
        locator - The locator to use when finding the resolver
        annotatedGuy - The annotated class or producer method
        Returns:
        The scope of this class or producer method. If no scope is found will return the dependent scope
        Throws:
        java.lang.IllegalStateException - If we could not find a valid resolver
      • getInjectionResolver

        private InjectionResolver<?> getInjectionResolver​(ServiceLocatorImpl locator,
                                                          java.lang.reflect.AnnotatedElement annotatedGuy,
                                                          int position)
                                                   throws java.lang.IllegalStateException
        Throws:
        java.lang.IllegalStateException
      • getInjectAnnotation

        private java.lang.annotation.Annotation getInjectAnnotation​(ServiceLocatorImpl locator,
                                                                    java.lang.reflect.AnnotatedElement annotated,
                                                                    boolean checkParams,
                                                                    int position)
        Gets the annotation that was used for the injection
        Parameters:
        locator - The service locator to use (as it will get all the annotations that were added on as well as the normal Inject)
        annotated - the annotated annotated
        checkParams - check the params if true
        position - index of constructor or method parameter which which will be checked for inject annotations. The position parameter is only used when annotated is method or constructor otherwise the value will be ignored.
        Returns:
        The annotation that is the inject annotation, or null if no inject annotation was found
      • releaseCaches

        public void releaseCaches()
      • shutdown

        public void shutdown()