田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.vci.client.uif.engine.common;
 
import java.util.HashMap;
import java.util.Map;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientBusinessObjectOperation;
import com.vci.client.bof.ClientLinkObject;
import com.vci.corba.common.VCIError;
 
public abstract class AbstractDataNode implements IDataNode {
 
    protected Object masterObject = null;
    protected Map<String, String> valueMap = new HashMap<String, String>();
    protected boolean isForward = true;
    private Object customObject = null;
    
    @Override
    public Object getMaterObject() {
        return this.masterObject;
    }
 
    @Override
    public Map<String, String> getValueMap() {
        return this.valueMap;
    }
    
    @Override
    public Object getCustomObject() {
        return this.customObject;
    }
    
    @Override
    public void setCustomObject(Object customObject) {
        this.customObject = customObject;
    }
 
    @Override
    public void setMasterObject(Object masterObject) {
        this.masterObject = masterObject;
    }
 
    @Override
    public void setValueMap(Map<String, String> valueMap) {
        this.valueMap = valueMap;
    }
 
    @Override
    public boolean isForward() {
        return this.isForward;
    }
    
    @Override
    public void setForward(boolean isForward) {
        this.isForward = isForward;
    }
    
 
    /**
     * 返回节点对应的ClientBusinessObject对象。
     * @return
     */
    @Override
    public ClientBusinessObject getClientBusinessObject(){
        if(cbo == null){
            toString();
        }
        return cbo;
    }
    
    private boolean cboIsLoaded = false;
    private ClientBusinessObject cbo = null;
    @Override
    public String toString(){
        /**
         * toString() 执行策略
         * 如果 ${id} != ${name},则返回 ${id}+空格+${name}
         * 否则 返回  ${id}+空格+${desc}
         */
        String res = "";
        if(getMaterObject() instanceof ClientBusinessObject){
            cbo = (ClientBusinessObject)getMaterObject();
        } else if(getMaterObject() instanceof ClientLinkObject){
            ClientLinkObject clo = (ClientLinkObject)getMaterObject();
            if(!cboIsLoaded){
                cbo = getBOByLO(clo);
                cboIsLoaded = true;
            }
        }
        if(cbo != null){
            String id = getBOAttrVal(cbo, "ID");
            res = id;
            
            String name = getBOAttrVal(cbo, "NAME");
            if(!id.equals(name)){
                res += " " + name;
            } else{
                String desc = getBOAttrVal(cbo, "DESCRIPTION");
                res += " " + desc;
            }
        }
        return res;
    }
    
    private ClientBusinessObject getBOByLO(ClientLinkObject clo){
        ClientBusinessObjectOperation operation = new ClientBusinessObjectOperation();
        String oid = CBOHelper.getBusinessObjectOid(this);
        String type = CBOHelper.getBusinessObjectType(this);
        try {
            cbo = operation.readBusinessObjectById(oid, type);
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return cbo;
    }
 
    private String getBOAttrVal(ClientBusinessObject cbo, String attrName){
        return cbo.getAttributeValue(attrName);
    }
}