org.glassfish.hk2.utilities.reflection
Class ReflectionHelper

java.lang.Object
  extended by org.glassfish.hk2.utilities.reflection.ReflectionHelper

public class ReflectionHelper
extends Object

Author:
jwells

Constructor Summary
ReflectionHelper()
           
 
Method Summary
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 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<String> getContractsFromClass(Class<?> clazz, Class<? extends Annotation> markerAnnotation)
          Returns the set of types this class advertises
static String getName(Class<?> implClass)
          Returns the name that should be associated with this class
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 Class<? extends Annotation> getScopeFromClass(Class<?> clazz, Class<? extends Annotation> annoDefault)
          Gets the scope annotation from the object
static Class<? extends Annotation> getScopeFromObject(Object t, Class<? extends 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)
          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 isStatic(Member member)
          Returns true if the underlying member is static
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 void setContextClassLoader(Thread t, ClassLoader l)
          Sets the context classloader under the privileged of this class
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionHelper

public ReflectionHelper()
Method Detail

getRawClass

public 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

Parameters:
type - The type to find the raw class on
Returns:
The raw class associated with this type

getName

public static String getName(Class<?> implClass)
Returns the name that should be associated with this class

Parameters:
implClass - The class to evaluate
Returns:
The name this class should have

getTypeClosure

public 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

Parameters:
ofType - The type to check
contracts - The contracts this type is allowed to handle
Returns:
The type closure restricted to the contracts

getAdvertisedTypesFromClass

public static Set<Type> getAdvertisedTypesFromClass(Type type,
                                                    Class<? extends Annotation> markerAnnotation)
Returns the set of types this class advertises

Parameters:
type - The outer type to analyze
markerAnnotation - The annotation to use to discover the advertised types
Returns:
The type itself and the contracts it implements

getAdvertisedTypesFromObject

public static Set<Type> getAdvertisedTypesFromObject(Object t,
                                                     Class<? extends Annotation> markerAnnotation)
Returns the set of types this class advertises

Parameters:
t - the object we are analyzing
markerAnnotation - The annotation to use to discover the advertised types
Returns:
The type itself and the contracts it implements

getContractsFromClass

public static Set<String> getContractsFromClass(Class<?> clazz,
                                                Class<? extends Annotation> markerAnnotation)
Returns the set of types this class advertises

Parameters:
clazz - the class we are analyzing
markerAnnotation - The annotation to use to discover annotated types
Returns:
The type itself and the contracts it implements

getScopeAnnotationFromObject

public static Annotation getScopeAnnotationFromObject(Object t)
Gets the scope annotation from the object

Parameters:
t - The object to analyze
Returns:
The class of the scope annotation

getScopeAnnotationFromClass

public static Annotation getScopeAnnotationFromClass(Class<?> clazz)
Gets the scope annotation from the object

Parameters:
clazz - The class to analyze
Returns:
The class of the scope annotation

getScopeFromObject

public static Class<? extends Annotation> getScopeFromObject(Object t,
                                                             Class<? extends Annotation> annoDefault)
Gets the scope annotation from the object

Parameters:
t - The object to analyze
annoDefault - The default that this should have if no scope could be found
Returns:
The class of the scope annotation

getScopeFromClass

public static Class<? extends Annotation> getScopeFromClass(Class<?> clazz,
                                                            Class<? extends Annotation> annoDefault)
Gets the scope annotation from the object

Parameters:
clazz - The class to analyze
annoDefault - The scope that should be returned if no scope could be found
Returns:
The class of the scope annotation

isAnnotationAQualifier

public static boolean isAnnotationAQualifier(Annotation anno)
Returns true if the given annotation is a qualifier

Parameters:
anno - The annotation to check
Returns:
true if this is an annotation

getQualifiersFromObject

public static Set<Annotation> getQualifiersFromObject(Object t)
Gets all the qualifiers from the object

Parameters:
t - The object to analyze
Returns:
The set of qualifiers. Will not return null but may return an empty set

getQualifiersFromClass

public static Set<String> getQualifiersFromClass(Class<?> clazz)
Gets all the qualifiers from the object

Parameters:
clazz - The class to analyze
Returns:
The set of qualifiers. Will not return null but may return an empty set

getQualifierAnnotations

public static Set<Annotation> getQualifierAnnotations(AnnotatedElement annotatedGuy)
Gets all the qualifier annotations from the object

Parameters:
annotatedGuy - The thing to analyze
Returns:
The set of qualifiers. Will not return null but may return an empty set

writeSet

public static String writeSet(Set<?> set)
Writes a set in a way that can be read from an input stream as well

Parameters:
set - The set to write
Returns:
a representation of a list

readSet

public static void readSet(String line,
                           Collection<String> addToMe)
                    throws IOException
Writes a set in a way that can be read from an input stream as well. The values in the set may not contain the characters "{},"

Parameters:
line - The line to read
addToMe - The set to add the strings to
Throws:
IOException - On a failure

readMetadataMap

public static void readMetadataMap(String line,
                                   Map<String,List<String>> addToMe)
                            throws IOException
Writes a set in a way that can be read from an input stream as well

Parameters:
line - The line to read
addToMe - The set to add the strings to
Throws:
IOException - On a failure

writeMetadata

public static String writeMetadata(Map<String,List<String>> metadata)
Used to write the metadata out

Parameters:
metadata - The metadata to externalize
Returns:
The metadata in an externalizable format

addMetadata

public static void addMetadata(Map<String,List<String>> metadatas,
                               String key,
                               String value)
Adds a value to the list of values associated with this key

Parameters:
metadatas - The base metadata object
key - The key to which to add the value. May not be null
value - The value to add. May not be null

removeMetadata

public static boolean removeMetadata(Map<String,List<String>> metadatas,
                                     String key,
                                     String value)
Removes the given value from the given key

Parameters:
metadatas - The base metadata object
key - The key of the value to remove. May not be null
value - The value to remove. May not be null
Returns:
true if the value was removed

removeAllMetadata

public static boolean removeAllMetadata(Map<String,List<String>> metadatas,
                                        String key)
Removes all the metadata values associated with key

Parameters:
metadatas - The base metadata object
key - The key of the metadata values to remove
Returns:
true if any value was removed

deepCopyMetadata

public 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)

Parameters:
copyMe - The guy to copy (if null, null will be returned)
Returns:
A deep copy of the metadata

invoke

public static Object invoke(Object o,
                            Method m,
                            Object[] args)
                     throws Throwable
This version of invoke is CCL neutral (it will return with the same CCL as what it went in with)

Parameters:
m - the method to invoke
o - the object on which to invoke it
args - The arguments to invoke (may not be null)
Returns:
The return from the invocation
Throws:
Throwable - The unwrapped throwable thrown by the method

isStatic

public static boolean isStatic(Member member)
Returns true if the underlying member is static

Parameters:
member - The non-null member to test
Returns:
true if the member is static

setContextClassLoader

public static void setContextClassLoader(Thread t,
                                         ClassLoader l)
Sets the context classloader under the privileged of this class

Parameters:
t - The thread on which to set the classloader
l - The classloader to set


Copyright © 2013 Oracle Corporation. All Rights Reserved.