|
||||||||||
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(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
|
createAutoDescriptor(Class<T> clazz,
ServiceLocatorImpl locator)
Creates a reified automatically generated descriptor |
|
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 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 Class<?> |
getFactoryAwareImplementationClass(ActiveDescriptor<?> descriptor)
This utility will return the proper implementation class, taking into account that the descriptor may be a factory |
|
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
|
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 InjectionResolver<?> |
getInjectionResolver(ServiceLocatorImpl locator,
AnnotatedElement annotatedGuy)
Returns an injection resolver for this AnnotatedElement |
|
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 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 |
isProxiableScope(Class<? extends Annotation> scope)
Returns true if this scope is proxiable |
|
static
|
justCreate(Class<T> createMe,
ServiceLocatorImpl locator)
Just creates the thing, doesn't try to do anything else |
|
static void |
justInject(Object injectMe,
ServiceLocatorImpl locator)
Just creates the thing, doesn't try to do anything else |
|
static void |
justPostConstruct(Object postMe)
Post constructs the given object |
|
static void |
justPreDestroy(Object preMe)
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 Object |
makeMe(Constructor<?> c,
Object[] args)
This version of invoke is CCL neutral (it will return with the same CCL as what it went in with) |
|
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. |
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 Class<?> getFactoryAwareImplementationClass(ActiveDescriptor<?> descriptor)
descriptor
- The descriptor (reified and not null) that will be used to find the
implementation
public static void checkLookupType(Class<?> checkMe)
checkMe
- class to checkpublic static Class<?> translatePrimitiveType(Class<?> type)
type
- The type to convert
public 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 null
public static Class<?> loadClass(String implementation, Injectee injectee)
implementation
- the impl class name stringinjectee
- the injectee
public static Class<? extends Annotation> getInjectionResolverType(ActiveDescriptor<?> desc)
desc
- The reified descriptor to find the injection resolution on
public 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 this
MultiException
- if there was an error in the class
IllegalArgumentException
- If the class is nullpublic static void justPreDestroy(Object preMe)
preMe
- pre destroys the thingpublic static void justPostConstruct(Object postMe)
postMe
- post constructs the thingpublic static void justInject(Object injectMe, ServiceLocatorImpl locator)
injectMe
- The object to inject intolocator
- The locator to find the injection points withpublic static <T> T justCreate(Class<T> createMe, ServiceLocatorImpl locator)
createMe
- The thing to createlocator
- The locator to find the injection points with
public static Class<?>[] getInterfacesForProxy(Set<Type> contracts)
contracts
- All of the advertised contracts
public static boolean isProxiableScope(Class<? extends Annotation> scope)
scope
- The scope annotation to test
public static <T> T getFirstThingInList(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<javax.inject.Inject>> getThreeThirtyDescriptor(ServiceLocatorImpl locator)
locator
- The service locator to get the ActiveDescriptor for
public 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 collector
public static Type getFirstTypeArgument(Type type)
type
- The type to find the first type argument on
public 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 to
public 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 collector
public static boolean isPrivate(Member member)
member
- The non-null member to test
public static boolean isAbstract(Member member)
member
- The non-null member to test
public static boolean isFinal(Member member)
member
- The non-null member to test
public static Class<? extends Annotation> getScopeAnnotationType(Class<?> fromThis, Descriptor defaultScope)
fromThis
- The annotated class or producer method
public static Class<? extends Annotation> getScopeAnnotationType(AnnotatedElement annotatedGuy, Descriptor defaultScope, Collector collector)
annotatedGuy
- The annotated class or producer methodcollector
- The error collector
public static InjectionResolver<?> getInjectionResolver(ServiceLocatorImpl locator, AnnotatedElement annotatedGuy) throws IllegalStateException
locator
- The locator to use when finding the resolverannotatedGuy
- The annotated class or producer method
IllegalStateException
- If we could not find a valid resolverpublic static Method getFactoryProvideMethod(Class<?> clazz)
clazz
- This class must implement factory
public 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 searching
public static String getDefaultNameFromMethod(Method parent, Collector collector)
parent
- The parent annotated elementcollector
- For errors
public 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 collector
public static List<Injectee> getConstructorInjectees(Constructor<?> c)
c
- The constructor to analyze
public static List<Injectee> getMethodInjectees(Method c)
c
- The constructor to analyze
public static List<Injectee> getFieldInjectees(Field f)
f
- The field to analyze
public 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 collector
public static Method findPreDestroy(Class<?> clazz, Collector collector)
clazz
- The class to search for the pre destroy methodcollector
- An error collector
public static Object makeMe(Constructor<?> c, Object[] args) throws Throwable
c
- the constructor to callargs
- The arguments to invoke (may not be null)
Throwable
- The unwrapped throwable thrown by the methodpublic 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 have
public static <T> T cast(Object o)
o
- The thing to cast
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |