public class Utilities extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
Utilities.Interceptors
The return type from getAllInterceptors
|
Constructor and Description |
---|
Utilities() |
Modifier and Type | Method and Description |
---|---|
static void |
checkFactoryType(Class<?> factoryClass,
Collector collector)
Checks to be sure the Factory class is ok
|
static void |
checkLookupType(Class<?> checkMe)
Checks that the incoming lookup type is not improper in some way
|
static <T> AutoActiveDescriptor<T> |
createAutoDescriptor(Class<T> clazz,
ServiceLocatorImpl locator)
Creates a reified automatically generated descriptor
|
static <T> AutoActiveDescriptor<T> |
createAutoFactoryDescriptor(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,
Class<?> requestedClass)
Creates the service (without the need for an intermediate ServiceHandle
to be created)
|
static Set<Field> |
findInitializerFields(Class<?> annotatedType,
ServiceLocatorImpl locator,
Collector errorCollector)
Will find all the initialize fields in the class
|
static Set<Method> |
findInitializerMethods(Class<?> annotatedType,
ServiceLocatorImpl locator,
Collector errorCollector)
Get all the initializer methods of the annotatedType.
|
static Method |
findPostConstruct(Class<?> clazz,
ServiceLocatorImpl locator,
Collector collector)
Finds the post construct method on this class
|
static Method |
findPreDestroy(Class<?> clazz,
ServiceLocatorImpl locator,
Collector collector)
Finds the pre destroy method on this class
|
static Constructor<?> |
findProducerConstructor(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 Set<Annotation> |
fixAndCheckQualifiers(Annotation[] qualifiers,
String name)
This method returns a set of qualifiers from an array of qualifiers.
|
static Set<Annotation> |
getAllQualifiers(AnnotatedElement annotatedGuy,
String name,
Collector collector)
Returns the full set of qualifier annotations on this class
|
static ClassAnalyzer |
getClassAnalyzer(ServiceLocatorImpl sli,
String analyzerName,
Collector errorCollector)
Returns the class analyzer with the given name
|
static <T> Constructor<T> |
getConstructor(Class<T> implClass,
ClassAnalyzer analyzer,
Collector collector)
Gets the constructor given the implClass and analyzer.
|
static List<SystemInjecteeImpl> |
getConstructorInjectees(Constructor<?> c,
ActiveDescriptor<?> injecteeDescriptor)
Returns all the injectees for a constructor
|
static String |
getDefaultNameFromMethod(Method parent,
Collector collector)
Returns the default name if one can be found.
|
static Class<?> |
getFactoryAwareImplementationClass(ActiveDescriptor<?> descriptor)
This utility will return the proper implementation class, taking into account that the
descriptor may be a factory
|
static Type |
getFactoryProductionType(Class<?> factoryClass)
This method returns the type produced by a factory class
|
static Method |
getFactoryProvideMethod(Class<?> clazz)
This method will retrieve the provide method from a Factory
|
static List<SystemInjecteeImpl> |
getFieldInjectees(Class<?> actualClass,
Field f,
ActiveDescriptor<?> injecteeDescriptor)
Returns the injectees for a field
|
static <T> T |
getFirstThingInList(List<T> set)
Returns the first thing found in the set
|
static Set<Field> |
getInitFields(Class<?> implClass,
ClassAnalyzer analyzer,
Collector collector)
Gets the initializer fields from the given class and analyzer.
|
static Set<Method> |
getInitMethods(Class<?> implClass,
ClassAnalyzer analyzer,
Collector collector)
Gets the initializer methods from the given class and analyzer.
|
static Class<? extends 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 Class<?>[] |
getInterfacesForProxy(Set<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 List<SystemInjecteeImpl> |
getMethodInjectees(Class<?> actualClass,
Method c,
ActiveDescriptor<?> injecteeDescriptor)
Returns all the injectees for a constructor
|
static List<SystemInjecteeImpl> |
getMethodInjectees(Class<?> actualClass,
Method c,
ActiveDescriptor<?> injecteeDescriptor,
Map<Integer,MethodParameter> knownValues)
Returns all the injectees for a constructor
|
static Method |
getPostConstruct(Class<?> implClass,
ClassAnalyzer analyzer,
Collector collector)
Gets the post construct from the analyzer, checking output
|
static Method |
getPreDestroy(Class<?> implClass,
ClassAnalyzer analyzer,
Collector collector)
Gets the preDestroy from the analyzer, checking output
|
static ScopeInfo |
getScopeAnnotationType(AnnotatedElement annotatedGuy,
Descriptor defaultScope,
Collector collector)
Returns the scope of this thing
|
static Class<? extends Annotation> |
getScopeAnnotationType(Class<?> fromThis,
Descriptor defaultScope)
Returns the scope of this thing
|
static ActiveDescriptor<InjectionResolver<javax.inject.Inject>> |
getThreeThirtyDescriptor(ServiceLocatorImpl locator)
Creates a Three Thirty constant active descriptor
|
static void |
handleErrors(NarrowResults results,
LinkedList<ErrorService> callThese)
Calls the list of error services for the list of errors
|
static boolean |
isAbstract(Member member)
Returns true if the underlying member is abstract
|
static boolean |
isFinal(Member member)
Returns true if the underlying member is abstract
|
static boolean |
isProxiableScope(Class<? extends Annotation> scope)
Returns true if this scope is proxiable
|
static boolean |
isTypeSafe(Type requiredType,
Type beanType)
This code uses the TypeChecker but does some extra checking if
the types are annotations
|
static boolean |
isUnproxiableScope(Class<? extends Annotation> scope)
Returns true if this scope is unproxiable
|
static Object |
justAssistedInject(Object injectMe,
Method method,
ServiceLocatorImpl locator,
ServiceHandle<?> root,
MethodParameter... givenValues)
Just injects this one method
|
static <T> T |
justCreate(Class<T> createMe,
ServiceLocatorImpl locator,
String strategy)
Just creates the thing, doesn't try to do anything else
|
static void |
justInject(Object injectMe,
ServiceLocatorImpl locator,
String strategy)
Just injects the thing, doesn't try to do anything else
|
static void |
justPostConstruct(Object postMe,
ServiceLocatorImpl locator,
String strategy)
Post constructs the given object
|
static void |
justPreDestroy(Object preMe,
ServiceLocatorImpl locator,
String strategy)
Pre Destroys the given object
|
static Class<?> |
loadClass(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 Class<?> |
loadClass(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 Class<?> |
translatePrimitiveType(Class<?> type)
Converts the type to its java form, or returns the original
|
static void |
validateSelfInjectees(ActiveDescriptor<?> givenDescriptor,
List<SystemInjecteeImpl> injectees,
Collector collector)
This method validates a list of injectees to ensure that any self injectees have
the proper set of requirements.
|
public static ClassAnalyzer getClassAnalyzer(ServiceLocatorImpl sli, 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> Constructor<T> getConstructor(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 Set<Method> getInitMethods(Class<?> implClass, ClassAnalyzer analyzer, Collector collector)
implClass
- the non-null impl classanalyzer
- the non-null analyzercollector
- for gathering errorspublic static Set<Field> getInitFields(Class<?> implClass, ClassAnalyzer analyzer, Collector collector)
implClass
- the non-null impl classanalyzer
- the non-null analyzercollector
- for gathering errorspublic static Method getPostConstruct(Class<?> implClass, ClassAnalyzer analyzer, Collector collector)
implClass
- The non-null implementation classanalyzer
- The non-null analyzercollector
- The non-null error collectorpublic static Method getPreDestroy(Class<?> implClass, ClassAnalyzer analyzer, Collector collector)
implClass
- The non-null implementation classanalyzer
- The non-null analyzercollector
- The non-null error collectorpublic static Class<?> getFactoryAwareImplementationClass(ActiveDescriptor<?> descriptor)
descriptor
- The descriptor (reified and not null) that will be used to find the
implementationpublic static void checkLookupType(Class<?> checkMe)
checkMe
- class to checkpublic static Class<?> translatePrimitiveType(Class<?> type)
type
- The type to convertpublic static void handleErrors(NarrowResults results, LinkedList<ErrorService> callThese)
results
- the resultscallThese
- the services to callpublic static Class<?> loadClass(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 Class<?> loadClass(String implementation, Injectee injectee)
implementation
- the impl class name stringinjectee
- the injecteepublic static Class<? extends Annotation> getInjectionResolverType(ActiveDescriptor<?> desc)
desc
- The reified descriptor to find the injection resolution onpublic static Type getFactoryProductionType(Class<?> factoryClass)
factoryClass
- The non-null factory class. May not be nullMultiException
- if there was an error analyzing the classpublic static void checkFactoryType(Class<?> factoryClass, Collector collector)
factoryClass
- the class to checkcollector
- the exception collectorpublic static <T> AutoActiveDescriptor<T> createAutoDescriptor(Class<T> clazz, ServiceLocatorImpl locator) throws MultiException, IllegalArgumentException, 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 classIllegalArgumentException
- If the class is nullIllegalStateException
- If the name could not be determined from the Named annotationpublic static <T> AutoActiveDescriptor<T> createAutoFactoryDescriptor(Class<T> parentClazz, ActiveDescriptor<?> factoryDescriptor, ServiceLocatorImpl locator) throws MultiException, IllegalArgumentException, 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 classIllegalArgumentException
- If the class is nullIllegalStateException
- If the name could not be determined from the Named annotationpublic static void justPreDestroy(Object preMe, ServiceLocatorImpl locator, 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(Object postMe, ServiceLocatorImpl locator, 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 Object justAssistedInject(Object injectMe, Method method, ServiceLocatorImpl locator, ServiceHandle<?> root, MethodParameter... givenValues)
injectMe
- method
- locator
- givenValues
- public static void justInject(Object injectMe, ServiceLocatorImpl locator, 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(Class<T> createMe, ServiceLocatorImpl locator, String strategy)
createMe
- The thing to createlocator
- The locator to find the injection points withstrategy
- The strategy to use for analyzing the classpublic static Class<?>[] getInterfacesForProxy(Set<Type> contracts)
contracts
- All of the advertised contractspublic static boolean isProxiableScope(Class<? extends Annotation> scope)
scope
- The scope annotation to testpublic static boolean isUnproxiableScope(Class<? extends Annotation> scope)
scope
- The scope annotation to testpublic static <T> T getFirstThingInList(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 Constructor<?> findProducerConstructor(Class<?> annotatedType, ServiceLocatorImpl locator, Collector collector)
annotatedType
- The type to find the producer constructorlocator
- The service locator to use when analyzing constructorscollector
- The error collectorpublic static Set<Method> findInitializerMethods(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 Method findPostConstruct(Class<?> clazz, ServiceLocatorImpl locator, Collector collector)
clazz
- The class to search for the post constructcollector
- An error collectorpublic static Method findPreDestroy(Class<?> clazz, ServiceLocatorImpl locator, Collector collector)
clazz
- The class to search for the pre destroy methodcollector
- An error collectorpublic static Set<Field> findInitializerFields(Class<?> annotatedType, ServiceLocatorImpl locator, Collector errorCollector)
annotatedType
- The class to search for fieldslocator
- The locator to use when analyzing the classerrorCollector
- The error collectorpublic static boolean isAbstract(Member member)
member
- The non-null member to testpublic static boolean isFinal(Member member)
member
- The non-null member to testpublic static Class<? extends Annotation> getScopeAnnotationType(Class<?> fromThis, Descriptor defaultScope)
fromThis
- The annotated class or producer methoddefaultScope
- The default scope if none other can be foundpublic static ScopeInfo getScopeAnnotationType(AnnotatedElement annotatedGuy, Descriptor defaultScope, Collector collector)
annotatedGuy
- The annotated class or producer methoddefaultScope
- The default scope if none other can be foundcollector
- The error collectorpublic static Method getFactoryProvideMethod(Class<?> clazz)
clazz
- This class must implement factorypublic static String getDefaultNameFromMethod(Method parent, Collector collector)
parent
- The parent annotated elementcollector
- For errorspublic static Set<Annotation> getAllQualifiers(AnnotatedElement annotatedGuy, String name, Collector collector)
annotatedGuy
- The element we are searching for qualifiersname
- The name this element must havecollector
- The error collectorpublic static List<SystemInjecteeImpl> getConstructorInjectees(Constructor<?> c, ActiveDescriptor<?> injecteeDescriptor)
c
- The constructor to analyzeinjecteeDescriptor
- The descriptor of the injecteepublic static List<SystemInjecteeImpl> getMethodInjectees(Class<?> actualClass, Method c, ActiveDescriptor<?> injecteeDescriptor)
c
- The constructor to analyzeinjecteeDescriptor
- The descriptor of the injecteepublic static List<SystemInjecteeImpl> getMethodInjectees(Class<?> actualClass, Method c, ActiveDescriptor<?> injecteeDescriptor, Map<Integer,MethodParameter> knownValues)
c
- The constructor to analyzeinjecteeDescriptor
- The descriptor of the injecteepublic static List<SystemInjecteeImpl> getFieldInjectees(Class<?> actualClass, Field f, ActiveDescriptor<?> injecteeDescriptor)
f
- The field to analyzeinjecteeDescriptor
- The descriptor of the injecteepublic static void validateSelfInjectees(ActiveDescriptor<?> givenDescriptor, 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 Set<Annotation> fixAndCheckQualifiers(Annotation[] qualifiers, 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, 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 forpublic static boolean isTypeSafe(Type requiredType, Type beanType)
requiredType
- The type this must conform tobeanType
- The type of the bean we are checkingpublic static boolean proxiesAvailable()
Copyright © 2009-2017, Oracle and/or its affiliates. All Rights Reserved.