it.avutils.jmapper.util
Class ClassesManager

java.lang.Object
  extended by it.avutils.jmapper.util.ClassesManager

public final class ClassesManager
extends Object

Utility class that allows you to manage classes.

Author:
Alessandro Vurro

Method Summary
static boolean areEqual(Field destination, Field source)
          Returns true if destination and source have the same structure.
static boolean areMappedObjects(Class<?> dClass, Class<?> sClass, XML xml)
          returns true if almost one class is configured, false otherwise.
static ChooseConfig configChosen(Class<?> dItem, Class<?> sItem, XML xml)
          returns the location of the configuration, null if both classes are configured.
static Class<?> defineStructure(Field destination, Field source)
          This method defines the destination structure for this operation.
static boolean existField(Class<?> aClass, String name)
          Returns true if exist a field with this name in aClass, false otherwise.
static List<Method> getAllMethods(Class<?> aClass)
          Returns all methods that belongs to aClass.
static List<Class<?>> getAllsuperclasses(Class<?> aClass)
          Returns a list with the class passed in input plus his superclasses.
static Class<?> getArrayItemClass(Field field)
          Extracts the generic class from the type of field given as input.
static Class<?> getCollectionItemClass(Field generic)
          Extracts the generic class from the type of field given as input.
static List<ConversionMethod> getConversionMethods(Class<?> clazz, XML xml)
          Returns the conversions method belonging to clazz.
static
<T> T
getFieldValue(Object obj, String fieldName)
          Extracts the value of a field from an object.
static Class<?> getGenericMapKeyItem(Field generic)
          Extracts the generic class from the type of field given as input.
static Class<?> getGenericMapValueItem(Field generic)
          Extracts the generic class from the type of field given as input.
static String getGenericString(Field field)
           
static void getKeyValueClasses(Field field, Class<?> key, Class<?> value)
          Classes key and value will be enhanced with the type of classes of the map.
static List<Field> getListOfFields(Class<?> aClass)
          Returns a List of aClass fields and all of its super classes.
static Method getMethodOf(Class<?> clazz, Field field)
          Returns the getMethod of the field received in input.
static Method getMethodOf(Class<?> clazz, String field)
          Returns the getMethod of the field received in input.
static boolean isAddAllPermitted(Field destination, Field source)
          this method verify that the istruction: destination.addAll(source) is permitted
static boolean isAssignableFrom(Class<?> destination, Class<?> source)
          Returns true if destination is assignable from source analyzing autoboxing also.
static boolean isAssignableFrom(Field destination, Field source)
          this method verify that the instruction: destination = source is permitted, checking their generics also
static boolean isBoxing(Class<?> destination, Class<?> source)
          Returns true if is a boxing operation, false otherwise.
static boolean isMapped(Class<?> aClass, XML xml)
          Returns true if the class is configured in annotation or xml, false otherwise.
static boolean isMappedInAnnotation(Class<?> aClass)
          Returns true if the class is configured in annotation, false otherwise.
static boolean isMappedInXML(Class<?> aClass, XML xml)
          Returns true if the class is configured in xml, false otherwise.
static boolean isPutAllPermitted(Field destination, Field source)
          this method verify that the istruction: destination.putAll(source) is permitted
static boolean isUnBoxing(Class<?> destination, Class<?> source)
          Returns true if is an unboxing operation, false otherwise.
static String mapperClassName(Class<?> destination, Class<?> source, String path)
          Returns the name of mapper that identifies the destination and source classes.
static Field retrieveField(Class<?> clazz, String fieldName)
          Returns a field with a specific name from class given as input.
static Method setMethodOf(Class<?> clazz, Field field)
          Returns the setMethod of the field received in input.
static Method setMethodOf(Class<?> clazz, String field)
          Returns the setMethod of the field received in input.
static void verifiesAccessorMethods(Class<?> clazz, Field... fields)
          Verifies that the accessor methods are compliant with the naming convention.
static void verifiesGetterMethods(Class<?> clazz, Field... fields)
          Verifies that the getter methods are compliant with the naming convention.
static void verifySetterMethods(Class<?> clazz, Field... fields)
          Verifies that the setter methods are compliant with the naming convention.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isPutAllPermitted

public static boolean isPutAllPermitted(Field destination,
                                        Field source)
this method verify that the istruction:

destination.putAll(source)

is permitted

Parameters:
destination -
source -
Returns:
true if the istruction destination.putAll(source) is permitted

