Top Description Inners Fields Constructors Methods
org.jvnet.hk2.internal

public Class Utilities

extends Object
Class Inheritance
Imports
org.aopalliance.intercept.ConstructorInterceptor, .MethodInterceptor, java.io.IOException, java.lang.annotation.Annotation, .Inherited, java.lang.reflect.AnnotatedElement, .Constructor, .Field, .Member, .Method, .Modifier, .ParameterizedType, .Type, .WildcardType, java.security.AccessController, .PrivilegedAction, java.util.ArrayList, .Collections, .HashMap, .HashSet, .LinkedHashMap, .LinkedHashSet, .LinkedList, .List, .Map, .Set, java.util.concurrent.locks.ReentrantLock, jakarta.inject.Inject, .Named, .Qualifier, .Scope, .Singleton, org.glassfish.hk2.api.ActiveDescriptor, .ClassAnalyzer, .Context, .ContractIndicator, .Descriptor, .DescriptorType, .DescriptorVisibility, .DynamicConfigurationListener, .DynamicConfigurationService, .ErrorService, .ErrorType, .Factory, .Filter, .HK2Loader, .Injectee, .InjectionResolver, .InstanceLifecycleListener, .InterceptionService, .MethodParameter, .MultiException, .PerLookup, .Proxiable, .ProxyCtl, .ProxyForSameScope, .Rank, .Self, .ServiceHandle, .ServiceLocator, .Unproxiable, .Unqualified, .UseProxy, .ValidationService, .Visibility, org.glassfish.hk2.api.messaging.SubscribeTo, org.glassfish.hk2.utilities.BuilderHelper, .NamedImpl, .ServiceLocatorUtilities, org.glassfish.hk2.utilities.reflection.ClassReflectionHelper, .Constants, .MethodWrapper, .Pretty, .ParameterizedTypeImpl, .ReflectionHelper, .ScopeInfo, .TypeChecker, org.jvnet.hk2.annotations.Contract, .ContractsProvided, .Optional, .Service

This class contains a set of static utilities useful for implementing HK2
Author
jwells

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static interface
Utilities.Interceptors

The return type from getAllInterceptors

Field Summary

Modifier and TypeField and Description
private static final Utilities.AnnotationInformation
private static final Utilities.Interceptors
private static final ReentrantLock
private static final HashSet<String>
private static final String
private static Boolean
pack-priv static final boolean
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
checkFactoryType(Class<?>
the class to check
factoryClass
,
Collector
the exception collector
collector
)

Checks to be sure the Factory class is ok

public static void
checkLookupType(Class<?>
class to check
checkMe
)

Checks that the incoming lookup type is not improper in some way

pack-priv static AnnotatedElementAnnotationInfo

Returns:

An annotated element constructed from the information in the annotatedElement
computeAEAI
(AnnotatedElement
The raw annotated element that can be used to calculate the information needed to determine the resolver
annotatedElement
)

Represents a cache miss, and will fetch all of the information needed about the AnnotatedElement in order to quickly determine what its resolver would be

public static <T> AutoActiveDescriptor<T>

Returns:

A reified active descriptor
createAutoDescriptor
(Class<T>
The class to create the desciptor for
clazz
,
ServiceLocatorImpl
The service locator for whom we are creating this
locator
)

Creates a reified automatically generated descriptor

public static <T> AutoActiveDescriptor<T>

Returns:

A reified active descriptor
createAutoFactoryDescriptor
(Class<T>
The class to create the desciptor for
parentClazz
,
ActiveDescriptor<?> factoryDescriptor, ServiceLocatorImpl
The service locator for whom we are creating this
locator
)

Creates a reified automatically generated descriptor

public static <T> T

Returns:

The created service
createService
(ActiveDescriptor<T>
The ultimate parent of this operation
root
,
Injectee
the injectee we are creating this service for
injectee
,
ServiceLocatorImpl
The locator to use to find services
locator
,
ServiceHandle<T>
The ServiceHandle (or null if there is none)
handle
,
Class<?>
The class for the service we are looking for
requestedClass
)

Creates the service (without the need for an intermediate ServiceHandle to be created)

public static Set<Field>

Returns:

A non-null but possibly empty set of initializer fields
findInitializerFields
(Class<?>
The class to search for fields
annotatedType
,
ServiceLocatorImpl
The locator to use when analyzing the class
locator
,
Collector
The error collector
errorCollector
)

