com.agapple.mapping.BeanCopy Maven / Gradle / Ivy
package com.agapple.mapping;
import com.agapple.mapping.core.BeanMappingException;
import com.agapple.mapping.core.BeanMappingExecutor;
import com.agapple.mapping.core.BeanMappingParam;
import com.agapple.mapping.core.config.BeanMappingConfigHelper;
import com.agapple.mapping.core.config.BeanMappingEnvironment;
import com.agapple.mapping.core.config.BeanMappingObject;
/**
* Bean copy操作的处理单元
*
*
*
* 使用例子:
* BeanCopy beanCopy = BeanCopy.create(srcClass , targetClass);
* beanCopy.copy(src,target);//完成copy动作
*
*
*
* @author jianghang 2011-6-8 上午11:10:47
*/
public class BeanCopy {
private BeanMappingObject config; // 对应的Bean Mapping配置
BeanCopy(BeanMappingObject config){
this.config = config;
}
/**
* 创建srcClass和targetClass之间的BeanCopy操作
*/
public static BeanCopy create(Class srcClass, Class targetClass) {
BeanMappingObject config = BeanMappingConfigHelper.getInstance().getBeanMappingObject(srcClass, targetClass,
true);
return new BeanCopy(config);
}
/**
* 对象属性的拷贝,与BeanUtils , BeanCopier功能类似
*
* @param src
* @param target
* @throws BeanMappingException
*/
public void copy(Object src, Object target) throws BeanMappingException {
BeanMappingParam param = new BeanMappingParam();
param.setSrcRef(src);
param.setTargetRef(target);
param.setConfig(this.config);
param.setProcesses(BeanMappingEnvironment.getBeanCopyVps());
// 执行mapping处理
BeanMappingExecutor.execute(param);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy