Package org.simpleframework.xml.core
Class Reflector
java.lang.Object
org.simpleframework.xml.core.Reflector
The
Reflector
object is used to determine the type
of a generic type. This is used when the type of an XML annotation
is not explicitly and the schema scanner needs to determine via
reflection what the generic parameters are of a specific type. In
particular this is used to determine the parameters within a list
annotated with the ElementList
annotation. This also
has special handling for arrays within generic collections.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Class
getArrayClass
(Type type) This is used to extract an array class from the specified.private static Class
getClass
(ParameterizedType type) This is used to extract the class from the specified type.private static Class
This is used to extract the class from the specified type.private static Class[]
getClasses
(ParameterizedType type) This is used to extract the class from the specified type.static Class
getDependent
(Field field) This method is used to acquire a generic parameter dependent from the specified field.static Class[]
getDependents
(Field field) This method is used to acquire generic parameter dependents from the specified field.private static Class
getGenericClass
(Type type) This is used to extract the class from the specified type.static String
This is used to acquire a bean name for a method or field name.static Class
getParameterDependent
(Constructor factory, int index) This method is used to acquire a generic parameter dependent from the specified parameter type.static Class
getParameterDependent
(Method method, int index) This method is used to acquire a generic parameter dependent from the specified parameter type.static Class[]
getParameterDependents
(Constructor factory, int index) This method is used to acquire a generic parameter dependent from the specified parameter type.static Class[]
getParameterDependents
(Method method, int index) This method is used to acquire a generic parameter dependent from the specified parameter type.private static ParameterizedType
getParameterType
(Constructor factory, int index) This is used to acquire the parameterized types from the given constructors parameter class at the specified index position.private static ParameterizedType
getParameterType
(Method method, int index) This is used to acquire the parameterized types from the given methods parameter class at the specified index position.static Class
getReturnDependent
(Method method) This method is used to acquire a generic parameter dependent from the method return type.static Class[]
getReturnDependents
(Method method) This method is used to acquire a generic parameter dependent from the method return type.private static ParameterizedType
getReturnType
(Method method) This is used to acquire the parameterized types from the given methods return class.private static ParameterizedType
This is used to acquire the parameterized types from the given field.private static boolean
isAcronym
(char[] array) This is used to determine if the provided array of characters represents an acronym.private static boolean
isUpperCase
(char value) This is used to determine if the provided character is an upper case character.private static char
toLowerCase
(char value) This is used to convert the provided character to lower case.
-
Constructor Details
-
Reflector
Reflector()
-
-
Method Details
-
getDependent
This method is used to acquire a generic parameter dependent from the specified field. This will acquire the field class and attempt to extract the first generic parameter type from that field. If there is a generic parameter then the class of that parameter is returned from this method.- Parameters:
field
- this is the field to acquire the dependent class- Returns:
- this returns the generic parameter class declared
-
getDependents
This method is used to acquire generic parameter dependents from the specified field. This will acquire the field class and attempt to extract all of the generic parameter types from that field. If there is a generic parameter then the class of that parameter is returned from this method.- Parameters:
field
- this is the field to acquire the dependent types- Returns:
- this returns the generic parameter classes declared
-
getType
This is used to acquire the parameterized types from the given field. If the field class has been parameterized then this will return the parameters that have been declared on that class.- Parameters:
field
- this is the field to acquire the parameters from- Returns:
- this will return the parameterized types for the field
-
getReturnDependent
This method is used to acquire a generic parameter dependent from the method return type. This will acquire the return type and attempt to extract the first generic parameter type from that type. If there is a generic parameter then the class of that parameter is returned from this method.- Parameters:
method
- this is the method to acquire the dependent of- Returns:
- this returns the generic parameter class declared
-
getReturnDependents
This method is used to acquire a generic parameter dependent from the method return type. This will acquire the return type and attempt to extract the first generic parameter type from that type. If there is a generic parameter then the class of that parameter is returned from this method.- Parameters:
method
- this is the method to acquire the dependent of- Returns:
- this returns the generic parameter class declared
-
getReturnType
This is used to acquire the parameterized types from the given methods return class. If the return type class is parameterized then this will return the parameters that have been declared on that class, otherwise null is returned.- Parameters:
method
- this is the method to acquire the parameters from- Returns:
- this returns the parameterized types for the method
-
getParameterDependent
This method is used to acquire a generic parameter dependent from the specified parameter type. This will acquire the type for the parameter at the specified index and attempt to extract the first generic parameter type from that type. If there is a generic parameter then the class of that parameter is returned from this method, otherwise null is returned.- Parameters:
method
- this is the method to acquire the dependent ofindex
- this is the index to acquire the parameter from- Returns:
- this returns the generic parameter class declared
-
getParameterDependents
This method is used to acquire a generic parameter dependent from the specified parameter type. This will acquire the type for the parameter at the specified index and attempt to extract the first generic parameter type from that type. If there is a generic parameter then the class of that parameter is returned from this method, otherwise null is returned.- Parameters:
method
- this is the method to acquire the dependent ofindex
- this is the index to acquire the parameter from- Returns:
- this returns the generic parameter class declared
-
getParameterDependent
This method is used to acquire a generic parameter dependent from the specified parameter type. This will acquire the type for the parameter at the specified index and attempt to extract the first generic parameter type from that type. If there is a generic parameter then the class of that parameter is returned from this method, otherwise null is returned.- Parameters:
factory
- this is the constructor to acquire the dependentindex
- this is the index to acquire the parameter from- Returns:
- this returns the generic parameter class declared
-
getParameterDependents
This method is used to acquire a generic parameter dependent from the specified parameter type. This will acquire the type for the parameter at the specified index and attempt to extract the first generic parameter type from that type. If there is a generic parameter then the class of that parameter is returned from this method, otherwise null is returned.- Parameters:
factory
- this is the constructor to acquire the dependentindex
- this is the index to acquire the parameter from- Returns:
- this returns the generic parameter class declared
-
getParameterType
This is used to acquire the parameterized types from the given methods parameter class at the specified index position. If the parameter class is parameterized this returns the parameters that have been declared on that class.- Parameters:
method
- this is the method to acquire the parameters fromindex
- this is the index to acquire the parameter from- Returns:
- this returns the parameterized types for the method
-
getParameterType
This is used to acquire the parameterized types from the given constructors parameter class at the specified index position. If the parameter class is parameterized this returns the parameters that have been declared on that class.- Parameters:
factory
- this is constructor method to acquire the parametersindex
- this is the index to acquire the parameter from- Returns:
- this returns the parameterized types for the method
-
getClass
This is used to extract the class from the specified type. If there are no actual generic type arguments to the specified type then this will return null. Otherwise this will return the actual class, regardless of whether the class is an array.- Parameters:
type
- this is the type to extract the class from- Returns:
- this returns the class type from the first parameter
-
getClasses
This is used to extract the class from the specified type. If there are no actual generic type arguments to the specified type then this will return null. Otherwise this will return the actual class, regardless of whether the class is an array.- Parameters:
type
- this is the type to extract the class from- Returns:
- this returns the class type from the first parameter
-
getClass
This is used to extract the class from the specified type. If there are no actual generic type arguments to the specified type then this will return null. Otherwise this will return the actual class, regardless of whether the class is an array.- Parameters:
type
- this is the type to extract the class from- Returns:
- this returns the class type from the first parameter
-
getGenericClass
This is used to extract the class from the specified type. If there are no actual generic type arguments to the specified type then this will return null. Otherwise this will return the actual class, regardless of whether the class is an array.- Parameters:
type
- this is the type to extract the class from- Returns:
- this returns the class type from the first parameter
-
getArrayClass
This is used to extract an array class from the specified. If a class can be extracted from the type then the array class is created by reflective creating a zero length array with the component type of the array and returning the array class.- Parameters:
type
- this is the type to extract the class from- Returns:
- this returns the class type from the array type
-
getName
This is used to acquire a bean name for a method or field name. A bean name is the name of a method or field with the first character decapitalized. An exception to this is when a method or field starts with an acronym, in such a case the name will remain unchanged from the original name.- Parameters:
name
- this is the name to convert to a bean name- Returns:
- this returns the bean value for the given name
-
isAcronym
private static boolean isAcronym(char[] array) This is used to determine if the provided array of characters represents an acronym. The array of characters is considered an acronym if the first and second characters are upper case.- Parameters:
array
- the array to evaluate whether it is an acronym- Returns:
- this returns true if the provided array is an acronym
-
toLowerCase
private static char toLowerCase(char value) This is used to convert the provided character to lower case. The character conversion is done for all unicode characters.- Parameters:
value
- this is the value that is to be converted- Returns:
- this returns the provided character in lower case
-
isUpperCase
private static boolean isUpperCase(char value) This is used to determine if the provided character is an upper case character. This can deal with unicode characters.- Parameters:
value
- this is the value that is to be evaluated- Returns:
- this returns true if the character is upper case
-