public String getMapId() { return classMap.getMapId(); }
public void failOnDuplicate(Object result, ClassMap classMap) { if (result != null && !classMap.getSrcClassName().equals(classMap.getDestClassName())) { throw new IllegalArgumentException("Duplicate Class Mapping Found. Source: " + classMap.getSrcClassName() + " Destination: " + classMap.getDestClassName() + " map-id: " + classMap.getMapId()); } }
public void failOnDuplicate(Object result, ClassMap classMap) { if (result != null && !classMap.getSrcClassName().equals(classMap.getDestClassName())) { throw new IllegalArgumentException( "Duplicate Class Mapping Found. Source: " + classMap.getSrcClassName() + " Destination: " + classMap .getDestClassName() + " map-id: " + classMap.getMapId()); } }
public ClassMap find(Class<?> srcClass, Class<?> destClass, String mapId) { final String key = keyFactory.createKey(srcClass, destClass, mapId); ClassMap mapping = classMappings.get(key); if (mapping == null) { mapping = findInterfaceMapping(destClass, srcClass, mapId); } // one more try... // if the mapId is not null looking up a map is easy if (!MappingUtils.isBlankOrNull(mapId) && mapping == null) { // probably a more efficient way to do this... for (Entry<String, ClassMap> entry : classMappings.entrySet()) { ClassMap classMap = entry.getValue(); if (StringUtils.equals(classMap.getMapId(), mapId) && classMap.getSrcClassToMap().isAssignableFrom(srcClass) && classMap.getDestClassToMap().isAssignableFrom(destClass)) { return classMap; } else if (StringUtils.equals(classMap.getMapId(), mapId) && srcClass.equals(destClass)) { return classMap; } } // If map-id was specified and mapping was not found, then fail MappingUtils.throwMappingException("Class mapping not found by map-id: " + key); } return mapping; }
public ClassMap find(Class<?> srcClass, Class<?> destClass, String mapId) { final String key = keyFactory.createKey(srcClass, destClass, mapId); ClassMap mapping = classMappings.get(key); if (mapping == null) { mapping = findInterfaceMapping(destClass, srcClass, mapId); } // one more try... // if the mapId is not null looking up a map is easy if (!MappingUtils.isBlankOrNull(mapId) && mapping == null) { // probably a more efficient way to do this... for (Entry<String, ClassMap> entry : classMappings.entrySet()) { ClassMap classMap = entry.getValue(); if (StringUtils.equals(classMap.getMapId(), mapId) && classMap.getSrcClassToMap() .isAssignableFrom(srcClass) && classMap.getDestClassToMap().isAssignableFrom(destClass)) { return classMap; } else if (StringUtils.equals(classMap.getMapId(), mapId) && srcClass.equals(destClass)) { return classMap; } } // If map-id was specified and mapping was not found, then fail MappingUtils.throwMappingException("Class mapping not found by map-id: " + key); } return mapping; }
private ClassMap findInterfaceMapping(Class<?> destClass, Class<?> srcClass, String mapId) { // Use object array for keys to avoid any rare thread synchronization issues // while iterating over the custom mappings. // See bug #1550275. Object[] keys = classMappings.keySet().toArray(); for (Object key : keys) { ClassMap map = classMappings.get(key); Class<?> mappingDestClass = map.getDestClassToMap(); Class<?> mappingSrcClass = map.getSrcClassToMap(); if ((mapId == null && map.getMapId() != null) || (mapId != null && !mapId.equals(map.getMapId()))) { continue; } if (isInterfaceImplementation(srcClass, mappingSrcClass)) { if (isInterfaceImplementation(destClass, mappingDestClass)) { return map; } else if (destClass.equals(mappingDestClass)) { return map; } } // Destination could be an abstract type. Picking up the best concrete type to use. if ((destClass.isAssignableFrom(mappingDestClass) && isAbstract(destClass)) || (isInterfaceImplementation(destClass, mappingDestClass))) { if (MappingUtils.getRealClass(srcClass).equals(mappingSrcClass)) { return map; } } } return null; }
private void mapFromIterateMethodFieldMap(Object srcObj, Object destObj, Object srcFieldValue, FieldMap fieldMapping) { // Iterate over the destFieldValue - iterating is fine unless we are mapping // in the other direction. // Verify that it is truly a collection if it is an iterator object turn it // into a List if (srcFieldValue instanceof Iterator) { srcFieldValue = IteratorUtils.toList((Iterator<?>) srcFieldValue); } if (srcFieldValue != null) { for (int i = 0; i < CollectionUtils.getLengthOfCollection(srcFieldValue); i++) { final Object value = CollectionUtils.getValueFromCollection(srcFieldValue, i); // map this value if (fieldMapping.getDestHintContainer() == null) { MappingUtils.throwMappingException("<field type=\"iterate\"> must have a source or destination type hint"); } Class<?> destinationHint = fieldMapping.getDestHintType(value.getClass()); Object result = mapOrRecurseObject(srcObj, value, destinationHint, fieldMapping, destObj); if (value != null) { writeDestinationValue(destObj, result, fieldMapping, srcObj); } } } if (log.isDebugEnabled()) { log.debug(logMsgFactory.createFieldMappingSuccessMsg(srcObj.getClass(), destObj.getClass(), fieldMapping.getSrcFieldName(), fieldMapping.getDestFieldName(), srcFieldValue, null, fieldMapping.getClassMap().getMapId())); } }
fieldMapping.getDestFieldName(), srcFieldValue, destFieldValue, fieldMapping.getClassMap().getMapId()));
log.debug(LogMsgFactory.createFieldMappingSuccessMsg(srcObj.getClass(), destObj.getClass(), fieldMapping .getSrcFieldName(), fieldMapping.getDestFieldName(), srcFieldValue, null, fieldMapping.getClassMap() .getMapId()));
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); result.add(classMap.getDestClassToMap(), classMap.getSrcClassToMap(), classMap.getMapId(), classMapPrime);
srcFieldValue, null, fieldMapping.getClassMap().getMapId()));
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); result.add(classMap.getDestClassToMap(), classMap.getSrcClassToMap(), classMap.getMapId(), classMapPrime);
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); result.add(classMap.getDestClassToMap(), classMap.getSrcClassToMap(), classMap.getMapId(), classMapPrime);
public static void reverseFields(ClassMap source, ClassMap destination) { // reverse the fields destination.setSrcClass(new DozerClass(source.getDestClassName(), source.getDestClassToMap(), source.getDestClassBeanFactory(), source.getDestClassBeanFactoryId(), source.getDestClassMapGetMethod(), source.getDestClassMapSetMethod(), source.getDestClass().getCreateMethod(), source.isDestMapNull(), source.isDestMapEmptyString(), source.getDestClass().isAccesible())); destination.setDestClass(new DozerClass(source.getSrcClassName(), source.getSrcClassToMap(), source.getSrcClassBeanFactory(), source.getSrcClassBeanFactoryId(), source.getSrcClassMapGetMethod(), source.getSrcClassMapSetMethod(), source.getSrcClass().getCreateMethod(), source.isSrcMapNull(), source.isSrcMapEmptyString(), source.getSrcClass().isAccesible())); destination.setType(source.getType()); destination.setWildcard(source.isWildcard()); destination.setTrimStrings(source.isTrimStrings()); destination.setDateFormat(source.getDateFormat()); destination.setRelationshipType(source.getRelationshipType()); destination.setStopOnErrors(source.isStopOnErrors()); destination.setAllowedExceptions(source.getAllowedExceptions()); destination.setSrcClassCreateMethod(source.getDestClassCreateMethod()); destination.setDestClassCreateMethod(source.getSrcClassCreateMethod()); if (StringUtils.isNotEmpty(source.getMapId())) { destination.setMapId(source.getMapId()); } }