}
ClassMappings result = new ClassMappings();
if (classMaps == null || classMaps.size() == 0) {
return result;
}
FieldMap fieldMapPrime;
// need to create bi-directional mappings now.
ClassMap classMapPrime;
Set<String> mapIds = new HashSet<String>();
for (ClassMap classMap : classMaps) {
classMap.setGlobalConfiguration(globalConfiguration);
// add our first class map to the result map and initialize PropertyDescriptor Cache
ReflectionUtils.findPropertyDescriptor(classMap.getSrcClassToMap(), "", null);
ReflectionUtils.findPropertyDescriptor(classMap.getDestClassToMap(), "", null);
// Check to see if this is a duplicate map id, irregardless of src and dest class names.
// Duplicate map-ids are not allowed
if (!MappingUtils.isBlankOrNull(classMap.getMapId())) {
if (mapIds.contains(classMap.getMapId())) {
throw new IllegalArgumentException("Duplicate Map Id's Found. Map Id: " + classMap.getMapId());
}
mapIds.add(classMap.getMapId());
}
result.add(classMap.getSrcClassToMap(), classMap.getDestClassToMap(), classMap.getMapId(), classMap);
// now create class map prime
classMapPrime = new ClassMap(globalConfiguration);
MappingUtils.reverseFields(classMap, classMapPrime);
if (classMap.getFieldMaps() != null) {
List<FieldMap> fms = classMap.getFieldMaps();
// iterate through the fields and see wether or not they should be mapped
// one way class mappings we do not need to add any fields
if (!MappingDirection.ONE_WAY.equals(classMap.getType())) {
for (FieldMap fieldMap : fms.toArray(new FieldMap[]{})) {
fieldMap.validate();
// If we are dealing with a Map data type, transform the field map into a MapFieldMap type
// only apply transformation if it is map to non-map mapping.
if (!(fieldMap instanceof ExcludeFieldMap)) {
if ( ( isSupportedMap(classMap.getDestClassToMap()) ^ isSupportedMap(classMap.getSrcClassToMap()) )
|| ( isSupportedMap(fieldMap.getDestFieldType(classMap.getDestClassToMap()))
^ isSupportedMap(fieldMap.getSrcFieldType(classMap.getSrcClassToMap())) ) ) {
FieldMap fm = new MapFieldMap(fieldMap);
classMap.removeFieldMapping(fieldMap);
classMap.addFieldMapping(fm);
fieldMap = fm;
}
}