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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package com.vci.omd.utils;
 
import java.util.ArrayList;
 
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.data.LinkObject;
 
 
/**
 * 获取业务对象或链接对象的属性值信息
 * @author VCI_STGK_Lincq
 *
 */
public class ObjectTool {
 
 
    /**
     * 获取业务对象的属性信息
     * @param bo
     * @param attrName
     * @return
     */
    public static String getBOAttributeValue(BusinessObject bo, String attrName) {
        for (int i = 0; i < bo.hisAttrValList.length; i++) {
            if (bo.hisAttrValList[i].attrName.equalsIgnoreCase(attrName)) {
                return bo.hisAttrValList[i].attrVal;
            }
        }
        return "";
    }
    
    /**
     * 获取链接对象的属性信息
     * @param lo
     * @param attrName
     * @return
     */
    public static String getLOAttributeValue(LinkObject lo, String attrName) {
        for (int i = 0; i < lo.hisAttrValList.length; i++) {
            if (lo.hisAttrValList[i].attrName.equalsIgnoreCase(attrName)) {
                return lo.hisAttrValList[i].attrVal;
            }
        }
        return "";
    }
    
    /**
     * 获取业务对象中新设置的属性信息
     * @param bo
     * @param attrName
     * @return
     */
    public static String getNewBOAttributeValue(BusinessObject bo, String attrName) {
        for (int i = 0; i < bo.newAttrValList.length; i++) {
            if (bo.newAttrValList[i].attrName.equalsIgnoreCase(attrName)) {
                return bo.newAttrValList[i].attrVal;
            }
        }
        return "";
    }
    
    /**
     * 获取链接对象的新设置属性信息
     * @param lo
     * @param attrName
     * @return
     */
    public static String getNewLOAttributeValue(LinkObject lo, String attrName) {
        for (int i = 0; i < lo.newAttrValList.length; i++) {
            if (lo.newAttrValList[i].attrName.equalsIgnoreCase(attrName)) {
                return lo.newAttrValList[i].attrVal;
            }
        }
        return "";
    }
    
    public static void setBOAttributeValue(BusinessObject businessObject, String attributeName, String attributeValue) {
        AttributeValue[] attrValues = businessObject.newAttrValList;
        ArrayList<AttributeValue> attrValList = new ArrayList<AttributeValue>();
        if (attrValues != null && attrValues.length > 0) {
            for (AttributeValue attrVal: attrValues) {
                attrValList.add(attrVal);
            }
        }
        AttributeValue attrVal = null;
        boolean isExist = false;
        for (int i = 0; i < attrValList.size(); i++) {
            attrVal = attrValList.get(i);
            if (attrVal.attrName.equalsIgnoreCase(attributeName)) {
                attrVal.attrVal = attributeValue;
                isExist = true;
                break;
            }
        }
        if (!isExist) {
            attrVal = new AttributeValue();
            attrVal.attrName = attributeName;
            attrVal.attrVal = attributeValue;
            attrValList.add(attrVal);
        }
        businessObject.newAttrValList = attrValList.toArray(new AttributeValue[attrValList.size()]);
    }
    
    public static void setLOAttributeValue(LinkObject linkObject, String attributeName, String attributeValue) {
        AttributeValue[] attrValues = linkObject.newAttrValList;
        ArrayList<AttributeValue> attrValList = new ArrayList<AttributeValue>();
        if (attrValues != null && attrValues.length > 0) {
            for (AttributeValue attrVal: attrValues) {
                attrValList.add(attrVal);
            }
        }
        AttributeValue attrVal = null;
        boolean isExist = false;
        for (int i = 0; i < attrValList.size(); i++) {
            attrVal = attrValList.get(i);
            if (attrVal.attrName.equalsIgnoreCase(attributeName)) {
                attrVal.attrVal = attributeValue;
                isExist = true;
                break;
            }
        }
        if (!isExist) {
            attrVal = new AttributeValue();
            attrVal.attrName = attributeName;
            attrVal.attrVal = attributeValue;
            attrValList.add(attrVal);
        }
        linkObject.newAttrValList = attrValList.toArray(new AttributeValue[attrValList.size()]);
    }
    
    public static void setLOFromBO(LinkObject lo, BusinessObject fromBo) {
        lo.fromOid = fromBo.oid;
        lo.fromRevOid = fromBo.revisionid;
        lo.fromNameOid = fromBo.nameoid;
        lo.fromBTName = fromBo.btName;
    }
    
    public static void setLOToBO(LinkObject lo, BusinessObject toBo) {
        lo.toOid = toBo.oid;
        lo.toRevOid = toBo.revisionid;
        lo.toNameOid = toBo.nameoid;
        lo.toBTName = toBo.btName;
    }
    
    /**
     * 设置业务对象的历史属性值
     * @param bo
     * @param attrName
     * @param attrVal
     */
    public static void setHisBOAttributeValue(BusinessObject bo, String attrName, String attrVal) {
        if (attrVal == null) {
            attrVal = "";
        }
        for (int i = 0; i < bo.hisAttrValList.length; i++) {
            if (bo.hisAttrValList[i].attrName.equalsIgnoreCase(attrName)) {
                bo.hisAttrValList[i].attrVal = attrVal;
                return;
            }
        }
    }
    
    /**
     * 设置链接对象的历史属性值
     * @param lo
     * @param attrName
     * @param attrVal
     */
    public static void setLOHisAttributeValue(LinkObject lo, String attrName, String attrVal) {
        if (attrVal == null) {
            attrVal = "";
        }
        for (int i = 0; i < lo.hisAttrValList.length; i++) {
            if (lo.hisAttrValList[i].attrName.equalsIgnoreCase(attrName)) {
                lo.hisAttrValList[i].attrVal = attrVal;
            }
        }
    }
}