public final class ReflectionHelper extends Object
Constructor and Description |
---|
ReflectionHelper() |
Modifier and Type | Method and Description |
---|---|
static void |
addMetadata(Map<String,List<String>> metadatas,
String key,
String value)
Adds a value to the list of values associated with this key
|
static boolean |
annotationContainsAll(Set<Annotation> candidateAnnotations,
Set<Annotation> requiredAnnotations)
This is used to check on the annotation set.
|
static <T> T |
cast(Object o)
Casts this thing to the given type
|
static MethodWrapper |
createMethodWrapper(Method wrapMe)
Creates a method wrapper for the given method
|
static Map<String,List<String>> |
deepCopyMetadata(Map<String,List<String>> copyMe)
This method does a deep copy of the incoming meta-data, (which basically means we will
also make copies of the value list)
|
static Set<Type> |
getAdvertisedTypesFromClass(Type type,
Class<? extends Annotation> markerAnnotation)
Returns the set of types this class advertises
|
static Set<Type> |
getAdvertisedTypesFromObject(Object t,
Class<? extends Annotation> markerAnnotation)
Returns the set of types this class advertises
|
static Set<Type> |
getAllTypes(Type t) |
static Set<String> |
getContractsFromClass(Class<?> clazz,
Class<? extends Annotation> markerAnnotation)
Returns the set of types this class advertises
|
static Type |
getFirstTypeArgument(Type type)
Gets the first type argument if this is a parameterized
type, otherwise it returns Object.class
|
static String |
getName(Class<?> implClass)
Returns the name that should be associated with this class
|
static String |
getNameFromAllQualifiers(Set<Annotation> qualifiers,
AnnotatedElement parent)
Gets the name from the &46;Named qualifier in this set of qualifiers
|
static Set<Annotation> |
getQualifierAnnotations(AnnotatedElement annotatedGuy)
Gets all the qualifier annotations from the object
|
static Set<String> |
getQualifiersFromClass(Class<?> clazz)
Gets all the qualifiers from the object
|
static Set<Annotation> |
getQualifiersFromObject(Object t)
Gets all the qualifiers from the object
|
static Class<?> |
getRawClass(Type type)
Given the type parameter gets the raw type represented
by the type, or null if this has no associated raw class
|
static Annotation |
getScopeAnnotationFromClass(Class<?> clazz)
Gets the scope annotation from the object
|
static Annotation |
getScopeAnnotationFromObject(Object t)
Gets the scope annotation from the object
|
static Annotation |
getScopeFromClass(Class<?> clazz,
Annotation annoDefault)
Gets the scope annotation from the object
|
static Annotation |
getScopeFromObject(Object t,
Annotation annoDefault)
Gets the scope annotation from the object
|
static Set<Type> |
getTypeClosure(Type ofType,
Set<String> contracts)
Returns the type closure, as restricted by the classes listed in the
set of contracts implemented
|
static Object |
invoke(Object o,
Method m,
Object[] args,
boolean neutralCCL)
This version of invoke is CCL neutral (it will return with the
same CCL as what it went in with)
|
static boolean |
isAnnotationAQualifier(Annotation anno)
Returns true if the given annotation is a qualifier
|
static boolean |
isPrivate(Member member)
Returns true if the underlying member is private
|
static boolean |
isStatic(Member member)
Returns true if the underlying member is static
|
static Object |
makeMe(Constructor<?> c,
Object[] args,
boolean neutralCCL)
This version of invoke is CCL neutral (it will return with the
same CCL as what it went in with)
|
static void |
parseServiceMetadataString(String metadataField,
Map<String,List<String>> metadata)
This method parses the string that is found in the VService metadata field.
|
static void |
readMetadataMap(String line,
Map<String,List<String>> addToMe)
Writes a set in a way that can be read from an input stream as well
|
static void |
readSet(String line,
Collection<String> addToMe)
Writes a set in a way that can be read from an input stream as well.
|
static boolean |
removeAllMetadata(Map<String,List<String>> metadatas,
String key)
Removes all the metadata values associated with key
|
static boolean |
removeMetadata(Map<String,List<String>> metadatas,
String key,
String value)
Removes the given value from the given key
|
static Type |
resolveField(Class<?> topclass,
Field field)
Resolves the generic type of a field given the actual class being instantiated
|
static Type |
resolveKnownType(TypeVariable<?> userType,
ParameterizedType knownType,
Class<?> knownDeclaringClass)
If you have a class that declares type variables (knownDeclaringClass) and the type the user has told
us it should be (knownType) then return the replaced type for the given userType.
|
static Type |
resolveMember(Class<?> topclass,
Type lookingForType,
Class<?> declaringClass)
Resolves the generic type of a type and declaring class given the actual class being instantiated
|
static void |
setField(Field field,
Object instance,
Object value)
Sets the given field to the given value
|
static Class<?> |
translatePrimitiveType(Class<?> type)
Converts the type to its java form, or returns the original
|
static String |
writeMetadata(Map<String,List<String>> metadata)
Used to write the metadata out
|
static String |
writeSet(Set<?> set)
Writes a set in a way that can be read from an input stream as well
|
static String |
writeSet(Set<?> set,
Object excludeMe)
Writes a set in a way that can be read from an input stream as well
|
public static Class<?> getRawClass(Type type)
type
- The type to find the raw class onpublic static Type resolveField(Class<?> topclass, Field field)
topclass
- The instantiation class. Must not be nullfield
- The non-null field whose type to resolvepublic static Type resolveMember(Class<?> topclass, Type lookingForType, Class<?> declaringClass)
topclass
- The instantiation class. Must not be nulllookingForType
- The type to resolve. Must not be nulldeclaringClass
- The class of the entity declaring the lookingForType. Must not be nullpublic static Type resolveKnownType(TypeVariable<?> userType, ParameterizedType knownType, Class<?> knownDeclaringClass)
userType
- The user type to replace. May not be nullknownType
- The user defined known final type of the knownDeclaringClass. May not be nullknownDeclaringClass
- The declaringClass for which knownType is the resolved ParameterizedType for it.
May not be nullpublic static Type getFirstTypeArgument(Type type)
type
- The type to find the first type argument onpublic static String getName(Class<?> implClass)
implClass
- The class to evaluatepublic static Set<Type> getTypeClosure(Type ofType, Set<String> contracts)
ofType
- The type to checkcontracts
- The contracts this type is allowed to handlepublic static Set<Type> getAdvertisedTypesFromClass(Type type, Class<? extends Annotation> markerAnnotation)
type
- The outer type to analyzemarkerAnnotation
- The annotation to use to discover the advertised typespublic static Set<Type> getAdvertisedTypesFromObject(Object t, Class<? extends Annotation> markerAnnotation)
t
- the object we are analyzingmarkerAnnotation
- The annotation to use to discover the advertised typespublic static Set<String> getContractsFromClass(Class<?> clazz, Class<? extends Annotation> markerAnnotation)
clazz
- the class we are analyzingmarkerAnnotation
- The annotation to use to discover annotated typespublic static Annotation getScopeAnnotationFromObject(Object t)
t
- The object to analyzepublic static Annotation getScopeAnnotationFromClass(Class<?> clazz)
clazz
- The class to analyzepublic static Annotation getScopeFromObject(Object t, Annotation annoDefault)
t
- The object to analyzeannoDefault
- The default that this should have if no scope could be foundpublic static Annotation getScopeFromClass(Class<?> clazz, Annotation annoDefault)
clazz
- The class to analyzeannoDefault
- The scope that should be returned if no scope could be foundpublic static boolean isAnnotationAQualifier(Annotation anno)
anno
- The annotation to checkpublic static Set<Annotation> getQualifiersFromObject(Object t)
t
- The object to analyzepublic static Set<String> getQualifiersFromClass(Class<?> clazz)
clazz
- The class to analyzepublic static Set<Annotation> getQualifierAnnotations(AnnotatedElement annotatedGuy)
A strange behavior of this method is that if the annotatedGuy is a field and that field has the Named annotation on it with no value, then that Named annotation will NOT be added to the return list. This is because we have no access at this level to AnnotationLiteral, and hence cannot create a NamedImpl with which to fix the annotation. It is the responsibility of the caller of this method to add in the NamedImpl in that circumstance
annotatedGuy
- The thing to analyzepublic static String writeSet(Set<?> set)
set
- The set to writepublic static String writeSet(Set<?> set, Object excludeMe)
set
- The set to writeexcludeMe
- An object to exclude from the list of things writtenpublic static void readSet(String line, Collection<String> addToMe) throws IOException
line
- The line to readaddToMe
- The set to add the strings toIOException
- On a failurepublic static void readMetadataMap(String line, Map<String,List<String>> addToMe) throws IOException
line
- The line to readaddToMe
- The set to add the strings toIOException
- On a failurepublic static String writeMetadata(Map<String,List<String>> metadata)
metadata
- The metadata to externalizepublic static void addMetadata(Map<String,List<String>> metadatas, String key, String value)
metadatas
- The base metadata objectkey
- The key to which to add the value. May not be nullvalue
- The value to add. May not be nullpublic static boolean removeMetadata(Map<String,List<String>> metadatas, String key, String value)
metadatas
- The base metadata objectkey
- The key of the value to remove. May not be nullvalue
- The value to remove. May not be nullpublic static boolean removeAllMetadata(Map<String,List<String>> metadatas, String key)
metadatas
- The base metadata objectkey
- The key of the metadata values to removepublic static Map<String,List<String>> deepCopyMetadata(Map<String,List<String>> copyMe)
copyMe
- The guy to copy (if null, null will be returned)public static void setField(Field field, Object instance, Object value) throws Throwable
field
- The non-null field to setinstance
- The non-null instance to set intovalue
- The value to which the field should be setThrowable
- If there was some exception while setting the fieldpublic static Object invoke(Object o, Method m, Object[] args, boolean neutralCCL) throws Throwable
m
- the method to invokeo
- the object on which to invoke itargs
- The arguments to invoke (may not be null)neutralCCL
- true if the ContextClassLoader shoult remain null with this callThrowable
- The unwrapped throwable thrown by the methodpublic static boolean isStatic(Member member)
member
- The non-null member to testpublic static Object makeMe(Constructor<?> c, Object[] args, boolean neutralCCL) throws Throwable
c
- the constructor to callargs
- The arguments to invoke (may not be null)neutralCCL
- true if the context class loader should remain null through this callThrowable
- The unwrapped throwable thrown by the methodpublic static void parseServiceMetadataString(String metadataField, Map<String,List<String>> metadata)
metadataField
- A non-null metadata field that normally comes from the Service
metadata fieldmetadata
- The metadata field to add toIllegalStateException
- if a string with an invalid format is foundpublic static String getNameFromAllQualifiers(Set<Annotation> qualifiers, AnnotatedElement parent) throws IllegalStateException
qualifiers
- The set of qualifiers that may or may not have Named in itparent
- The parent element for which we are searchingIllegalStateException
- If the parent is annotated with a blank Named but is not
a Class or a Fieldpublic static boolean annotationContainsAll(Set<Annotation> candidateAnnotations, Set<Annotation> requiredAnnotations)
candidateAnnotations
- The candidate annotationsrequiredAnnotations
- The required annotationspublic static Class<?> translatePrimitiveType(Class<?> type)
type
- The type to convertpublic static boolean isPrivate(Member member)
member
- The non-null member to testpublic static MethodWrapper createMethodWrapper(Method wrapMe)
wrapMe
- The non-null method to wrappublic static <T> T cast(Object o)
o
- The thing to castCopyright © 2009-2017, Oracle and/or its affiliates. All Rights Reserved.