package com.hcy.rabbitbasicutils.beans;
import org.apache.commons.lang3.StringUtils;
import org.dozer.*;
import org.dozer.builder.BuilderUtil;
import org.dozer.builder.DestBeanBuilderCreator;
import org.dozer.cache.Cache;
import org.dozer.cache.CacheKeyFactory;
import org.dozer.cache.CacheManager;
import org.dozer.cache.DozerCacheType;
import org.dozer.classmap.*;
import org.dozer.converters.DateFormatContainer;
import org.dozer.converters.PrimitiveOrWrapperConverter;
import org.dozer.event.DozerEvent;
import org.dozer.event.DozerEventManager;
import org.dozer.event.DozerEventType;
import org.dozer.event.EventManager;
import org.dozer.factory.BeanCreationDirective;
import org.dozer.factory.DestBeanCreator;
import org.dozer.fieldmap.*;
import org.dozer.stats.StatisticType;
import org.dozer.stats.StatisticsManager;
import org.dozer.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.Map.Entry;
import static org.dozer.util.DozerConstants.BASE_CLASS;
import static org.dozer.util.DozerConstants.ITERATE;
public class MappingProcessor implements Mapper {
private final Logger log = LoggerFactory.getLogger(MappingProcessor.class);
private final ClassMappings classMappings;
private final Configuration globalConfiguration;
private final List<CustomConverter> customConverterObjects;
private final Map<String, CustomConverter> customConverterObjectsWithId;
private final StatisticsManager statsMgr;
private final EventManager eventMgr;
private final CustomFieldMapper customFieldMapper;
private final MappedFieldsTracker mappedFields = new MappedFieldsTracker();
private final Cache converterByDestTypeCache;
private final Cache superTypeCache;
private final PrimitiveOrWrapperConverter primitiveConverter = new PrimitiveOrWrapperConverter();
private final LogMsgFactory logMsgFactory = new LogMsgFactory();
protected MappingProcessor(ClassMappings classMappings, Configuration globalConfiguration, CacheManager cacheMgr,
StatisticsManager statsMgr, List<CustomConverter> customConverterObjects,
DozerEventManager eventManager, CustomFieldMapper customFieldMapper,
Map<String, CustomConverter> customConverterObjectsWithId) {
this.classMappings = classMappings;
this.globalConfiguration = globalConfiguration;
this.statsMgr = statsMgr;
this.customConverterObjects = customConverterObjects;
this.eventMgr = eventManager;
this.customFieldMapper = customFieldMapper;
this.converterByDestTypeCache = cacheMgr.getCache(DozerCacheType.CONVERTER_BY_DEST_TYPE.name());
this.superTypeCache = cacheMgr.getCache(DozerCacheType.SUPER_TYPE_CHECK.name());
this.customConverterObjectsWithId = customConverterObjectsWithId;
}
/* Mapper Interface Implementation */
public <T> T map(final Object srcObj, final Class<T> destClass) {
return map(srcObj, destClass, null);
}
public <T> T map(final Object srcObj, final Class<T> destClass, final String mapId) {
MappingValidator.validateMappingRequest(srcObj, destClass);
return mapGeneral(srcObj, destClass, null, mapId);
}
public void map(final Object srcObj, final Object destObj) {
map(srcObj, destObj, null);
}
public void map(final Object srcObj, final Object destObj, final String mapId) {
MappingValidator.validateMappingRequest(srcObj, destObj);
mapGeneral(srcObj, null, destObj, mapId);
}
/* End of Mapper Interface Implementation */
/**
* Single point of entry for atomic mapping operations
*
* @param srcObj source object
* @param destClass destination class
* @param destObj destination object
* @param mapId mapping identifier
* @param <T> destination object type
* @return new or updated destination object
*/
private <T> T mapGeneral(Object srcObj, final Class<T> destClass, final T destObj, final String mapId) {
srcObj = MappingUtils.deProxy(srcObj);
Class<T> destType;
T result;
if (destClass == null) {
destType = (Class<T>) destObj.getClass();
result = destObj;
} else {
destType = destClass;
result = null;
}
ClassMap classMap = null;
try {
classMap = getClassMap(srcObj.getClass(), destType, mapId);
eventMgr.fireEvent(new DozerEvent(DozerEventType.MAPPING_STARTED, classMap, null, srcObj, result, null));
// TODO Check if any proxy issues are here
// Check to see if custom converter has been specified for this mapping
// combination. If so, just use it.
Class<?> converterClass = MappingUtils.findCustomConverter(converterByDestTypeCache, classMap.getCustomConverters(), srcObj
.getClass(), destType);
if (destObj == null) {
// If this is a nested MapperAware conversion this mapping can be already processed
// but we can do this optimization only in case of no destObject, instead we must copy to the dest object
Object alreadyMappedValue = mappedFields.getMappedValue(srcObj, destType);
if (alreadyMappedValue != null) {
return (T) alreadyMappedValue;
}
}
if (converterClass != null) {
return (T) mapUsingCustomConverter(converterClass, srcObj.getClass(), srcObj, destType, result, null, true);
}
BeanCreationDirective creationDirective =
new BeanCreationDirective(srcObj, classMap.getSrcClassToMap(), classMap.getDestClassToMap(), destType,
classMap.getDestClassBeanFactory(), classMap.getDestClassBeanFactoryId(), classMap.getDestClassCreateMethod());
result = createByCreationDirectiveAndMap(creationDirective, classMap, srcObj, result, false, null);
} catch (Throwable e) {
MappingUtils.throwMappingException(e);
}
eventMgr.fireEvent(new DozerEvent(DozerEventType.MAPPING_FINISHED, classMap, null, srcObj, result, null));
return result;
}
/**
* Create builder or target object if needed and call
* {@link MappingProcessor#mapToDestObject(ClassMap, Object, Object, boolean, String)} function with
* arguments {@code classMap}, {@code srcObj}, {@code result}, {@code bypassSuperMappings}, {@code mapId}
* @param creationDirective directive for concrete mapping (based mostly on {@code classMap})
* @param classMap class map information for concrete class
* @param srcObj source object
* @param result target entity for mapping
* @param bypassSuperMappings //TODO
* @param mapId mapping identifier
* @return result or created target entity for mapping
*/
private <T> T createByCreationDirectiveAndMap(BeanCreationDirective creationDirective, ClassMap classMap, Object srcObj, T result, boolean bypassSuperMappings, String mapId) {
if (result == null) {
BeanBuilder beanBuilder = DestBeanBuilderCreator.create(creationDirective);
if (beanBuilder == null) {
result = (T) DestBeanCreator.create(creationDirective);
mapToDestObject(classMap, srcObj, result, bypassSuperMappings, mapId);
} else {
mapToDestObject(classMap, srcObj, beanBuilder, bypassSuperMappings, mapId);
result = (T) beanBuilder.build();
}
} else {
mapToDestObject(classMap, srcObj, result, bypassSuperMappings, mapId);
}
return result;
}
/**
* This function used to map into created instance of destination class
* @param classMap object with mapping configuration
* @param srcObj source object
* @param de
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
该项目是一款基于Java和Lua语言的分布式微服务架构网约车系统源码,包含852个文件,其中包括493个Java源文件、90个XML配置文件、65个属性文件、51个Git忽略文件、49个命令行文件、39个JAR包文件、12个YAML配置文件和2个Markdown文件。该系统采用微服务架构,适用于构建灵活、可扩展的网约车服务。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java和Lua的分布式微服务网约车项目设计源码 (851个子文件)
mvnw.cmd 7KB
mvnw.cmd 7KB
mvnw.cmd 7KB
mvnw.cmd 7KB
mvnw.cmd 7KB
mvnw.cmd 7KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 395B
.gitignore 377B
.gitignore 246B
共 851 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
沐知全栈开发
- 粉丝: 5706
- 资源: 5216
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于Spring Boot和Vue的分布式权限管理系统.zip
- (源码)基于Spring Boot框架的后台管理系统.zip
- (源码)基于Spring Boot和Vue的高性能售票系统.zip
- (源码)基于Windows API的USB设备通信系统.zip
- (源码)基于Spring Boot框架的进销存管理系统.zip
- (源码)基于Java和JavaFX的学生管理系统.zip
- (源码)基于C语言和Easyx库的内存分配模拟系统.zip
- (源码)基于WPF和EdgeTTS的桌宠插件系统.zip
- (源码)基于PonyText的文本排版与预处理系统.zip
- joi_240913_8.8.0_73327_share-2EM46K.apk
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功