public class Utilities
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
Utilities.AnnotationInformation |
static interface |
Utilities.Interceptors
The return type from getAllInterceptors
|
Modifier and Type | Field and Description |
---|---|
private static Utilities.AnnotationInformation |
DEFAULT_ANNOTATION_INFORMATION |
private static Utilities.Interceptors |
EMTPY_INTERCEPTORS |
private static java.util.HashSet<java.lang.String> |
NOT_INTERCEPTED |
private static java.lang.String |
PROVIDE_METHOD |
private static java.lang.Boolean |
proxiesAvailable |
(package private) static boolean |
USE_SOFT_REFERENCE |
private static java.lang.String |
USE_SOFT_REFERENCE_PROPERTY |
Constructor and Description |
---|
Utilities() |
Modifier and Type | Method and Description |
---|---|
static void |
checkFactoryType(java.lang.Class<?> factoryClass,
Collector collector)
Checks to be sure the Factory class is ok
|
static void |
checkLookupType(java.lang.Class<?> checkMe)
Checks that the incoming lookup type is not improper in some way
|
(package private) static AnnotatedElementAnnotationInfo |
computeAEAI(java.lang.reflect.AnnotatedElement 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
|
static <T> AutoActiveDescriptor<T> |
createAutoDescriptor(java.lang.Class<T> clazz,
ServiceLocatorImpl locator)
Creates a reified automatically generated descriptor
|
static <T> AutoActiveDescriptor<T> |
createAutoFactoryDescriptor(java.lang.Class<T> parentClazz,
ActiveDescriptor<?> factoryDescriptor,
ServiceLocatorImpl locator)
Creates a reified automatically generated descriptor
|
static <T> T |
createService(ActiveDescriptor<T> root,
Injectee injectee,
ServiceLocatorImpl locator,
ServiceHandle<T> handle,
java.lang.Class<?> requestedClass)
Creates the service (without the need for an intermediate ServiceHandle
to be created)
|
static java.util.Set<java.lang.reflect.Field> |
findInitializerFields(java.lang.Class<?> annotatedType,
ServiceLocatorImpl locator,
Collector errorCollector)
Will find all the initialize fields in the class
|
static java.util.Set<java.lang.reflect.Method> |
findInitializerMethods(java.lang.Class<?> annotatedType,
ServiceLocatorImpl locator,
Collector errorCollector)
Get all the initializer methods of the annotatedType.
|
static java.lang.reflect.Method |
findPostConstruct(java.lang.Class<?> clazz,
ServiceLocatorImpl locator,
Collector collector)
Finds the post construct method on this class
|
static java.lang.reflect.Method |
findPreDestroy(java.lang.Class<?> clazz,
ServiceLocatorImpl locator,
Collector collector)
Finds the pre destroy method on this class
|
static java.lang.reflect.Constructor<?> |
findProducerConstructor(java.lang.Class<?> annotatedType,
ServiceLocatorImpl locator,
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)
|
static java.util.Set<java.lang.annotation.Annotation> |
fixAndCheckQualifiers(java.lang.annotation.Annotation[] qualifiers,
java.lang.String name)
This method returns a set of qualifiers from an array of qualifiers.
|
private static java.util.Set<java.lang.reflect.Constructor<?>> |
getAllConstructors(java.lang.Class<?> clazz)
Gets all the constructors for a given class
|
(package private) static Utilities.Interceptors |
getAllInterceptors(ServiceLocatorImpl impl,
ActiveDescriptor<?> descriptor,
java.lang.Class<?> clazz,
java.lang.reflect.Constructor<?> c) |
static java.util.Set<java.lang.annotation.Annotation> |
getAllQualifiers(java.lang.reflect.AnnotatedElement annotatedGuy,
java.lang.String name,
Collector collector)
Returns the full set of qualifier annotations on this class
|
private static java.util.Set<java.lang.reflect.Type> |
getAutoAdvertisedTypes(java.lang.reflect.Type t) |
static ClassAnalyzer |
getClassAnalyzer(ServiceLocatorImpl sli,
java.lang.String analyzerName,
Collector errorCollector)
Returns the class analyzer with the given name
|
static <T> java.lang.reflect.Constructor<T> |
getConstructor(java.lang.Class<T> implClass,
ClassAnalyzer analyzer,
Collector collector)
Gets the constructor given the implClass and analyzer.
|
static java.util.List<SystemInjecteeImpl> |
getConstructorInjectees(java.lang.reflect.Constructor<?> c,
ActiveDescriptor<?> injecteeDescriptor)
Returns all the injectees for a constructor
|
static java.lang.String |
getDefaultNameFromMethod(java.lang.reflect.Method parent,
Collector collector)
Returns the default name if one can be found.
|
static java.lang.Class<?> |
getFactoryAwareImplementationClass(ActiveDescriptor<?> descriptor)
This utility will return the proper implementation class, taking into account that the
descriptor may be a factory
|
private static java.lang.Class<?> |
getFactoryProductionClass(java.lang.Class<?> factoryClass)
This method returns the class associated with the type of the
factory
|
static java.lang.reflect.Type |
getFactoryProductionType(java.lang.Class<?> factoryClass)
This method returns the type produced by a factory class
|
static java.lang.reflect.Method |
getFactoryProvideMethod(java.lang.Class<?> clazz)
This method will retrieve the provide method from a Factory
|
private static java.util.Set<java.lang.annotation.Annotation> |
getFieldAdjustedQualifierAnnotations(java.lang.reflect.Field f,
java.util.Set<java.lang.annotation.Annotation> qualifiers) |
static java.util.List<SystemInjecteeImpl> |
getFieldInjectees(java.lang.Class<?> actualClass,
java.lang.reflect.Field f,
ActiveDescriptor<?> injecteeDescriptor)
Returns the injectees for a field
|
static <T> T |
getFirstThingInList(java.util.List<T> set)
Returns the first thing found in the set
|
static java.util.Set<java.lang.reflect.Field> |
getInitFields(java.lang.Class<?> implClass,
ClassAnalyzer analyzer,
Collector collector)
Gets the initializer fields from the given class and analyzer.
|
static java.util.Set<java.lang.reflect.Method> |
getInitMethods(java.lang.Class<?> implClass,
ClassAnalyzer analyzer,
Collector collector)
Gets the initializer methods from the given class and analyzer.
|
static java.lang.Class<? extends java.lang.annotation.Annotation> |
getInjectionResolverType(ActiveDescriptor<?> desc)
Will return the class of the injection resolver annotation type, or null if
no injection resolver annotation can be found
|
static java.lang.Class<?>[] |
getInterfacesForProxy(java.util.Set<java.lang.reflect.Type> contracts)
Returns all the interfaces the proxy must implement
|
static ActiveDescriptor<ServiceLocator> |
getLocatorDescriptor(ServiceLocator locator)
Returns a constant ActiveDescriptor for the basic ServiceLocator
|
static java.util.List<SystemInjecteeImpl> |
getMethodInjectees(java.lang.Class<?> actualClass,
java.lang.reflect.Method c,
ActiveDescriptor<?> injecteeDescriptor)
Returns all the injectees for a constructor
|
private static Utilities.AnnotationInformation |
getParamInformation(java.lang.annotation.Annotation[] memberAnnotations) |
static java.lang.reflect.Method |
getPostConstruct(java.lang.Class<?> implClass,
ClassAnalyzer analyzer,
Collector collector)
Gets the post construct from the analyzer, checking output
|
static java.lang.reflect.Method |
getPreDestroy(java.lang.Class<?> implClass,
ClassAnalyzer analyzer,
Collector collector)
Gets the preDestroy from the analyzer, checking output
|
static ScopeInfo |
getScopeAnnotationType(java.lang.reflect.AnnotatedElement annotatedGuy,
Descriptor defaultScope,
Collector collector)
Returns the scope of this thing
|
static java.lang.Class<? extends java.lang.annotation.Annotation> |
getScopeAnnotationType(java.lang.Class<?> fromThis,
Descriptor defaultScope)
Returns the scope of this thing
|
private static ScopeInfo |
getScopeInfo(java.lang.reflect.AnnotatedElement annotatedGuy,
Descriptor defaultScope,
Collector collector) |
static ActiveDescriptor<InjectionResolver<javax.inject.Inject>> |
getThreeThirtyDescriptor(ServiceLocatorImpl locator)
Creates a Three Thirty constant active descriptor
|
static void |
handleErrors(NarrowResults results,
java.util.LinkedList<ErrorService> callThese)
Calls the list of error services for the list of errors
|
private static boolean |
hasContract(java.lang.Class<?> clazz) |
private static java.lang.annotation.Annotation |
internalGetScopeAnnotationType(java.lang.reflect.AnnotatedElement annotatedGuy,
Collector collector)
This returns the scope annotation on this class *itself*, and no other
classes (like, not subclasses).
|
static boolean |
isAbstract(java.lang.reflect.Member member)
Returns true if the underlying member is abstract
|
private static boolean |
isFinal(java.lang.Class<?> clazz) |
static boolean |
isFinal(java.lang.reflect.Member member)
Returns true if the underlying member is abstract
|
private static boolean |
isProperConstructor(java.lang.reflect.Constructor<?> c) |
private static boolean |
isProperField(java.lang.reflect.Field field) |
private static boolean |
isProperMethod(java.lang.reflect.Method member) |
private static boolean |
isProxiable(ActiveDescriptor<?> desc,
Injectee injectee)
This method determines whether or not the descriptor should be proxied.
|
static boolean |
isProxiableScope(java.lang.Class<? extends java.lang.annotation.Annotation> scope)
Returns true if this scope is proxiable
|
static boolean |
isTypeSafe(java.lang.reflect.Type requiredType,
java.lang.reflect.Type beanType)
This code uses the TypeChecker but does some extra checking if
the types are annotations
|
static boolean |
isUnproxiableScope(java.lang.Class<? extends java.lang.annotation.Annotation> scope)
Returns true if this scope is unproxiable
|
static <T> T |
justCreate(java.lang.Class<T> createMe,
ServiceLocatorImpl locator,
java.lang.String strategy)
Just creates the thing, doesn't try to do anything else
|
static void |
justInject(java.lang.Object injectMe,
ServiceLocatorImpl locator,
java.lang.String strategy)
Just creates the thing, doesn't try to do anything else
|
static void |
justPostConstruct(java.lang.Object postMe,
ServiceLocatorImpl locator,
java.lang.String strategy)
Post constructs the given object
|
static void |
justPreDestroy(java.lang.Object preMe,
ServiceLocatorImpl locator,
java.lang.String strategy)
Pre Destroys the given object
|
static java.lang.Class<?> |
loadClass(java.lang.String loadMe,
Descriptor fromMe,
Collector collector)
Loads the class using the loader from the given descriptor or the
classloader of the utilities class otherwise
|
static java.lang.Class<?> |
loadClass(java.lang.String implementation,
Injectee injectee)
Load the given class for the given injectee.
|
static boolean |
proxiesAvailable()
Returns true if the system can create proxies, false otherwise
|
static java.lang.Class<?> |
translatePrimitiveType(java.lang.Class<?> type)
Converts the type to its java form, or returns the original
|
static void |
validateSelfInjectees(ActiveDescriptor<?> givenDescriptor,
java.util.List<SystemInjecteeImpl> injectees,
Collector collector)
This method validates a list of injectees to ensure that any self injectees have
the proper set of requirements.
|
private static final java.lang.String USE_SOFT_REFERENCE_PROPERTY
static final boolean USE_SOFT_REFERENCE
private static final Utilities.AnnotationInformation DEFAULT_ANNOTATION_INFORMATION
private static final java.lang.String PROVIDE_METHOD
private static final java.util.HashSet<java.lang.String> NOT_INTERCEPTED
private static final Utilities.Interceptors EMTPY_INTERCEPTORS
private static java.lang.Boolean proxiesAvailable
public static ClassAnalyzer getClassAnalyzer(ServiceLocatorImpl sli, java.lang.String analyzerName, Collector errorCollector)
sli
- The ServiceLocator to search in. May not be nullanalyzerName
- The name of the analyzer (may be null for the default analyzer)errorCollector
- A non-null collector of exceptionspublic static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> implClass, ClassAnalyzer analyzer, Collector collector)
implClass
- The implementation class (not null)analyzer
- The analyzer (not null)collector
- A collector for errors (not null)public static java.util.Set<java.lang.reflect.Method> getInitMethods(java.lang.Class<?> implClass, ClassAnalyzer analyzer, Collector collector)
implClass
- the non-null impl classanalyzer
- the non-null analyzercollector
- for gathering errorspublic static java.util.Set<java.lang.reflect.Field> getInitFields(java.lang.Class<?> implClass, ClassAnalyzer analyzer, Collector collector)
implClass
- the non-null impl classanalyzer
- the non-null analyzercollector
- for gathering errorspublic static java.lang.reflect.Method getPostConstruct(java.lang.Class<?> implClass, ClassAnalyzer analyzer, Collector collector)
implClass
- The non-null implementation classanalyzer
- The non-null analyzercollector
- The non-null error collectorpublic static java.lang.reflect.Method getPreDestroy(java.lang.Class<?> implClass, ClassAnalyzer analyzer, Collector collector)
implClass
- The non-null implementation classanalyzer
- The non-null analyzercollector
- The non-null error collectorpublic static java.lang.Class<?> getFactoryAwareImplementationClass(ActiveDescriptor<?> descriptor)
descriptor
- The descriptor (reified and not null) that will be used to find the
implementationpublic static void checkLookupType(java.lang.Class<?> checkMe)
checkMe
- class to checkpublic static java.lang.Class<?> translatePrimitiveType(java.lang.Class<?> type)
type
- The type to convertpublic static void handleErrors(NarrowResults results, java.util.LinkedList<ErrorService> callThese)
results
- the resultscallThese
- the services to callpublic static java.lang.Class<?> loadClass(java.lang.String loadMe, Descriptor fromMe, Collector collector)
loadMe
- The fully qualified class namefromMe
- The descriptor to use for the loadercollector
- The error collector to fill in if this returns nullpublic static java.lang.Class<?> loadClass(java.lang.String implementation, Injectee injectee)
implementation
- the impl class name stringinjectee
- the injecteepublic static java.lang.Class<? extends java.lang.annotation.Annotation> getInjectionResolverType(ActiveDescriptor<?> desc)
desc
- The reified descriptor to find the injection resolution onprivate static java.lang.Class<?> getFactoryProductionClass(java.lang.Class<?> factoryClass)
factoryClass
- The non-null factory class. May not be nullMultiException
- if there was an error analyzing the classpublic static java.lang.reflect.Type getFactoryProductionType(java.lang.Class<?> factoryClass)
factoryClass
- The non-null factory class. May not be nullMultiException
- if there was an error analyzing the classpublic static void checkFactoryType(java.lang.Class<?> factoryClass, Collector collector)
factoryClass
- the class to checkcollector
- the exception collectorprivate static boolean hasContract(java.lang.Class<?> clazz)
private static java.util.Set<java.lang.reflect.Type> getAutoAdvertisedTypes(java.lang.reflect.Type t)
public static <T> AutoActiveDescriptor<T> createAutoDescriptor(java.lang.Class<T> clazz, ServiceLocatorImpl locator) throws MultiException, java.lang.IllegalArgumentException, java.lang.IllegalStateException
clazz
- The class to create the desciptor forlocator
- The service locator for whom we are creating thisMultiException
- if there was an error in the classjava.lang.IllegalArgumentException
- If the class is nulljava.lang.IllegalStateException
- If the name could not be determined from the Named annotationpublic static <T> AutoActiveDescriptor<T> createAutoFactoryDescriptor(java.lang.Class<T> parentClazz, ActiveDescriptor<?> factoryDescriptor, ServiceLocatorImpl locator) throws MultiException, java.lang.IllegalArgumentException, java.lang.IllegalStateException
parentClazz
- The class to create the desciptor forlocator
- The service locator for whom we are creating thisMultiException
- if there was an error in the classjava.lang.IllegalArgumentException
- If the class is nulljava.lang.IllegalStateException
- If the name could not be determined from the Named annotationpublic static void justPreDestroy(java.lang.Object preMe, ServiceLocatorImpl locator, java.lang.String strategy)
preMe
- pre destroys the thinglocator
- The non-null service locator associated with the operation (for finding the strategy)strategy
- The strategy to use for analyzing the classpublic static void justPostConstruct(java.lang.Object postMe, ServiceLocatorImpl locator, java.lang.String strategy)
postMe
- post constructs the thinglocator
- The non-null service locator associated with the operation (for finding the strategy)strategy
- The strategy to use for analyzing the classpublic static void justInject(java.lang.Object injectMe, ServiceLocatorImpl locator, java.lang.String strategy)
injectMe
- The object to inject intolocator
- The locator to find the injection points withstrategy
- The strategy to use for analyzing the classpublic static <T> T justCreate(java.lang.Class<T> createMe, ServiceLocatorImpl locator, java.lang.String strategy)
createMe
- The thing to createlocator
- The locator to find the injection points withstrategy
- The strategy to use for analyzing the classpublic static java.lang.Class<?>[] getInterfacesForProxy(java.util.Set<java.lang.reflect.Type> contracts)
contracts
- All of the advertised contractspublic static boolean isProxiableScope(java.lang.Class<? extends java.lang.annotation.Annotation> scope)
scope
- The scope annotation to testpublic static boolean isUnproxiableScope(java.lang.Class<? extends java.lang.annotation.Annotation> scope)
scope
- The scope annotation to testprivate static boolean isProxiable(ActiveDescriptor<?> desc, Injectee injectee)
desc
- A non-null, reified ActiveDescriptorinjectee
- The injectee where this is being injected if known,
or null if not knownpublic static <T> T getFirstThingInList(java.util.List<T> set)
set
- The set from which to get the first elementpublic static ActiveDescriptor<ServiceLocator> getLocatorDescriptor(ServiceLocator locator)
locator
- The service locator to get the ActiveDescriptor forpublic static ActiveDescriptor<InjectionResolver<javax.inject.Inject>> getThreeThirtyDescriptor(ServiceLocatorImpl locator)
locator
- The service locator to get the ActiveDescriptor forpublic static java.lang.reflect.Constructor<?> findProducerConstructor(java.lang.Class<?> annotatedType, ServiceLocatorImpl locator, Collector collector)
annotatedType
- The type to find the producer constructorlocator
- The service locator to use when analyzing constructorscollector
- The error collectorprivate static boolean isProperConstructor(java.lang.reflect.Constructor<?> c)
private static java.util.Set<java.lang.reflect.Constructor<?>> getAllConstructors(java.lang.Class<?> clazz)
clazz
- The class to find the constructors ofpublic static java.util.Set<java.lang.reflect.Method> findInitializerMethods(java.lang.Class<?> annotatedType, ServiceLocatorImpl locator, Collector errorCollector)
annotatedType
- The type to find the errors inlocator
- The locator to use when analyzing methodserrorCollector
- The collector to add errors topublic static java.lang.reflect.Method findPostConstruct(java.lang.Class<?> clazz, ServiceLocatorImpl locator, Collector collector)
clazz
- The class to search for the post constructcollector
- An error collectorpublic static java.lang.reflect.Method findPreDestroy(java.lang.Class<?> clazz, ServiceLocatorImpl locator, Collector collector)
clazz
- The class to search for the pre destroy methodcollector
- An error collectorpublic static java.util.Set<java.lang.reflect.Field> findInitializerFields(java.lang.Class<?> annotatedType, ServiceLocatorImpl locator, Collector errorCollector)
annotatedType
- The class to search for fieldslocator
- The locator to use when analyzing the classerrorCollector
- The error collectorstatic AnnotatedElementAnnotationInfo computeAEAI(java.lang.reflect.AnnotatedElement annotatedElement)
annotatedElement
- The raw annotated element that can be used to
calculate the information needed to determine the resolverprivate static boolean isProperMethod(java.lang.reflect.Method member)
private static boolean isProperField(java.lang.reflect.Field field)
public static boolean isAbstract(java.lang.reflect.Member member)
member
- The non-null member to testpublic static boolean isFinal(java.lang.reflect.Member member)
member
- The non-null member to testprivate static boolean isFinal(java.lang.Class<?> clazz)
private static ScopeInfo getScopeInfo(java.lang.reflect.AnnotatedElement annotatedGuy, Descriptor defaultScope, Collector collector)
public static java.lang.Class<? extends java.lang.annotation.Annotation> getScopeAnnotationType(java.lang.Class<?> fromThis, Descriptor defaultScope)
fromThis
- The annotated class or producer methoddefaultScope
- The default scope if none other can be foundpublic static ScopeInfo getScopeAnnotationType(java.lang.reflect.AnnotatedElement annotatedGuy, Descriptor defaultScope, Collector collector)
annotatedGuy
- The annotated class or producer methoddefaultScope
- The default scope if none other can be foundcollector
- The error collectorprivate static java.lang.annotation.Annotation internalGetScopeAnnotationType(java.lang.reflect.AnnotatedElement annotatedGuy, Collector collector)
public static java.lang.reflect.Method getFactoryProvideMethod(java.lang.Class<?> clazz)
clazz
- This class must implement factorypublic static java.lang.String getDefaultNameFromMethod(java.lang.reflect.Method parent, Collector collector)
parent
- The parent annotated elementcollector
- For errorspublic static java.util.Set<java.lang.annotation.Annotation> getAllQualifiers(java.lang.reflect.AnnotatedElement annotatedGuy, java.lang.String name, Collector collector)
annotatedGuy
- The element we are searching for qualifiersname
- The name this element must havecollector
- The error collectorprivate static Utilities.AnnotationInformation getParamInformation(java.lang.annotation.Annotation[] memberAnnotations)
public static java.util.List<SystemInjecteeImpl> getConstructorInjectees(java.lang.reflect.Constructor<?> c, ActiveDescriptor<?> injecteeDescriptor)
c
- The constructor to analyzeinjecteeDescriptor
- The descriptor of the injecteepublic static java.util.List<SystemInjecteeImpl> getMethodInjectees(java.lang.Class<?> actualClass, java.lang.reflect.Method c, ActiveDescriptor<?> injecteeDescriptor)
c
- The constructor to analyzeinjecteeDescriptor
- The descriptor of the injecteeprivate static java.util.Set<java.lang.annotation.Annotation> getFieldAdjustedQualifierAnnotations(java.lang.reflect.Field f, java.util.Set<java.lang.annotation.Annotation> qualifiers)
public static java.util.List<SystemInjecteeImpl> getFieldInjectees(java.lang.Class<?> actualClass, java.lang.reflect.Field f, ActiveDescriptor<?> injecteeDescriptor)
f
- The field to analyzeinjecteeDescriptor
- The descriptor of the injecteepublic static void validateSelfInjectees(ActiveDescriptor<?> givenDescriptor, java.util.List<SystemInjecteeImpl> injectees, Collector collector)
givenDescriptor
- The descriptor associated with this injectee, or null if there are noneinjectees
- The list of injectees to check. Only self injectees are validatescollector
- The collector to add any errors topublic static java.util.Set<java.lang.annotation.Annotation> fixAndCheckQualifiers(java.lang.annotation.Annotation[] qualifiers, java.lang.String name)
qualifiers
- The qualifiers to convert. May not be null, but
may be zero lengthname
- The name this set of qualifiers must havepublic static <T> T createService(ActiveDescriptor<T> root, Injectee injectee, ServiceLocatorImpl locator, ServiceHandle<T> handle, java.lang.Class<?> requestedClass)
root
- The ultimate parent of this operationinjectee
- the injectee we are creating this service forlocator
- The locator to use to find serviceshandle
- The ServiceHandle (or null if there is none)requestedClass
- The class for the service we are looking forstatic Utilities.Interceptors getAllInterceptors(ServiceLocatorImpl impl, ActiveDescriptor<?> descriptor, java.lang.Class<?> clazz, java.lang.reflect.Constructor<?> c)
public static boolean isTypeSafe(java.lang.reflect.Type requiredType, java.lang.reflect.Type beanType)
requiredType
- The type this must conform tobeanType
- The type of the bean we are checkingpublic static boolean proxiesAvailable()