org.glassfish.hk2.api
Interface ClassAnalyzer

All Known Implementing Classes:
JaxRsClassAnalyzer

@Contract
public interface ClassAnalyzer

When HK2 automatically analyzes a class to find the constructor, fields, initializer methods and postConstruct and preDestroy methods it uses this service to analyze the class. This analyzer is only used for descriptors that are not pre-reified and which are not provided by factories.

HK2 will provided a default implementation of this service (with the name default). However, individual descriptors may choose a different class analyzer should they so choose. All user supplied implementations of this service must have a name. Implementations of this service must not be ClassAnalyzers for themselves.

Author:
jwells

Field Summary
static java.lang.String DEFAULT_IMPLEMENTATION_NAME
           
 
Method Summary
<T> java.lang.reflect.Constructor<T>
getConstructor(java.lang.Class<T> clazz)
          Will return the constructor that it to be used when constructing this service
<T> java.util.Set<java.lang.reflect.Field>
getFields(java.lang.Class<T> clazz)
          Will return the set of initializer fields to be used when initializing this service
<T> java.util.Set<java.lang.reflect.Method>
getInitializerMethods(java.lang.Class<T> clazz)
          Will return the set of initializer method to be used when initializing this service
<T> java.lang.reflect.Method
getPostConstructMethod(java.lang.Class<T> clazz)
          Will return the postConstruct method of the class
<T> java.lang.reflect.Method
getPreDestroyMethod(java.lang.Class<T> clazz)
          Will return the preDestroy method of the class
 

Field Detail

DEFAULT_IMPLEMENTATION_NAME

static final java.lang.String DEFAULT_IMPLEMENTATION_NAME
See Also:
Constant Field Values
Method Detail

getConstructor

<T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> clazz)
                                                throws MultiException,
                                                       java.lang.NoSuchMethodException
Will return the constructor that it to be used when constructing this service

The default implementation will use the zero-arg constructor if no single constructor with Inject is found

Parameters:
clazz - the non-null class to analyze
Returns:
The non-null constructor to use for creating this service
Throws:
MultiException - on an error when analyzing the class
java.lang.NoSuchMethodException - if there was no available constructor

getInitializerMethods

<T> java.util.Set<java.lang.reflect.Method> getInitializerMethods(java.lang.Class<T> clazz)
                                                              throws MultiException
Will return the set of initializer method to be used when initializing this service

The default implementation will return all methods marked with Inject

Parameters:
clazz - the non-null class to analyze
Returns:
A non-null but possibly empty set of initialization methods
Throws:
MultiException - on an error when analyzing the class

getFields

<T> java.util.Set<java.lang.reflect.Field> getFields(java.lang.Class<T> clazz)
                                                 throws MultiException
Will return the set of initializer fields to be used when initializing this service

The default implementation will return all fields marked with Inject

Parameters:
clazz - the non-null class to analyze
Returns:
A non-null but possibly empty set of initialization fields
Throws:
MultiException - on an error when analyzing the class

getPostConstructMethod

<T> java.lang.reflect.Method getPostConstructMethod(java.lang.Class<T> clazz)
                                                throws MultiException
Will return the postConstruct method of the class

The default implementation will return the PostConstruct.postConstruct() method or the method annotated with PostConstruct

Parameters:
clazz - the non-null class to analyze
Returns:
A possibly null method representing the postConstruct method to call
Throws:
MultiException - on an error when analyzing the class

getPreDestroyMethod

<T> java.lang.reflect.Method getPreDestroyMethod(java.lang.Class<T> clazz)
                                             throws MultiException
Will return the preDestroy method of the class

The default implementation will return the PreDestroy.preDestroy() method or the method annotated with PreDestroy

Parameters:
clazz - the non-null class to analyze
Returns:
A possibly null method representing the preDestroy method to call
Throws:
MultiException - on an error when analyzing the class


Copyright © 2013 Oracle Corporation. All Rights Reserved.