public class Utilities
extends java.lang.Object
| Constructor and Description |
|---|
Utilities() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
cast(java.lang.Object o)
Casts this thing to the given type
|
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
|
static <T> ActiveDescriptor<T> |
createAutoDescriptor(java.lang.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,
java.lang.Class<?> requestedClass) |
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,
Collector collector)
Finds the post construct method on this class
|
static java.lang.reflect.Method |
findPreDestroy(java.lang.Class<?> clazz,
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.
|
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
|
static java.lang.String |
getAutoAnalyzerName(java.lang.Class<?> c)
Gets the analyzer name from the Service annotation
|
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<Injectee> |
getConstructorInjectees(java.lang.reflect.Constructor<?> c)
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.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
|
static java.util.List<Injectee> |
getFieldInjectees(java.lang.reflect.Field f)
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.lang.reflect.Type |
getFirstTypeArgument(java.lang.reflect.Type type)
Gets the first type argument if this is a parameterized
type, otherwise it returns Object.class
|
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 InjectionResolver<?> |
getInjectionResolver(ServiceLocatorImpl locator,
java.lang.reflect.AnnotatedElement annotatedGuy)
Returns an injection resolver for this AnnotatedElement.
|
static InjectionResolver<?> |
getInjectionResolver(ServiceLocatorImpl locator,
Injectee injectee)
Returns an injection resolver for the injectee
|
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<Injectee> |
getMethodInjectees(java.lang.reflect.Method c)
Returns all the injectees for a constructor
|
static java.lang.String |
getNameFromAllQualifiers(java.util.Set<java.lang.annotation.Annotation> qualifiers,
java.lang.reflect.AnnotatedElement parent)
Gets the name from the &46;Named qualifier in this set of qualifiers
|
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 java.lang.Class<? extends java.lang.annotation.Annotation> |
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
|
static ActiveDescriptor<InjectionResolver<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
|
static boolean |
isAbstract(java.lang.reflect.Member member)
Returns true if the underlying member is abstract
|
static boolean |
isFinal(java.lang.reflect.Member member)
Returns true if the underlying member is abstract
|
static boolean |
isPrivate(java.lang.reflect.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(java.lang.Class<? extends java.lang.annotation.Annotation> scope)
Returns true if this scope is proxiable
|
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 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<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, 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)public 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 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 onpublic 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 collectorpublic static <T> ActiveDescriptor<T> createAutoDescriptor(java.lang.Class<T> clazz, ServiceLocatorImpl locator) throws MultiException, java.lang.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 classjava.lang.IllegalArgumentException - If the class is nullpublic static void justPreDestroy(java.lang.Object preMe,
ServiceLocatorImpl locator,
java.lang.String strategy)
preMe - pre destroys the thingpublic static void justPostConstruct(java.lang.Object postMe,
ServiceLocatorImpl locator,
java.lang.String strategy)
postMe - post constructs the thingpublic 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 withpublic 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 withpublic 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 testpublic static boolean isProxiable(ActiveDescriptor<?> desc)
desc - A non-null, reified ActiveDescriptorpublic 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<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 collectorpublic static java.lang.reflect.Type getFirstTypeArgument(java.lang.reflect.Type type)
type - The type to find the first type argument onpublic 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.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 collectorpublic static boolean isPrivate(java.lang.reflect.Member member)
member - The non-null member to testpublic 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 testpublic static java.lang.String getAutoAnalyzerName(java.lang.Class<?> c)
c - The class to get the analyzer name frompublic static java.lang.Class<? extends java.lang.annotation.Annotation> getScopeAnnotationType(java.lang.Class<?> fromThis,
Descriptor defaultScope)
fromThis - The annotated class or producer methodpublic static java.lang.Class<? extends java.lang.annotation.Annotation> getScopeAnnotationType(java.lang.reflect.AnnotatedElement annotatedGuy,
Descriptor defaultScope,
Collector collector)
annotatedGuy - The annotated class or producer methodcollector - The error collectorpublic static InjectionResolver<?> getInjectionResolver(ServiceLocatorImpl locator, Injectee injectee) throws java.lang.IllegalStateException
locator - The locator to use when finding the resolverinjectee - Injectee from which the annotation should be extractedjava.lang.IllegalStateException - If we could not find a valid resolverpublic static InjectionResolver<?> getInjectionResolver(ServiceLocatorImpl locator, java.lang.reflect.AnnotatedElement annotatedGuy) throws java.lang.IllegalStateException
locator - The locator to use when finding the resolverannotatedGuy - The annotated class or producer methodjava.lang.IllegalStateException - If we could not find a valid resolverpublic static java.lang.reflect.Method getFactoryProvideMethod(java.lang.Class<?> clazz)
clazz - This class must implement factorypublic static java.lang.String getNameFromAllQualifiers(java.util.Set<java.lang.annotation.Annotation> qualifiers,
java.lang.reflect.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 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 collectorpublic static java.util.List<Injectee> getConstructorInjectees(java.lang.reflect.Constructor<?> c)
c - The constructor to analyzepublic static java.util.List<Injectee> getMethodInjectees(java.lang.reflect.Method c)
c - The constructor to analyzepublic static java.util.List<Injectee> getFieldInjectees(java.lang.reflect.Field f)
f - The field to analyzepublic static void validateSelfInjectees(ActiveDescriptor<?> givenDescriptor, java.util.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 java.lang.reflect.Method findPostConstruct(java.lang.Class<?> clazz,
Collector collector)
clazz - The class to search for the post constructcollector - An error collectorpublic static java.lang.reflect.Method findPreDestroy(java.lang.Class<?> clazz,
Collector collector)
clazz - The class to search for the pre destroy methodcollector - An error collectorpublic 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 cast(java.lang.Object o)
o - The thing to castpublic static <T> T createService(ActiveDescriptor<T> root, Injectee injectee, ServiceLocatorImpl locator, ServiceHandle<T> handle, java.lang.Class<?> requestedClass)
Copyright © 2013 Oracle Corporation. All Rights Reserved.