isAddAllPermitted

public static boolean isAddAllPermitted(Field destination,
                                        Field source)
this method verify that the istruction:

destination.addAll(source)

is permitted

Parameters:
destination -
source -
Returns:
true if the istruction destination.addAll(source) is permitted

isAssignableFrom

public static boolean isAssignableFrom(Field destination,
                                       Field source)
this method verify that the instruction:

destination = source

is permitted, checking their generics also

Parameters:
destination -
source -
Returns:
true if destination is assignable from source

isAssignableFrom

public static boolean isAssignableFrom(Class<?> destination,
                                       Class<?> source)
Returns true if destination is assignable from source analyzing autoboxing also.

Parameters:
destination -
source -
Returns:
true if destination is assignable from source analyzing autoboxing also.

isUnBoxing

public static boolean isUnBoxing(Class<?> destination,
                                 Class<?> source)
Returns true if is an unboxing operation, false otherwise.

Parameters:
destination - the primitive Class
source - the Wrapper Class
Returns:
true if is an unboxing operation, false otherwise

isBoxing

public static boolean isBoxing(Class<?> destination,
                               Class<?> source)
Returns true if is a boxing operation, false otherwise.

Parameters:
destination - the Wrapper Class
source - the primitive Class
Returns:
true if is a boxing operation, false otherwise

getGenericString

public static String getGenericString(Field field)
Parameters:
field -
Returns:
returns a string that specified the structure of the field, including its generic

areEqual

public static boolean areEqual(Field destination,
                               Field source)
Returns true if destination and source have the same structure.

Parameters:
destination -
source -
Returns:
returns true if destination and source have the same structure

mapperClassName

public static String mapperClassName(Class<?> destination,
                                     Class<?> source,
                                     String path)
Returns the name of mapper that identifies the destination and source classes.

Parameters:
destination - class of Destination
source - class of Source
path - xml path
Returns:
Returns a string containing the names of the classes passed as input

existField

public static boolean existField(Class<?> aClass,
                                 String name)
Returns true if exist a field with this name in aClass, false otherwise.

Parameters:
aClass - a class to control
name - field to find
Returns:
true if exist a field with this name in aClass, false otherwise

areMappedObjects

public static boolean areMappedObjects(Class<?> dClass,
                                       Class<?> sClass,
                                       XML xml)
returns true if almost one class is configured, false otherwise.

Parameters:
dClass - class to verify
sClass - class to verify
Returns:
true if almost one class is configured, false otherwise.

isMapped

public static boolean isMapped(Class<?> aClass,
                               XML xml)
Returns true if the class is configured in annotation or xml, false otherwise.

Parameters:
aClass - a class
Returns:
true if the class is configured in annotation or xml, false otherwise

isMappedInXML

public static boolean isMappedInXML(Class<?> aClass,
                                    XML xml)
Returns true if the class is configured in xml, false otherwise.

Parameters:
aClass - a class
xml - object
Returns:
true if the class is configured in xml, false otherwise

isMappedInAnnotation

public static boolean isMappedInAnnotation(Class<?> aClass)
Returns true if the class is configured in annotation, false otherwise.

Parameters:
aClass - a class
Returns:
true if the class is configured in annotation, false otherwise

getAllsuperclasses

public static List<Class<?>> getAllsuperclasses(Class<?> aClass)
Returns a list with the class passed in input plus his superclasses.

Parameters:
aClass - class to check
Returns:
a classes list

getListOfFields

public static List<Field> getListOfFields(Class<?> aClass)
Returns a List of aClass fields and all of its super classes.

Parameters:
aClass - class to handle
Returns:
a list of aClass fields

getConversionMethods

public static List<ConversionMethod> getConversionMethods(Class<?> clazz,
                                                          XML xml)
Returns the conversions method belonging to clazz.

Parameters:
clazz - class to check
xml - xml object
Returns:
the conversion method list

getAllMethods

public static List<Method> getAllMethods(Class<?> aClass)
Returns all methods that belongs to aClass.

Parameters:
aClass - class to check
Returns:
list of methods

retrieveField

public static Field retrieveField(Class<?> clazz,
                                  String fieldName)
Returns a field with a specific name from class given as input.

Parameters:
clazz - class to handle
fieldName - name of field to retrieve
Returns:
field if exist, null otherwise

verifiesAccessorMethods

public static void verifiesAccessorMethods(Class<?> clazz,
                                           Field... fields)