Will find all the initialize fields in the class

public static Set<Method>

Returns:

A possibly empty but never null set of initializer methods
findInitializerMethods
(Class<?>
The type to find the errors in
annotatedType
,
ServiceLocatorImpl
The locator to use when analyzing methods
locator
,
Collector
The collector to add errors to
errorCollector
)

Get all the initializer methods of the annotatedType.

public static Method

Returns:

The post construct method or null
findPostConstruct
(Class<?>
The class to search for the post construct
clazz
,
ServiceLocatorImpl locator, Collector
An error collector
collector
)

Finds the post construct method on this class

public static Method

Returns:

The pre destroy method or null
findPreDestroy
(Class<?>
The class to search for the pre destroy method
clazz
,
ServiceLocatorImpl locator, Collector
An error collector
collector
)

Finds the pre destroy method on this class

public static Constructor<?>

Returns:

The producer constructor or null if the type has no valid producer constructor
findProducerConstructor
(Class<?>
The type to find the producer constructor
annotatedType
,
ServiceLocatorImpl
The service locator to use when analyzing constructors
locator
,
Collector
The error collector
collector
)

Validates the constructors of the annotated type and returns the producer for the annotatedType (if there is no valid producer constructor then this method returns null)

public static Set<Annotation>

Returns:

The set containing all the qualifiers
fixAndCheckQualifiers
(Annotation[]
The qualifiers to convert. May not be null, but may be zero length
qualifiers
,
String
The name this set of qualifiers must have
name
)

This method returns a set of qualifiers from an array of qualifiers.

private static Set<Constructor<?>>

Returns:

A set of Constructors for the given class
getAllConstructors
(final Class<?>
The class to find the constructors of
clazz
)

Gets all the constructors for a given class

pack-priv static Utilities.Interceptors
public static Set<Annotation>

Returns:

A non-null but possibly empty set of qualifiers
getAllQualifiers
(AnnotatedElement
The element we are searching for qualifiers
annotatedGuy
,
String
The name this element must have
name
,
Collector
The error collector
collector
)

Returns the full set of qualifier annotations on this class

private static Set<Type>
public static ClassAnalyzer

Returns:

The ClassAnalyzer corresponding to the name, or null if none was found
getClassAnalyzer
(ServiceLocatorImpl
The ServiceLocator to search in. May not be null
sli
,
String
The name of the analyzer (may be null for the default analyzer)
analyzerName
,
Collector
A non-null collector of exceptions
errorCollector
)

Returns the class analyzer with the given name

public static <T> Constructor<T>

Returns:

null on failure (collector will have failures), non-null on success
getConstructor
(Class<T>
The implementation class (not null)
implClass
,
ClassAnalyzer
The analyzer (not null)
analyzer
,
Collector
A collector for errors (not null)
collector
)

Gets the constructor given the implClass and analyzer.

public static List<SystemInjecteeImpl>

Returns:

the list (in order) of parameters to the constructor
getConstructorInjectees
(Constructor<?>
The constructor to analyze
c
,
ActiveDescriptor<?>
The descriptor of the injectee
injecteeDescriptor
)

Returns all the injectees for a constructor

public static String

Returns:

null if there is no default name (no Named)
getDefaultNameFromMethod
(Method
The parent annotated element
parent
,
Collector
For errors
collector
)

Returns the default name if one can be found.

public static Class<?>

Returns:

The real implementation class
getFactoryAwareImplementationClass
(ActiveDescriptor<?>
The descriptor (reified and not null) that will be used to find the implementation
descriptor
)

This utility will return the proper implementation class, taking into account that the descriptor may be a factory

private static Class<?>

Returns:

the CLASS version of what the factory produces. Will not be null.
getFactoryProductionClass
(ActiveDescriptor<?>
The descriptor (reified and not null) that will be used to find the implementation.
descriptor
)

This method returns the class associated with the type of the factory.

public static Type

Returns:

the type version of what the factory produces. Will not be null
getFactoryProductionType
(Class<?>
The non-null factory class. May not be null
factoryClass
)

This method returns the type produced by a factory class

public static Method

Returns:

The provide method from this class
getFactoryProvideMethod
(Class<?>
This class must implement factory
clazz
)

