ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.vci.server.bof.delegate;
 
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.LinkObject;
 
public class LOFacotryBaseDelegate extends FactoryBaseDelegate{
 
 
    /**
     * 克隆一全新的LinkObject
     * @param loSrc 原始 LinkObject
     * @return 全新的 LinkObject
     * <p>如果 loSrc == null 或 loSrc != null 且 loSrc.linkTypeName 为空,返回一个 null,否则返回克隆的对象 </p>
     * @throws VCIError
     */
    public LinkObject cloneLinkObject(LinkObject loSrc) throws VCIError{
        if(loSrc == null ) return null;
        if("".equals(loSrc.ltName)) return null;
        
        LinkObject lo = getNewEmptyLinkObject(loSrc.ltName);
        lo = initLinkTypeBaseAttr(lo, 
                loSrc.creator, loSrc.createTime, 
                loSrc.modifier, loSrc.modifyTime, 
                loSrc.fromOid, loSrc.fromRevOid, loSrc.fromNameOid, loSrc.fromBTName, 
                loSrc.toOid, loSrc.toRevOid, loSrc.toNameOid, loSrc.toBTName);
        lo.newAttrValList = cloneAttrVals(loSrc.newAttrValList);
        lo.hisAttrValList = cloneAttrVals(loSrc.hisAttrValList);
        return lo;
    }
    
    protected AttributeValue[] cloneAttrVals(AttributeValue[] srcAttrVals){
        AttributeValue[] destAttrVals = new AttributeValue[0];
        if(srcAttrVals == null || srcAttrVals.length == 0) return destAttrVals;
        destAttrVals = new AttributeValue[srcAttrVals.length];
        for (int i = 0; i < destAttrVals.length; i++) {
            destAttrVals[i] = new AttributeValue(srcAttrVals[i].attrName, srcAttrVals[i].attrVal);
        }
        return destAttrVals;
    }
    
    protected LinkObject getNewEmptyLinkObject(String linkTypeName){
        LinkObject lo = new LinkObject();
        lo.oid = ObjectUtility.getNewObjectID36();
        lo.ltName = linkTypeName;
        lo = initLinkTypeBaseAttr(lo, 
                HibernateSessionFactory.getVciSessionInfo().userName, 
                System.currentTimeMillis(), 
                HibernateSessionFactory.getVciSessionInfo().userName, 
                System.currentTimeMillis(), 
                "", "", "", "", 
                "", "", "", "");
        return lo;
    }
 
    protected LinkObject initLinkTypeBaseAttr(
            LinkObject lo,
            String creator, long createTime, String lastModifier, long lastModifyTime,
        String fromOid, String fromRevisionOid, String fromNameOid, String fromBtmName,
        String toOid, String toRevisionOid, String toNameOid, String toBtmName){
        lo.creator = creator;
        lo.createTime = createTime;
        lo.modifier = lastModifier;
        lo.modifyTime = lastModifyTime;
        lo.fromOid = fromOid;
        lo.fromRevOid = fromRevisionOid;
        lo.fromNameOid = fromNameOid;
        lo.fromBTName = fromBtmName;
        lo.toOid = toOid;
        lo.toRevOid = toRevisionOid;
        lo.toNameOid = toNameOid;
        lo.toBTName = toBtmName;
        lo.newAttrValList = new AttributeValue[0];
        lo.hisAttrValList = new AttributeValue[0];
        return lo;
    }
    
}