package com.vci.client.uif.engine.client.compare.dialog.treenode;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import com.vci.client.bof.ClientBusinessObject;
|
import com.vci.client.bof.ClientLinkObject;
|
import com.vci.client.uif.engine.client.compare.dataloader.DataLoader;
|
import com.vci.client.uif.engine.client.compare.enumeration.CompareState;
|
|
/**
|
* 树节点对象工厂类
|
* @author VCI-STGK006
|
*
|
*/
|
public class BusinessTreeNodeObjectFactory implements TreeNodeObjectFactory {
|
|
/**
|
* 节点对象列表
|
*/
|
private Map<String, BusinessTreeNodeObject> objectMap = new HashMap<String, BusinessTreeNodeObject>();
|
|
/**
|
* 主对象列表
|
*/
|
private Map<String, BusinessTreeNodeObject.MainObject> mianMap = new HashMap<String, BusinessTreeNodeObject.MainObject>();
|
|
/**
|
* 数据加载器
|
*/
|
private DataLoader<ClientBusinessObject, ClientLinkObject> dataloader = null;
|
|
/**
|
* 构造器
|
* @param dataloader
|
*/
|
public BusinessTreeNodeObjectFactory(DataLoader dataloader) {
|
this.dataloader = dataloader;
|
}
|
|
@Override
|
public TreeNodeObject getTreeNodeObject(TreeNodeObject parent,
|
Object relationObject, Object mainObject, boolean isRoot) {
|
String mainKey = "";
|
String relationKey = "";
|
if(mainObject != null) {
|
mainKey = this.dataloader.getKey(mainObject);
|
}
|
if(relationObject != null) {
|
relationKey = this.dataloader.getKey(relationObject);
|
}
|
if(isRoot) {
|
if(mainObject == null) {
|
throw new IllegalArgumentException("根节点主对象为空!");
|
}
|
return getRoot(mainKey, (ClientBusinessObject) mainObject);
|
} else {
|
//如果父节点为空节点,返回一个空节点
|
if(parent.getCompareState() == CompareState.ISNULL) {
|
return getNullNodeObject();
|
}
|
//如果主对象不存在
|
if(mainKey.equals("")) {
|
//构建返回空节点
|
return getNullNodeObject();
|
}
|
//判断节点对象是否存在
|
if(this.objectMap.containsKey(relationKey + "##" + mainKey)) {
|
return this.objectMap.get(relationKey + "##" + mainKey);
|
} else {
|
BusinessTreeNodeObject btno = new BusinessTreeNodeObject();
|
//判断主对象是否存在
|
if(this.mianMap.containsKey(mainKey)) {
|
btno.setMo(this.mianMap.get(mainKey));
|
} else {
|
BusinessTreeNodeObject.MainObject mo = btno.getMo();
|
mo.setKey(mainKey);
|
mo.setCbo((ClientBusinessObject)mainObject);
|
mo.setOwnedNodeObject(btno);
|
this.mianMap.put(mainKey, mo);
|
}
|
//设置关系属性
|
BusinessTreeNodeObject.RelationObject ro = btno.getRo();
|
ro.setKey(relationKey);
|
ro.setClo((ClientLinkObject)relationObject);
|
this.objectMap.put(relationKey + "##" + mainKey, btno);
|
return btno;
|
}
|
}
|
}
|
|
/**
|
* 得到根节点
|
* @param key
|
* @param cbo
|
* @return
|
*/
|
private TreeNodeObject getRoot(String key, ClientBusinessObject cbo) {
|
BusinessTreeNodeObject btno = new BusinessTreeNodeObject();
|
btno.setIsRoot(true);
|
btno.setMainKey(key);
|
btno.setMainCbo(cbo);
|
return btno;
|
}
|
|
/**
|
* 创建空节点
|
* @return
|
*/
|
private TreeNodeObject getNullNodeObject() {
|
BusinessTreeNodeObject btno = new BusinessTreeNodeObject();
|
btno.setCompareState(CompareState.ISNULL);
|
return btno;
|
}
|
}
|