This method will retrieve the provide method from a Factory

private static Set<Annotation>
public static List<SystemInjecteeImpl>

Returns:

the list (in order) of parameters to the constructor
getFieldInjectees
(Class<?> actualClass, Field
The field to analyze
f
,
ActiveDescriptor<?>
The descriptor of the injectee
injecteeDescriptor
)

Returns the injectees for a field

public static <T> T

Returns:

the first thing found in the set
getFirstThingInList
(List<T>
The set from which to get the first element
set
)

Returns the first thing found in the set

public static Set<Field>

Returns:

a non-null set (even in error cases, check the collector)
getInitFields
(Class<?>
the non-null impl class
implClass
,
ClassAnalyzer
the non-null analyzer
analyzer
,
Collector
for gathering errors
collector
)

Gets the initializer fields from the given class and analyzer.

public static Set<Method>

Returns:

a non-null set (even in error cases, check the collector)
getInitMethods
(Class<?>
the non-null impl class
implClass
,
ClassAnalyzer
the non-null analyzer
analyzer
,
Collector
for gathering errors
collector
)

Gets the initializer methods from the given class and analyzer.

public static Class<? extends Annotation>

Returns:

The annotation type for this injection resolver
getInjectionResolverType
(ActiveDescriptor<?>
The reified descriptor to find the injection resolution on
desc
)

Will return the class of the injection resolver annotation type, or null if no injection resolver annotation can be found

public static Class<?>[]

Returns:

The array of contracts to add to the proxy
getInterfacesForProxy
(Set<Type>
All of the advertised contracts
contracts
)

Returns all the interfaces the proxy must implement

public static ActiveDescriptor<ServiceLocator>

Returns:

An active descriptor specifically for the ServiceLocator
getLocatorDescriptor
(ServiceLocator
The service locator to get the ActiveDescriptor for
locator
)

Returns a constant ActiveDescriptor for the basic ServiceLocator

public static List<SystemInjecteeImpl>

Returns:

the list (in order) of parameters to the constructor
getMethodInjectees
(Class<?> actualClass, Method
The constructor to analyze
c
,
ActiveDescriptor<?>
The descriptor of the injectee
injecteeDescriptor
)

Returns all the injectees for a constructor

public static List<SystemInjecteeImpl>

Returns:

the list (in order) of parameters to the constructor
getMethodInjectees
(Class<?> actualClass, Method
The constructor to analyze
c
,
ActiveDescriptor<?>
The descriptor of the injectee
injecteeDescriptor
,
Map<Integer, MethodParameter> knownValues)

Returns all the injectees for a constructor

private static Utilities.AnnotationInformation
getParamInformation(Annotation[] memberAnnotations)

public static Method

Returns:

The possibly null post-construct method (check the collector for errors)
getPostConstruct
(Class<?>
The non-null implementation class
implClass
,
ClassAnalyzer
The non-null analyzer
analyzer
,
Collector
The non-null error collector
collector
)

Gets the post construct from the analyzer, checking output

public static Method

Returns:

The possibly null pre-destroy method (check the collector for errors)
getPreDestroy
(Class<?>
The non-null implementation class
implClass
,
ClassAnalyzer
The non-null analyzer
analyzer
,
Collector
The non-null error collector
collector
)

Gets the preDestroy from the analyzer, checking output

public static Class<? extends Annotation>

Returns:

The scope of this class or producer method. If no scope is found will return the dependent scope
getScopeAnnotationType
(Class<?>
The annotated class or producer method
fromThis
,
Descriptor
The default scope if none other can be found
defaultScope
)

Returns the scope of this thing

public static ScopeInfo

Returns:

The scope of this class or producer method. If no scope is found will return the dependent scope
getScopeAnnotationType
(AnnotatedElement
The annotated class or producer method
annotatedGuy
,
Descriptor
The default scope if none other can be found
defaultScope
,
Collector
The error collector
collector
)

Returns the scope of this thing

private static ScopeInfo
getScopeInfo(AnnotatedElement annotatedGuy, Descriptor defaultScope, Collector collector)

public static ActiveDescriptor<InjectionResolver<Inject>>

Returns:

An active descriptor specifically for the ServiceLocator
getThreeThirtyDescriptor
(ServiceLocatorImpl
The service locator to get the ActiveDescriptor for
locator
)

Creates a Three Thirty constant active descriptor

public static void
handleErrors(NarrowResults
the results
results
,
LinkedList<ErrorService>
the services to call
callThese
)

Calls the list of error services for the list of errors

private static boolean
hasContract(Class<?> clazz)

private static boolean
private static Annotation
internalGetScopeAnnotationType(AnnotatedElement annotatedGuy, Collector collector)

This returns the scope annotation on this class *itself*, and no other classes (like, not subclasses).

public static boolean

Returns:

true if the member is abstract
isAbstract
(Member
The non-null member to test
member
)

Returns true if the underlying member is abstract

public static boolean

Returns:

true if the member is abstract
isFinal
(Member
The non-null member to test
member
)

Returns true if the underlying member is abstract

private static boolean
isFinal(Class<?> clazz)

private static boolean
private static boolean
private static boolean
private static boolean

Returns:

true if this descriptor must be proxied, false otherwise
isProxiable
(ActiveDescriptor<?>
A non-null, reified ActiveDescriptor
desc
,
Injectee
The injectee where this is being injected if known, or null if not known
injectee
)

This method determines whether or not the descriptor should be proxied.

public static boolean

Returns:

true if this must be proxied
isProxiableScope
(Class<? extends Annotation>
The scope annotation to test
scope
)

Returns true if this scope is proxiable

public static boolean

Returns:

true if beanType is safely assignable to requiredType
isTypeSafe
(Type
The type this must conform to
requiredType
,
Type
The type of the bean we are checking
beanType
)

This code uses the TypeChecker but does some extra checking if the types are annotations

public static boolean

Returns:

true if this must be proxied
isUnproxiableScope
(Class<? extends Annotation>
The scope annotation to test
scope
)

Returns true if this scope is unproxiable

public static Object
justAssistedInject(Object injectMe, Method method, ServiceLocatorImpl locator, ServiceHandle<?> root, MethodParameter... givenValues)

Just injects this one method

public static <T> T

Returns:

The constructed thing, no further injection is performed
justCreate
(Class<T>
The thing to create
createMe
,
ServiceLocatorImpl
The locator to find the injection points with
locator
,
String
The strategy to use for analyzing the class
strategy
)

Just creates the thing, doesn't try to do anything else

public static void
justInject(Object
The object to inject into
injectMe
,
ServiceLocatorImpl
The locator to find the injection points with
locator
,
String
The strategy to use for analyzing the class
strategy
)

Just injects the thing, doesn't try to do anything else

public static void
justPostConstruct(Object
post constructs the thing
postMe
,
ServiceLocatorImpl
The non-null service locator associated with the operation (for finding the strategy)
locator
,
String
The strategy to use for analyzing the class
strategy
)

Post constructs the given object

public static void
justPreDestroy(Object
pre destroys the thing
preMe
,
ServiceLocatorImpl
The non-null service locator associated with the operation (for finding the strategy)
locator
,
String
The strategy to use for analyzing the class
strategy
)

Pre Destroys the given object

public static Class<?>

Returns:

null on failure to load (the failure will be added to the collector)
loadClass
(String
The fully qualified class name
loadMe
,
Descriptor
The descriptor to use for the loader
fromMe
,
Collector
The error collector to fill in if this returns null
collector
)

Loads the class using the loader from the given descriptor or the classloader of the utilities class otherwise

public static Class<?>

Returns:

The class represented by this implementation and injectee
loadClass
(String
the impl class name string
implementation
,
Injectee
the injectee
injectee
)

Load the given class for the given injectee.

public static boolean

Returns:

true if the system can create proxies, false otherwise
proxiesAvailable
()

Returns true if the system can create proxies, false otherwise

public static Class<?>

Returns:

The translated type or the type itself
translatePrimitiveType
(Class<?>
The type to convert
type
)

Converts the type to its java form, or returns the original

public static void
validateSelfInjectees(ActiveDescriptor<?>
The descriptor associated with this injectee, or null if there are none
givenDescriptor
,
List<SystemInjecteeImpl>
The list of injectees to check. Only self injectees are validates
injectees
,
Collector
The collector to add any errors to
collector
)

This method validates a list of injectees to ensure that any self injectees have the proper set of requirements.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait