|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jvnet.hk2.internal.Utilities
public class Utilities
This class contains a set of static utilities useful for implementing HK2
| Constructor Summary | |
|---|---|
Utilities()
|
|
| Method Summary | ||
|---|---|---|
static
|
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
|
createAutoDescriptor(java.lang.Class<T> clazz,
ServiceLocatorImpl locator)
Creates a reified automatically generated descriptor |
|
static
|
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)
Returns the class analyzer with the given name |
|
static
|
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
|
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
|
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. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Utilities()
| Method Detail |
|---|
public static ClassAnalyzer getClassAnalyzer(ServiceLocatorImpl sli,
java.lang.String analyzerName)
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 errors
public 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 errors
public 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 collector
public 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 collector
public static void checkLookupType(java.lang.Class<?> checkMe)
checkMe - class to checkpublic static java.lang.Class<?> translatePrimitiveType(java.lang.Class<?> type)
type - The type to convert
public static void handleErrors(NarrowResults results,
java.util.LinkedList<ErrorService> callThese)
results - the resultscallThese - the services to call
public 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 null
public static java.lang.Class<?> loadClass(java.lang.String implementation,
Injectee injectee)
implementation - the impl class name stringinjectee - the injectee
public static java.lang.Class<? extends java.lang.annotation.Annotation> getInjectionResolverType(ActiveDescriptor<?> desc)
desc - The reified descriptor to find the injection resolution on
public static java.lang.reflect.Type getFactoryProductionType(java.lang.Class<?> factoryClass)
factoryClass - The non-null factory class. May not be null
MultiException - if there was an error analyzing the class
public static void checkFactoryType(java.lang.Class<?> factoryClass,
Collector collector)
factoryClass - the class to checkcollector - the exception collector
public 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 this
MultiException - if there was an error in the class
java.lang.IllegalArgumentException - If the class is null
public static void justPreDestroy(java.lang.Object preMe,
ServiceLocatorImpl locator,
java.lang.String strategy)
preMe - pre destroys the thing
public static void justPostConstruct(java.lang.Object postMe,
ServiceLocatorImpl locator,
java.lang.String strategy)
postMe - post constructs the thing
public 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 with
public 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 with
public static java.lang.Class<?>[] getInterfacesForProxy(java.util.Set<java.lang.reflect.Type> contracts)
contracts - All of the advertised contracts
public static boolean isProxiableScope(java.lang.Class<? extends java.lang.annotation.Annotation> scope)
scope - The scope annotation to test
public static boolean isUnproxiableScope(java.lang.Class<? extends java.lang.annotation.Annotation> scope)
scope - The scope annotation to test
public static boolean isProxiable(ActiveDescriptor<?> desc)
desc - A non-null, reified ActiveDescriptor
public static <T> T getFirstThingInList(java.util.List<T> set)
set - The set from which to get the first element
public static ActiveDescriptor<ServiceLocator> getLocatorDescriptor(ServiceLocator locator)
locator - The service locator to get the ActiveDescriptor for
public static ActiveDescriptor<InjectionResolver<Inject>> getThreeThirtyDescriptor(ServiceLocatorImpl locator)
locator - The service locator to get the ActiveDescriptor for
public 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 collector
public static java.lang.reflect.Type getFirstTypeArgument(java.lang.reflect.Type type)
type - The type to find the first type argument on
public 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 to
public 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 collector
public static boolean isPrivate(java.lang.reflect.Member member)
member - The non-null member to test
public static boolean isAbstract(java.lang.reflect.Member member)
member - The non-null member to test
public static boolean isFinal(java.lang.reflect.Member member)
member - The non-null member to test
public static java.lang.String getAutoAnalyzerName(java.lang.Class<?> c)
c - The class to get the analyzer name from
public static java.lang.Class<? extends java.lang.annotation.Annotation> getScopeAnnotationType(java.lang.Class<?> fromThis,
Descriptor defaultScope)
fromThis - The annotated class or producer method
public 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 collector
public 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 extracted
java.lang.IllegalStateException - If we could not find a valid resolver
public 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 method
java.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 factory
public 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 searching
public static java.lang.String getDefaultNameFromMethod(java.lang.reflect.Method parent,
Collector collector)
parent - The parent annotated elementcollector - For errors
public 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 collector
public static java.util.List<Injectee> getConstructorInjectees(java.lang.reflect.Constructor<?> c)
c - The constructor to analyze
public static java.util.List<Injectee> getMethodInjectees(java.lang.reflect.Method c)
c - The constructor to analyze
public static java.util.List<Injectee> getFieldInjectees(java.lang.reflect.Field f)
f - The field to analyze
public 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 to
public static java.lang.reflect.Method findPostConstruct(java.lang.Class<?> clazz,
Collector collector)
clazz - The class to search for the post constructcollector - An error collector
public static java.lang.reflect.Method findPreDestroy(java.lang.Class<?> clazz,
Collector collector)
clazz - The class to search for the pre destroy methodcollector - An error collector
public 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 have
public static <T> T cast(java.lang.Object o)
o - The thing to cast
public static <T> T createService(ActiveDescriptor<T> root,
Injectee injectee,
ServiceLocatorImpl locator,
ServiceHandle<T> handle,
java.lang.Class<?> requestedClass)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||