net.sf.mmm.util.reflect.api
Interface GenericTypeFactory

All Known Subinterfaces:
ReflectionUtil
All Known Implementing Classes:
ReflectionUtilImpl

@ComponentSpecification
public interface GenericTypeFactory

This is the interface for a factory with ability to create GenericTypes.

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Method Summary
<T> GenericType<T>
createGenericType(Class<T> type)
          This method creates the GenericType representing the given type.
 GenericType<?> createGenericType(Type type)
          This method creates the GenericType representing the given type.
 GenericType<?> createGenericType(Type type, Class<?> definingType)
          This method creates the GenericType representing the given type in the context of the given definingType.
 GenericType<?> createGenericType(Type type, GenericType<?> definingType)
          This method creates the GenericType representing the given type in the context of the given definingType.
 

Method Detail

createGenericType

<T> GenericType<T> createGenericType(Class<T> type)
This method creates the GenericType representing the given type.
The type, lower bound and upper bound of the returned GenericType will all be identical to the given type.
ATTENTION:
If you know the Type where the given type was defined you should use createGenericType(Type, GenericType) instead to get a more precise result.

Type Parameters:
T - is the generic type of the Class to convert.
Parameters:
type - is the Type to represent.
Returns:
the according GenericType.

createGenericType

GenericType<?> createGenericType(Type type)
This method creates the GenericType representing the given type.
If the given type is a Class, the methods behaves like createGenericType(Class).
ATTENTION:
If you know the Type where the given type was defined (e.g. the Class where you retrieved the given type from as parameter, return-type or field-type) you should use createGenericType(Type, GenericType) instead to get a more precise result.

Parameters:
type - is the Type to represent.
Returns:
the according GenericType.

createGenericType

GenericType<?> createGenericType(Type type,
                                 GenericType<?> definingType)
This method creates the GenericType representing the given type in the context of the given definingType.
Here is some typical example of how to use this:
 ReflectionUtil util = ReflectionUtilImpl.getInstance();
 Class<?> myClass = getSomeClass();
 GenericType definingType = util.createGenericType(myClass);
 Method myMethod = findSomeMethod(myClass);
 Type returnType = myMethod.getGenericReturnType();
 GenericType type = util.createGenericType(returnType, definingType);
 Class<?> returnClass = type.GenericType.getRetrievalClass();
 
Now if you ask your self why all this instead of just using myMethod.getReturnType() ? Read the javadoc of GenericType to get the answer.
NOTE:
Please look at mmm-util-pojo which allows to use this features at a higher level and therefore much easier.

Parameters:
type - is the Type to represent.
definingType - is the GenericType where the given type is defined in. It is needed to resolve TypeVariables.
Returns:
the according GenericType.
See Also:
createGenericType(Type, Class)

createGenericType

GenericType<?> createGenericType(Type type,
                                 Class<?> definingType)
This method creates the GenericType representing the given type in the context of the given definingType.
It is a convenience method for createGenericType(type, createGenericType(definingType))

Parameters:
type - is the Type to represent.
definingType - is the Class where the given type is defined in. It is needed to resolve TypeVariables.
Returns:
the according GenericType.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.