public Class<?> getDestHintType(Class<?> runtimeSrcClass) { if (getDestHintContainer() != null) { if (getSrcHintContainer() != null) { return getDestHintContainer().getHint(runtimeSrcClass, getSrcHintContainer().getHints()); } else { return getDestHintContainer().getHint(); } } else { return runtimeSrcClass; } }
@Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("source field", srcField) .append("destination field", destField) .append("type", type) .append("customConverter", customConverter) .append("relationshipType", relationshipType) .append("removeOrphans", removeOrphans) .append("mapId", mapId) .append("copyByReference", copyByReference) .append("mapNull", mapNull) .append("mapEmptyString", mapEmptyString) .append("trimString", trimString) .append("copyByReferenceOveridden", copyByReferenceOveridden) .append("srcTypeHint", getSrcHintContainer()) .append("destTypeHint", getDestHintContainer()) .append("mapCondition", mappingCondition) .append("mapConditionId", mappingConditionId) .append("collectionItemDiscriminator", collectionItemDiscriminator) .append("collectionItemDiscriminatorId", collectionItemDiscriminatorId) .toString(); }
public Class<?> getDestHintType(Class<?> runtimeSrcClass) { if (getDestHintContainer() != null) { if (getSrcHintContainer() != null) { return getDestHintContainer().getHint(runtimeSrcClass, getSrcHintContainer().getHints()); } else { return getDestHintContainer().getHint(); } } else { return runtimeSrcClass; } }
public static Class<?> determineCustomConverter(FieldMap fieldMap, Cache converterByDestTypeCache, CustomConverterContainer customConverterContainer, Class<?> srcClass, Class<?> destClass) { if (customConverterContainer == null) { return null; } // This method is messy. Just trying to isolate the junk into this one method instead of spread across the mapping // processor until a better solution can be put into place // For indexed mapping, need to use the actual class at index to determine the custom converter. if (fieldMap != null && fieldMap.isDestFieldIndexed()) { if (destClass.isArray()) { destClass = destClass.getComponentType(); } else if (destClass.isAssignableFrom(Collection.class) && fieldMap.getDestHintContainer() != null && !fieldMap.getDestHintContainer().hasMoreThanOneHint()) { // use hint when trying to find a custom converter destClass = fieldMap.getDestHintContainer().getHint(); } } return findCustomConverter(converterByDestTypeCache, customConverterContainer, srcClass, destClass); }
public Class<?> getDestHintType(Class<?> runtimeSrcClass) { if (getDestHintContainer() != null) { if (getSrcHintContainer() != null) { return getDestHintContainer().getHint(runtimeSrcClass, getSrcHintContainer().getHints()); } else { return getDestHintContainer().getHint(); } } else { return runtimeSrcClass; } }
private List<?> mapArrayToList(Object srcObj, Object srcCollectionValue, FieldMap fieldMap, Object destObj) { Class<?> destEntryType; if (fieldMap.getDestHintContainer() != null) { destEntryType = fieldMap.getDestHintContainer().getHint(); } else { destEntryType = srcCollectionValue.getClass().getComponentType(); } List<?> srcValueList; if (CollectionUtils.isPrimitiveArray(srcCollectionValue.getClass())) { srcValueList = CollectionUtils.convertPrimitiveArrayToList(srcCollectionValue); } else { srcValueList = Arrays.asList((Object[]) srcCollectionValue); } return addOrUpdateToList(srcObj, fieldMap, srcValueList, destObj, destEntryType); }
private List<?> mapArrayToList(Object srcObj, Object srcCollectionValue, FieldMap fieldMap, Object destObj, MappingContext context) { Class<?> destEntryType; if (fieldMap.getDestHintContainer() != null) { destEntryType = fieldMap.getDestHintContainer().getHint(); } else { destEntryType = srcCollectionValue.getClass().getComponentType(); } List<?> srcValueList; if (CollectionUtils.isPrimitiveArray(srcCollectionValue.getClass())) { srcValueList = CollectionUtils.convertPrimitiveArrayToList(srcCollectionValue); } else { srcValueList = Arrays.asList((Object[]) srcCollectionValue); } return addOrUpdateToList(srcObj, fieldMap, srcValueList, destObj, destEntryType, context); }
private List<?> mapArrayToList(Object srcObj, Object srcCollectionValue, FieldMap fieldMap, Object destObj, MappingContext context) { Class<?> destEntryType; if (fieldMap.getDestHintContainer() != null) { destEntryType = fieldMap.getDestHintContainer().getHint(); } else { destEntryType = srcCollectionValue.getClass().getComponentType(); } List<?> srcValueList; if (CollectionUtils.isPrimitiveArray(srcCollectionValue.getClass())) { srcValueList = CollectionUtils.convertPrimitiveArrayToList(srcCollectionValue); } else { srcValueList = Arrays.asList((Object[]) srcCollectionValue); } return addOrUpdateToList(srcObj, fieldMap, srcValueList, destObj, destEntryType, context); }
destType = destClass.getComponentType(); } else if (destClass .isAssignableFrom(Collection.class) && fieldMap.getDestHintContainer() != null && !fieldMap .getDestHintContainer().hasMoreThanOneHint()) { destType = fieldMap.getDestHintContainer().getHint();
if (destClass.isArray()) { destType = destClass.getComponentType(); } else if (destClass.isAssignableFrom(Collection.class) && fieldMap.getDestHintContainer() != null && !fieldMap.getDestHintContainer() .hasMoreThanOneHint()) { destType = fieldMap.getDestHintContainer().getHint();
for (Object srcValue : srcCollectionValue) { if (destEntryType == null || (fieldMap.getDestHintContainer() != null && fieldMap.getDestHintContainer().hasMoreThanOneHint())) { destEntryType = determineCollectionItemType(fieldMap, destObj, srcValue, prevDestEntryType);
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())); } }
if (fieldMap.getDestHintContainer() != null) { Class<?> destHintType = fieldMap.getDestHintType(srcFieldValue.getClass()); if (fieldMap.getDestHintContainer() != null && fieldMap.getDestHintContainer().getHint() != null) { targetClass = fieldMap.getDestHintContainer().getHint(); } else { targetClass = destFieldType;
if (fieldMap.getDestHintContainer() != null) { Class<?> destHintType = fieldMap.getDestHintType(srcFieldValue.getClass()); if (fieldMap.getDestHintContainer() != null && fieldMap.getDestHintContainer().getHint() != null) { targetClass = fieldMap.getDestHintContainer().getHint(); } else { targetClass = destFieldType;
public static void reverseFields(FieldMap source, FieldMap reversed) { // in case of multi-source field mapping we should use custom // implementation of exclude field map // if (source instanceof MultiSourceFieldMap) { ((MultiFieldsExcludeFieldMap) reversed) .setDest(FieldMapUtils.getCopy(((MultiSourceFieldMap) source).getSrc())); ((MultiFieldsExcludeFieldMap) reversed).setSrc(Arrays.asList(source.getDestFieldCopy())); } else { DozerField destField = source.getSrcFieldCopy(); DozerField sourceField = source.getDestFieldCopy(); reversed.setDestField(destField); reversed.setSrcField(sourceField); reversed.setSrcHintContainer(source.getDestHintContainer()); reversed.setDestHintContainer(source.getSrcHintContainer()); reversed.setSrcDeepIndexHintContainer(source.getDestDeepIndexHintContainer()); reversed.setDestDeepIndexHintContainer(source.getSrcDeepIndexHintContainer()); } reversed.setCustomConverter(source.getCustomConverter()); reversed.setCustomConverterId(source.getCustomConverterId()); reversed.setMapId(source.getMapId()); reversed.setRelationshipType(source.getRelationshipType()); reversed.setRemoveOrphans(source.isRemoveOrphans()); }
public static void reverseFields(FieldMap source, FieldMap reversed) { DozerField destField = source.getSrcFieldCopy(); DozerField sourceField = source.getDestFieldCopy(); reversed.setDestField(destField); reversed.setSrcField(sourceField); reversed.setCustomConverter(source.getCustomConverter()); reversed.setCustomConverterId(source.getCustomConverterId()); reversed.setMapId(source.getMapId()); reversed.setRelationshipType(source.getRelationshipType()); reversed.setRemoveOrphans(source.isRemoveOrphans()); reversed.setSrcHintContainer(source.getDestHintContainer()); reversed.setDestHintContainer(source.getSrcHintContainer()); reversed.setSrcDeepIndexHintContainer(source.getDestDeepIndexHintContainer()); reversed.setDestDeepIndexHintContainer(source.getSrcDeepIndexHintContainer()); }
public static void reverseFields(FieldMap source, FieldMap reversed) { // in case of multi-source field mapping we should use custom // implementation of exclude field map // if (source instanceof MultiSourceFieldMap) { ((MultiFieldsExcludeFieldMap) reversed).setDest(FieldMapUtils.getCopy(((MultiSourceFieldMap) source).getSrc())); ((MultiFieldsExcludeFieldMap) reversed).setSrc(Arrays.asList(source.getDestFieldCopy())); } else { DozerField destField = source.getSrcFieldCopy(); DozerField sourceField = source.getDestFieldCopy(); reversed.setDestField(destField); reversed.setSrcField(sourceField); reversed.setSrcHintContainer(source.getDestHintContainer()); reversed.setDestHintContainer(source.getSrcHintContainer()); reversed.setSrcDeepIndexHintContainer(source.getDestDeepIndexHintContainer()); reversed.setDestDeepIndexHintContainer(source.getSrcDeepIndexHintContainer()); } reversed.setCustomConverter(source.getCustomConverter()); reversed.setCustomConverterId(source.getCustomConverterId()); reversed.setMapId(source.getMapId()); reversed.setRelationshipType(source.getRelationshipType()); reversed.setRemoveOrphans(source.isRemoveOrphans()); }
public MapFieldMap(FieldMap fieldMap) { // Create from existing field map super(fieldMap.getClassMap()); setCopyByReference(fieldMap.isCopyByReference()); setCustomConverter(fieldMap.getCustomConverter()); setCustomConverterId(fieldMap.getCustomConverterId()); setCustomConverterParam(fieldMap.getCustomConverterParam()); setDestField(fieldMap.getDestField()); setDestHintContainer(fieldMap.getDestHintContainer()); setDestDeepIndexHintContainer(fieldMap.getDestDeepIndexHintContainer()); setMapId(fieldMap.getMapId()); setRelationshipType(fieldMap.getRelationshipType()); setRemoveOrphans(fieldMap.isRemoveOrphans()); setSrcField(fieldMap.getSrcField()); setSrcHintContainer(fieldMap.getSrcHintContainer()); setSrcDeepIndexHintContainer(fieldMap.getSrcDeepIndexHintContainer()); setType(fieldMap.getType()); }
public MapFieldMap(FieldMap fieldMap) { //Create from existing field map super(fieldMap.getClassMap()); setCopyByReference(fieldMap.isCopyByReference()); setCustomConverter(fieldMap.getCustomConverter()); setCustomConverterId(fieldMap.getCustomConverterId()); setCustomConverterParam(fieldMap.getCustomConverterParam()); setDestField(fieldMap.getDestField()); setDestHintContainer(fieldMap.getDestHintContainer()); setDestDeepIndexHintContainer(fieldMap.getDestDeepIndexHintContainer()); setMapId(fieldMap.getMapId()); setRelationshipType(fieldMap.getRelationshipType()); setRemoveOrphans(fieldMap.isRemoveOrphans()); setSrcField(fieldMap.getSrcField()); setSrcHintContainer(fieldMap.getSrcHintContainer()); setSrcDeepIndexHintContainer(fieldMap.getSrcDeepIndexHintContainer()); setType(fieldMap.getType()); }
public MapFieldMap(FieldMap fieldMap) { // Create from existing field map super(fieldMap.getClassMap()); setCopyByReference(fieldMap.isCopyByReference()); setCustomConverter(fieldMap.getCustomConverter()); setCustomConverterId(fieldMap.getCustomConverterId()); setCustomConverterParam(fieldMap.getCustomConverterParam()); setDestField(fieldMap.getDestField()); setDestHintContainer(fieldMap.getDestHintContainer()); setDestDeepIndexHintContainer(fieldMap.getDestDeepIndexHintContainer()); setMapId(fieldMap.getMapId()); setRelationshipType(fieldMap.getRelationshipType()); setRemoveOrphans(fieldMap.isRemoveOrphans()); setSrcField(fieldMap.getSrcField()); setSrcHintContainer(fieldMap.getSrcHintContainer()); setSrcDeepIndexHintContainer(fieldMap.getSrcDeepIndexHintContainer()); setType(fieldMap.getType()); }