Verifies that the accessor methods are compliant with the naming convention.

Parameters:
clazz - a class to check
fields - fields to control
See Also:
javaBean conventions

verifiesGetterMethods

public static void verifiesGetterMethods(Class<?> clazz,
                                         Field... fields)
Verifies that the getter methods are compliant with the naming convention.

Parameters:
clazz - a class to check
fields - fields to control
See Also:
javaBean conventions

verifySetterMethods

public static void verifySetterMethods(Class<?> clazz,
                                       Field... fields)
Verifies that the setter methods are compliant with the naming convention.

Parameters:
clazz - a class to check
fields - fields to control
See Also:
javaBean conventions

configChosen

public static ChooseConfig configChosen(Class<?> dItem,
                                        Class<?> sItem,
                                        XML xml)
returns the location of the configuration, null if both classes are configured.

Parameters:
dItem - class to analyze
sItem - class to analyze
Returns:
the location of the configuration, null if both classes are configured.

getMethodOf

public static Method getMethodOf(Class<?> clazz,
                                 String field)
Returns the getMethod of the field received in input.

Parameters:
clazz - class of the field
field -
Returns:
Method

setMethodOf

public static Method setMethodOf(Class<?> clazz,
                                 String field)
Returns the setMethod of the field received in input.

Parameters:
clazz - class of the field
field -
Returns:
Method

getMethodOf

public static Method getMethodOf(Class<?> clazz,
                                 Field field)
Returns the getMethod of the field received in input.

Parameters:
clazz - class of the field
field -
Returns:
Method

setMethodOf

public static Method setMethodOf(Class<?> clazz,
                                 Field field)
Returns the setMethod of the field received in input.

Parameters:
clazz - class of the field
field -
Returns:
Method

getFieldValue

public static <T> T getFieldValue(Object obj,
                                  String fieldName)
Extracts the value of a field from an object.
Example:
MyClass {
private String aField;
get and set...
}

String aFieldValue = getFieldValue(new MyClass("example"),"aField");
assertEqual("example",aFieldValue);

Parameters:
obj -
fieldName -
Returns:
the value of a field from an object

getCollectionItemClass

public static Class<?> getCollectionItemClass(Field generic)
Extracts the generic class from the type of field given as input.
Example:
MyClass {
List<String> aList;
get and set...
}

Field aField = MyClass.class.getDeclaredField("aList");
Class generic = getCollectionItemClass(aField);
assertEqual(generic,String.class);

Parameters:
generic - a Field
Returns:
a Class contained in the class type of the field, returns null if no generics

getGenericMapKeyItem

public static Class<?> getGenericMapKeyItem(Field generic)
Extracts the generic class from the type of field given as input.
Example:
MyClass {
Map<String, Integer> aMap;
get and set...
}

Field aField = MyClass.class.getDeclaredField("aMap");
Class generic = getGenericMapKeyItem(aField);
assertEqual(generic,String.class);

Parameters:
generic - a Field
Returns:
a Class contained in the class type of the field

getGenericMapValueItem

public static Class<?> getGenericMapValueItem(Field generic)
Extracts the generic class from the type of field given as input.
Example:
MyClass {
Map<String, Integer> aMap;
get and set...
}

Field aField = MyClass.class.getGenericMapValueItem("aMap");
Class generic = getGenericMapKeyItem(aField);
assertEqual(generic,Integer.class);

Parameters:
generic - a Field
Returns:
a Class contained in the class type of the field

getArrayItemClass

public static Class<?> getArrayItemClass(Field field)
Extracts the generic class from the type of field given as input.
Example:
MyClass {
MyObj[] anArray;
get and set...
}

Field aField = MyClass.class.getDeclaredField("anArray");
Class item = getArrayItemClass(aField);
assertEqual(item,MyObj.class);

Parameters:
field - a Field
Returns:
a Class contained in the class type of the field

getKeyValueClasses

public static void getKeyValueClasses(Field field,
                                      Class<?> key,
                                      Class<?> value)
Classes key and value will be enhanced with the type of classes of the map.

Parameters:
field - of type map
key - class of the map
value - class of the map

defineStructure

public static Class<?> defineStructure(Field destination,
                                       Field source)
This method defines the destination structure for this operation. If destination class is an interface, a relative implementation will be found.

Parameters:
destination - destination field
source - source field


Copyright © 2013. All Rights Reserved.