public class Utilities extends Object
Constructor and Description |
---|
Utilities() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
cast(Object o)
Casts this thing to the given type
|
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> ActiveDescriptor<T> |
createAutoDescriptor(Class<T> clazz,
ServiceLocatorImpl locator)
Creates a reified automatically generated descriptor
|
static <T> T |
createService(ActiveDescriptor<T> root,
Injectee injectee,
ServiceLocatorImpl locator,
ServiceHandle<T> handle,
Class<?> requestedClass) |
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,
Collector collector)
Finds the post construct method on this class
|
static Method |
findPreDestroy(Class<?> clazz,
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 String |
getAutoAnalyzerName(Class<?> c)
Gets the analyzer name from the Service annotation
|
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<Injectee> |
getConstructorInjectees(Constructor<?> c)
Returns all the injectees for a constructor
|
static String |
getDefaultNameFromMethod(Method parent,
Collector collector)
Returns the default name if one can be found.
|
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<Injectee> |
getFieldInjectees(Field f)
Returns the injectees for a field
|
static <T> T |
getFirstThingInList(List<T> set)
Returns the first thing found in the set
|
static Type |
getFirstTypeArgument(Type type)
Gets the first type argument if this is a parameterized
type, otherwise it returns Object.class
|
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 InjectionResolver<?> |
getInjectionResolver(ServiceLocatorImpl locator,
AnnotatedElement annotatedGuy)
Returns an injection resolver for this AnnotatedElement.
|
static InjectionResolver<?> |
getInjectionResolver(ServiceLocatorImpl locator,
Injectee injectee)
Returns an injection resolver for the injectee
|
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<Injectee> |
getMethodInjectees(Method c)
Returns all the injectees for a constructor
|
static String |
getNameFromAllQualifiers(Set<Annotation> qualifiers,
AnnotatedElement parent)
Gets the name from the &46;Named qualifier in this set of qualifiers
|
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 Class<? extends Annotation> |
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 |
isPrivate(Member member)
Returns true if the underlying member is private
|
static boolean |
isProxiable(ActiveDescriptor<?> desc)
This method determines whether or not the descriptor should be proxied.
|
static boolean |
isProxiableScope(Class<? extends Annotation> scope)
Returns true if this scope is proxiable
|
static boolean |
isUnproxiableScope(Class<? extends Annotation> scope)
Returns true if this scope is unproxiable
|
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 creates 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 Class<?> |
translatePrimitiveType(Class<?> type)
Converts the type to its java form, or returns the original
|
static void |
validateSelfInjectees(ActiveDescriptor<?> givenDescriptor,
List<Injectee> 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)public 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 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> ActiveDescriptor<T> createAutoDescriptor(Class<T> clazz, ServiceLocatorImpl locator) throws MultiException, IllegalArgumentException
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 nullpublic static void justPreDestroy(Object preMe, ServiceLocatorImpl locator, String strategy)
preMe
- pre destroys the thingpublic static void justPostConstruct(Object postMe, ServiceLocatorImpl locator, String strategy)
postMe
- post constructs the thingpublic static void justInject(Object injectMe, ServiceLocatorImpl locator, String strategy)
injectMe
- The object to inject intolocator
- The locator to find the injection points withpublic static <T> T justCreate(Class<T> createMe, ServiceLocatorImpl locator, String strategy)
createMe
- The thing to createlocator
- The locator to find the injection points withpublic 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 boolean isProxiable(ActiveDescriptor<?> desc)
desc
- A non-null, reified ActiveDescriptorpublic 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 Type getFirstTypeArgument(Type type)
type
- The type to find the first type argument onpublic 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 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 isPrivate(Member member)
member
- The non-null member to testpublic 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 String getAutoAnalyzerName(Class<?> c)
c
- The class to get the analyzer name frompublic static Class<? extends Annotation> getScopeAnnotationType(Class<?> fromThis, Descriptor defaultScope)
fromThis
- The annotated class or producer methodpublic static Class<? extends Annotation> getScopeAnnotationType(AnnotatedElement annotatedGuy, Descriptor defaultScope, Collector collector)
annotatedGuy
- The annotated class or producer methodcollector
- The error collectorpublic static InjectionResolver<?> getInjectionResolver(ServiceLocatorImpl locator, Injectee injectee) throws IllegalStateException
locator
- The locator to use when finding the resolverinjectee
- Injectee from which the annotation should be extractedIllegalStateException
- If we could not find a valid resolverpublic static InjectionResolver<?> getInjectionResolver(ServiceLocatorImpl locator, AnnotatedElement annotatedGuy) throws IllegalStateException
locator
- The locator to use when finding the resolverannotatedGuy
- The annotated class or producer methodIllegalStateException
- If we could not find a valid resolverpublic static Method getFactoryProvideMethod(Class<?> clazz)
clazz
- This class must implement factorypublic static String getNameFromAllQualifiers(Set<Annotation> qualifiers, AnnotatedElement parent)
qualifiers
- The set of qualifiers that may or may not have Named in itparent
- The parent element for which we are searchingpublic 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<Injectee> getConstructorInjectees(Constructor<?> c)
c
- The constructor to analyzepublic static List<Injectee> getMethodInjectees(Method c)
c
- The constructor to analyzepublic static List<Injectee> getFieldInjectees(Field f)
f
- The field to analyzepublic static void validateSelfInjectees(ActiveDescriptor<?> givenDescriptor, List<Injectee> 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 Method findPostConstruct(Class<?> clazz, Collector collector)
clazz
- The class to search for the post constructcollector
- An error collectorpublic static Method findPreDestroy(Class<?> clazz, Collector collector)
clazz
- The class to search for the pre destroy methodcollector
- An error collectorpublic 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 cast(Object o)
o
- The thing to castpublic static <T> T createService(ActiveDescriptor<T> root, Injectee injectee, ServiceLocatorImpl locator, ServiceHandle<T> handle, Class<?> requestedClass)
Copyright © 2013 Oracle Corporation. All rights reserved.