wangting
2024-09-27 a3e87f78ee262ca9bb7d9b0c997639d5f3295890
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
package com.vci.client.uif.actions.client;
 
import java.awt.Component;
import java.awt.Window;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
 
import javax.swing.JOptionPane;
 
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Workbook;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientBusinessObjectOperation;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.bof.ClientLinkObjectOperation;
import com.vci.client.common.ConfigUtils;
import com.vci.client.common.FreeMarkerCommon;
import com.vci.client.common.FreemarkerParamObject;
import com.vci.client.common.PositionMessager;
import com.vci.client.common.oq.OQTool;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.client.omd.attribpool.ui.APClient;
import com.vci.client.omd.btm.ui.BtmClient;
import com.vci.client.omd.lifecycle.LifeCycleStart;
import com.vci.client.oq.QTClient;
import com.vci.client.oq.QTDClient;
import com.vci.client.portal.utility.PRM;
import com.vci.client.portal.utility.PRMItem;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.client.uif.engine.client.IRegionPanel;
import com.vci.client.uif.engine.client.combobox.IComboBoxDataProvider;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.client.uif.engine.common.UIFUtilsCommon;
import com.vci.client.utils.excel.ExcelCellStyleSettingCallback;
import com.vci.client.utils.excel.ExcelDocumentUtils;
import com.vci.client.utils.excel.ExcelFileOperation;
import com.vci.client.utils.excel.SheetDataSet;
import com.vci.client.utils.excel.WorkboolStyleSetting;
import com.vci.common.qt.object.Condition;
import com.vci.common.qt.object.ConditionItem;
import com.vci.common.qt.object.LeafInfo;
import com.vci.common.qt.object.LeafValue;
import com.vci.common.qt.object.Operator;
import com.vci.common.qt.object.QueryTemplate;
import com.vci.common.qt.object.Version;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.corba.omd.btm.BtmAndApName;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.data.LinkObject;
import com.vci.corba.omd.etm.EnumChild;
import com.vci.corba.omd.etm.EnumItem;
import com.vci.corba.omd.lcm.LifeCycle;
import com.vci.corba.omd.lcm.TransitionVO;
import com.vci.corba.omd.qtm.QTInfo;
import com.vci.corba.query.ObjectQueryServicePrx;
import com.vci.corba.query.data.BOAndLO;
import com.vci.corba.omd.stm.StatePool;
import com.vci.mw.ClientContextVariable;
import com.vci.omd.constants.BusinessConstants;
import com.vci.omd.constants.LinkConstants;
import com.vci.omd.dataType.VTDataType;
import com.vci.omd.utils.ObjectTool;
 
/**
 * 业务对象及link对象操作类
 * XXX 除了必要的异常处理,其他异常全部都抛出,
 *     
 * @author VCI-STGK006
 * 
 */
public class UIFUtils extends UIFUtilsCommon{
 
    /**
     * UIF 国际化文件资源文件名称
     */
    public final static String UIFMODEL_RESOURCE_FILE_NAME = "UIFModelAction";
    
    /**
     * 业务对象操作方法
     */
    private ClientBusinessObjectOperation boOperation = new ClientBusinessObjectOperation();
 
    /**
     * link对象操作方法
     */
    private ClientLinkObjectOperation loOperation = new ClientLinkObjectOperation();
 
    /**
     * 业务对象操作类
     */
    public UIFUtils(){}
    
    /**
     * 获得cbo对象指定名称的属性值
     * @param cbo 业务对象
     * @param key 属性名称
     * @return 属性值
     */
    public String getBusinessObejctAttrValue(ClientBusinessObject cbo, String key){
        if(key == null){
            return "";
        }
        if(key.toUpperCase().startsWith("T_OID")){
            if(key.indexOf(".") != -1){
                key = key.substring(key.lastIndexOf(".") + 1);
            } else {
                key = key.substring(5);
            }
        }
        return cbo.getAttributeValue(key);
    }
    
    /**
     * 获得link对象或业务对象的属性值
     * 此时如果是业务对象的属性值需要时t_oid开头的对象
     * @param clo link对象
     * @param cbo 业务对象
     * @param key key
     * @return 属性值
     */
    public String getLinkObejctAttrValue(ClientLinkObject clo, ClientBusinessObject cbo, String key){
        if(key == null){
            return "";
        }
        String value = "";
        //判断是业务对象属性还是link属性
        if(key.toUpperCase().startsWith("T_OID")){
            if(key.indexOf(".") != -1){
                key = key.substring(key.lastIndexOf(".") + 1);
            } else {
                key = key.substring(5);
            }
            //如果是系统属性
            if (BusinessConstants.BO_CONSTANTS.containsKey(key.toUpperCase())) {
                if (key.equalsIgnoreCase(BusinessConstants.SELECT_NAME)){
                    value = cbo.getBusinessObject().name;
                } else if (key.equalsIgnoreCase(BusinessConstants.SELECT_ID)){
                    value = cbo.getBusinessObject().id;
                } else if (key.equalsIgnoreCase(BusinessConstants.SELECT_DESCRIPTION)){
                    value = cbo.getBusinessObject().description;
                }
            } else {
                AttributeValue[] attrVals = cbo.getBusinessObject().hisAttrValList;
                if(attrVals != null){
                    for(AttributeValue attr : attrVals){
                        if(key.toUpperCase().equals(attr.attrName)){
                            value = attr.attrVal;
                        }
                    }
                }
            }
        } else {
            //如果是系统属性
            if (LinkConstants.LO_CONSTANTS.containsKey(key.toUpperCase())) {
            } else {
                AttributeValue[] attrVals = clo.getLinkObject().hisAttrValList;
                if(attrVals != null){
                    for(AttributeValue attr : attrVals){
                        if(key.toUpperCase().equals(attr.attrName)){
                            value = attr.attrVal;
                        }
                    }
                }
            }
        }
        return value;
    }    
 
    /**
     * 创建一个空的业务对象
     * @param parent 父窗口
     * @param btmName 业务类型
     * @return 创建失败时返回null
     */
    public ClientBusinessObject createEmptyClientBusinessObject(Component parent, String btmName) {
        try {
            return boOperation.createBusinessObject(btmName);
        } catch (Exception e) {
            showErrorMessage(parent, e);
        }
        return null;
    }
    
    /**
     * 创建一个空的link对象
     * @param parent 父窗口
     * @param loName link类型
     * @return
     */
    public ClientLinkObject createEmptyClientLinkObject(Component parent, String loName) {
        try {
            return loOperation.createLinkObject(loName);
        } catch (Exception e) {
            showErrorMessage(parent, e);
        }
        return null;
    }
 
    /**
     * 组装业务对象 主要设置业务对象属性并进行属性的校验
     * @param parent 父窗体
     * @param cbo 业务对象
     * @param attrMap 业务对象属性。map中需要包含业务对象所有属性
     * @return 失败返回null
     */
    public ClientBusinessObject assembleClientBusinessObject(Component parent,
            ClientBusinessObject cbo, Map<String, String> attrMap) {
        // 设置验证业务对象属性值
        if (attrMap != null && !attrMap.isEmpty()) {
            Set<Entry<String, String>> set = attrMap.entrySet();
            for (Entry<String, String> entry : set) {
                String key = entry.getKey();
                String value = entry.getValue();
                try {
                    //如果是系统属性
                    if (BusinessConstants.BO_CONSTANTS.containsKey(key.toUpperCase())) {
                        cbo.setAttributeValue(key, value, true);
                    } else {
                        cbo.setAttributeValue(key, value);
                    }
                } catch (Exception e) {
                    showErrorMessage(parent, e);
                    return null;
                }
            }
        }
        return cbo;
    }
 
    /**
     * 根据业务对象的OID和BTMNAME重新加载对象
     * @param cbo 业务对象
     * @throws VCIError
     */
    public ClientBusinessObject reloadClientBusinessObject(ClientBusinessObject cbo)throws VCIError {
        return boOperation.readBusinessObjectById(cbo.getOid(), cbo.getBtmName());
    }
    
    /**
     * 根据业务对象的OID和BTMNAME重新加载对象
     * @param parent
     * @param oid
     * @param btmName
     * @return
     */
    public ClientBusinessObject reloadClientBusinessObject(Component parent,String oid, String btmName){
        ClientBusinessObject cbo = new ClientBusinessObject();
        try{
            cbo = boOperation.readBusinessObjectById(oid, btmName);
        } catch (Exception e){
            e.printStackTrace();
        }
        return cbo;
    }
    
    /**
     * 重新下载link对象
     * @param oid link oid
     * @param loName link类型
     * @return
     */
    public ClientLinkObject reloadLinkObjectById(String oid, String loName){
        ClientLinkObject clo = null;
        try {
            clo = loOperation.readLinkObjectById(oid, loName);
        } catch (Exception e){
            e.printStackTrace();
            return null;
        }
        return clo;
    }
    
    /**
     * 加载link对象
     * @param cbo from端业务对象
     * @param linkType link类型
     * @return link对象集合
     * @throws Exception
     */
    public ClientLinkObject[] reloadClientLinkObject(ClientBusinessObject cbo, String linkType) throws Exception {
        return loOperation.readLinkObjectByFromBO(cbo, linkType);
    }
 
    /**
     * 升级业务对象版次
     * @param parent 父窗体
     * @param cbo 业务对象
     * @return true 操作成功
     */
    public boolean upBusinessObjectVersion(Component parent, ClientBusinessObject cbo) throws Exception{
        // 获得升级版次的业务对象
         ClientBusinessObject to = boOperation.createBusinessObjectVersion(cbo);
         boOperation.saveVersionBuinessObject(to);
         return true;
    }
 
    /**
     * 跃迁
     * @param parent 父窗体
     * @param cbo 业务对象
     * @param vo
     * @return true跃迁成功
     */
    public boolean transferBusinessObject(Component parent,
            ClientBusinessObject cbo,TransitionVO vo) {
        try {
            if (!boOperation.transferBusinessObject(cbo, vo)) {
                showMessage(parent, "uifmodel.plm.uif.actions.transferBOError", cbo.getName());
                return false;
            }
            showMessage(parent, "uifmodel.plm.uif.actions.transfersuccessmsg", cbo.getName());
        } catch (Exception e) {
            showErrorMessage(parent, e);
            return false;
        }
        return true;
    }
 
    /**
     * 修改业务对象
     * @param parent 父窗体
     * @param cbo 将要操作的业务对象
     * @param attrMap 业务对象属性
     * @return true 操作成功
     */
    public boolean updateBusinessObject(Component parent, 
            ClientBusinessObject cbo, Map<String, String> attrMap) {
        // 验证业务对象属性值
        // 直接使用setAttributeValue方法中的校验
        if (attrMap != null && !attrMap.isEmpty()) {
            // 设置业务对象属性
            Set<Entry<String, String>> set = attrMap.entrySet();
            for (Entry<String, String> entry : set) {
                String key = entry.getKey();
                if(key.toUpperCase().startsWith("T_OID")){
                    if(key != null && key.indexOf(".") != -1){
                        key = key.substring(key.lastIndexOf(".") + 1);
                    } else {
                        key = key.substring(5);
                    }
                }
                String value = entry.getValue();
                try {
                    //更新时直接将属性值设置到newAttrValList中即可
                    cbo.setAttributeValue(key, value);
                } catch (Exception e) {
                    showErrorMessage(parent, e);
                    return false;
                }
            }
        }
        // 更新业务对象
        try {
            boOperation.updateBuinessObject(cbo);
            showMessage(parent, "uifmodel.plm.uif.actions.editsuccessmsg", cbo.getName());
        } catch (Exception e1) {
            showErrorMessage(parent, e1);
            return false;
        }
        return true;
    }
 
    /**
     * 删除版本,版次,业务对象
     * @param parent 父窗口
     * @param cbo 将要操作的业务对象
     * @param type 删除类型 1:版次对象;2:版本对象;3:主对象
     * @return true 操作成功
     */
    public boolean deleteBusinessObject(Component parent, ClientBusinessObject cbo, int type) {
        try {
            // 删除业务对象
            boolean issuccess = false;
            if(type == 1) {
                issuccess = boOperation.deleteBuinessObject(cbo);
            } else if(type == 2) {
                issuccess = boOperation.deleteBuinessObjectRevision(cbo);
            } else if(type == 3) {
                issuccess = boOperation.deleteBuinessObjectMaster(cbo);
            } else {
                showMessage(parent, "uifmodel.plm.uif.actions.delBOTypeError");
                return false;
            }
            //删除失败
            if(!issuccess){
                showMessage(parent, "uifmodel.plm.uif.actions.deleteBOError");
                return false;
            }
            showMessage(parent, "uifmodel.plm.uif.actions.deletesuccessmsg", cbo.getName());
        } catch (Exception e) {
            showErrorMessage(parent, e);
            return false;
        }
        return true;
    }
    
    /**
     * 批量删除版本,版次,业务对象
     * @param parent 父窗口
     * @param cbos 将要操作的业务对象
     * @param type 删除类型 1:版次对象;2:版本对象;3:主对象
     * @return true 操作成功
     */
    public boolean batchDeleteBuinessObject(Component parent, ClientBusinessObject[] cbos, int type){
        try {
            // 删除业务对象
            boolean issuccess = false;
            if(type == 1) {
                issuccess = boOperation.batchDeleteBuinessObject(cbos);
            } else if(type == 2) {
                issuccess = boOperation.batchDeleteBuinessObjectRevision(cbos);
            } else if(type == 3) {
                issuccess = boOperation.batchDeleteBuinessObjectMaster(cbos);
            } else {
                showMessage(parent, "uifmodel.plm.uif.actions.delBOTypeError");
                return false;
            }
            //删除失败
            if(!issuccess){
                showMessage(parent, "uifmodel.plm.uif.actions.deleteBOError");
                return false;
            }
            showMessage(parent, "uifmodel.plm.uif.actions.deletesuccessmsg", "");
        } catch (Exception e) {
            showErrorMessage(parent, e);
            return false;
        }
        return true;
    }
    
    /**
     * 启用业务对象
     * @param parent,父窗口
     * @param cbos,需要启用的数据
     * @param vos,跃迁的起始与目标状态
     * @return
     */
    public boolean enableBusinessObject(Component parent, ClientBusinessObject[] cbos, TransitionVO[] vos) {
        try {
            // 删除业务对象
            String[] releaseStatus = new String[vos.length];
            for (int i = 0; i < releaseStatus.length; i++) {
                releaseStatus[i] = "";
            }
            boolean issuccess = boOperation.batchTransferBusinessObject(cbos, vos, releaseStatus);
            //删除失败
            if(!issuccess){
                showMessage(parent, "uifmodel.plm.uif.actions.enableBOError");
                return false;
            }
            showMessage(parent, "uifmodel.plm.uif.actions.enablesuccessmsg", "");
        } catch (Exception e) {
            showErrorMessage(parent, e);
            return false;
        }
        return true;
    }
    
    /**
     * 停用业务对象
     * @param parent,父窗口
     * @param cbos,需要停用的数据
     * @param vos,跃迁的起始与目标状态
     * @return
     */
    public boolean disableBusinessObject(Component parent, ClientBusinessObject[] cbos, TransitionVO[] vos) {
        try {
            // 删除业务对象
            String[] releaseStatus = new String[vos.length];
            for (int i = 0; i < releaseStatus.length; i++) {
                releaseStatus[i] = "";
            }
            boolean issuccess = boOperation.batchTransferBusinessObject(cbos, vos, releaseStatus);
            //删除失败
            if(!issuccess){
                showMessage(parent, "uifmodel.plm.uif.actions.disableBOError");
                return false;
            }
            showMessage(parent, "uifmodel.plm.uif.actions.disablesuccessmsg", "");
        } catch (Exception e) {
            showErrorMessage(parent, e);
            return false;
        }
        return true;
    }
    
    /**
     * 保存link对象
     * @param parent
     * @param clos
     * @return
     */
    public boolean saveLinkObject(Component parent, ClientLinkObject[] clos) {
        if(clos == null || clos.length < 1){
            return true;
        } 
        try {
            return boOperation.batchSaveCreateBuinessObject(new ClientBusinessObject[0], clos);
        } catch (Exception e) {
            showErrorMessage(parent, e);
            return false;
        }
    }
 
    /**
     * 修改link对象 对于更改to端对象时,不保存to端业务对象
     * @param parent 父窗体
     * @param lo link对象
     * @param to to端业务对象,当不需要修改to端业务对象时为null
     * @param attrMap link对象属性
     * @return true 操作成功
     */
    public boolean updateLinkObject(Component parent,
            ClientLinkObject lo, ClientBusinessObject to,
            Map<String, String> attrMap) {
        // 设置link对象属性
        if (attrMap != null && !attrMap.isEmpty()) {
            Set<Entry<String, String>> set = attrMap.entrySet();
            for (Entry<String, String> entry : set) {
                String key = entry.getKey();
                String value = entry.getValue();
                try {
                    lo.setAttributeValue(key, value);
                } catch (Exception e) {
                    showErrorMessage(parent, e);
                    return false;
                }
            }
        }
        // 如果需要修改to端对象to端业务对象
        if (to != null) {
            lo.setToBO(to);
        }
        // 更新link对象
        try {
            return loOperation.updateLinkObject(lo);
        } catch (Exception e) {
            showErrorMessage(parent, e);
            return false;
        }
    }
    
    /**
     * 删除link对象
     * @param parent 父窗体
     * @param clos link对象
     * @return true 操作成功
     */
    public boolean deleteLinkObject(Component parent, ClientLinkObject[] clos){
        return deleteLinkObject(parent, clos, true);
    }
    
    /**
     * 删除link对象
     * @param parent 父窗体
     * @param clos link对象
     * @param showMessage 是否显示异常信息 true显示
     * @return true 操作成功
     */
    public boolean deleteLinkObject(Component parent, ClientLinkObject[] clos, boolean showMessage){
        if(clos == null || clos.length < 1){
            if(showMessage){
                showMessage(parent, "uifmodel.plm.uif.actions.removenotexistmsg");
            }
            return false;
        }
        if(clos.length == 1){
            //删除单个link对象
            try {
                if(!loOperation.deleteLinkObject(clos[0])){
                    if(showMessage){
                        showMessage(parent, "uifmodel.plm.uif.actions.deleteerror", clos[0].getLoName());
                    }
                    
                    return false;
                }
            } catch (Exception e) {
                if(showMessage){
                    showErrorMessage(parent, e);
                }
                return false;
            }
        } else {
            //批量删除
            try {
                if(!loOperation.batchdDeleteLinkObject(clos)){
                    if(showMessage){
                        showMessage(parent, "uifmodel.plm.uif.actions.deletelinkerror");
                    }
                    return false;
                }
            } catch (Exception e) {
                if(showMessage){
                    showErrorMessage(parent, e);
                }
                return false;
            }
        }
        return true;
    }
 
    /**
     * 从from端移除link对象 删除所有以此业务对象为from的link
     * @param parent 消息窗口的父窗口
     * @param cbos 业务对象数组
     * @param linkNameMap 每一个业务对象对应的link类型 key:cbos.OID,value:loName
     * @return true 操作成功 
     */
    public boolean deleteLinkObjectByFromBO(Component parent,ClientBusinessObject[] cbos,
            Map<String, String> linkNameMap) {
        if (cbos != null && linkNameMap != null) {
            List<ClientLinkObject> linkList = new ArrayList<ClientLinkObject>();
            // 得到所有业务员对象的link对象
            for (ClientBusinessObject cbo : cbos) {
                // 检查是否有业务对象对应的link名称
                String loName = linkNameMap.get(cbo.getBusinessObject().oid);
                if (loName == null || loName.equals("")) {
                    //没有设置对应的link名称不能删除相关link对象
                    //showMessage(parent, code, args);
                } else {
                    try {
                        // 查询所有以cbo为from端的link对象并添加到linkList
                        ClientLinkObject[] los = loOperation
                                .readLinkObjectByFromBO(cbo, loName);
                        if (los != null) {
                            for (ClientLinkObject clo : los) {
                                linkList.add(clo);
                            }
                        }
                    } catch (Exception e) {
                        //TODO 对于在查找相关的link对象时出错的信息暂时没有处理
                        e.printStackTrace();
                        //showErrorMessage(parent, e);
                        //return false;
                    }
                }
            }
            // 批量删除所有LinkObject
            if (!linkList.isEmpty()) {
                try {
                    loOperation
                            .batchdDeleteLinkObject((ClientLinkObject[]) linkList
                                    .toArray());
                } catch (Exception e) {
                    showErrorMessage(parent, e);
                    return false;
                }
            }
        }
        return true;
    }
 
    /**
     * 粘贴业务对象
     * @param parent 父窗体
     * @param from from端业务对象
     * @param loName from端link类型
     * @param tos 要粘贴的业务对象
     * @return true 操作成功 
     */
    public boolean pasteBusinessObjects(Component parent,
            ClientBusinessObject from, String loName, ClientBusinessObject[] tos) {
        if (tos == null || tos.length < 1) {
            // 剪切板中没有业务对象
            showMessage(parent, "uifmodel.plm.uif.actions.ClipboardEmpty");
            return false;
        }
        if (loName == null || loName.equals("")) {
            showMessage(parent, "uifmodel.plm.uif.actions.fromLinkNull");
        }
        //获得from段所有的头端对象
        Map<String,ClientBusinessObject> toMap = new HashMap<String,ClientBusinessObject>();
        ClientLinkObject[] clos;
        try {
            clos = loOperation.readLinkObjectByFromBO(from, loName);
            if(clos != null && clos.length > 0){
                for(int i = 0; i<clos.length; i++){
                    String oid = clos[i].getToOid();
                    String btmName = clos[i].getToBTMName();
                    ClientBusinessObject tempto = boOperation.readBusinessObjectById(oid, btmName);
                    if(tempto != null){
                        toMap.put(oid, tempto);
                    }
                }
            }
        } catch (Exception e1) {
            showErrorMessage(parent, e1);
            return false;
        }
        
        // 判断所有to端对象是否存在 对应的link对象是否已经设置
        List<ClientLinkObject> cloList = new ArrayList<ClientLinkObject>();
        for (int i = 0; i < tos.length; i++) {
            if(toMap.containsKey(tos[i].getOid())){
                int confirm = VCIOptionPane.showConfirmDialog(
                        parent, "“" + tos[i].getName() +"”已经存在,继续粘贴将忽略“"+ tos[i].getName() 
                        +"”.\n是否继续执行粘贴操作?", "系统提示",JOptionPane.YES_NO_OPTION);
                if(confirm == JOptionPane.NO_OPTION){
                    return false;
                } 
                continue;
            }
            
            ClientLinkObject clo = this.createEmptyClientLinkObject(parent, loName);
            clo.setFromBO(from);
            clo.setToBO(tos[i]);
            cloList.add(clo);
        }
        // 批量创建link
        try {
            //如果都存在不需要粘贴返回成功
            if(cloList.isEmpty()){
                return true;
            }
            boOperation.batchSaveCreateBuinessObject(
                    new ClientBusinessObject[0], cloList.toArray(new ClientLinkObject[0]));
        } catch (Exception e) {
            showErrorMessage(parent, e);
            return false;
        }
        return true;
    }
    
    /**
     * 直接复制link对象
     * @param parent 父窗体
     * @param from from端业务对象
     * @param loName from端link类型
     * @param clos 复制的link对象
     * @return true 操作成功 
     */
    public boolean pasteBusinessObjects(Component parent,
            ClientBusinessObject from, String loName ,ClientLinkObject[] clos) {
        if (from == null) {
            showMessage(parent, "uifmodel.plm.uif.actions.ClipboardError");
            return false;
        }
        if (loName == null || loName.equals("")) {
            showMessage(parent, "uifmodel.plm.uif.actions.fromLinkNull");
        }
        if (clos == null || clos.length < 1) {
            // 剪切板中没有业务对象
            showMessage(parent, "uifmodel.plm.uif.actions.ClipboardEmpty");
            return false;
        }
        
        //获得from段所有的头端对象
        Map<String,ClientBusinessObject> toMap = new HashMap<String,ClientBusinessObject>();
        ClientLinkObject[] existClos;
        try {
            existClos = loOperation.readLinkObjectByFromBO(from, loName);
            if(existClos != null && existClos.length > 0){
                for(int i = 0; i<existClos.length; i++){
                    String oid = existClos[i].getToOid();
                    String btmName = existClos[i].getToBTMName();
                    ClientBusinessObject tempto = boOperation.readBusinessObjectById(oid, btmName);
                    if(tempto != null){
                        toMap.put(oid, tempto);
                    }
                }
            }
        } catch (Exception e1) {
            showErrorMessage(parent, e1);
            return false;
        }
        
        //验证link对象是否可以复制并设置from端
        List<ClientLinkObject> loList = new ArrayList<ClientLinkObject>();
        for (int i = 0; i < clos.length; i++) {
            clos[i].getLinkObject().ltName = loName;
            ClientLinkObject clo = cloneClientLinkObject(clos[i]);
            //判断to端对象是否存在
            if(toMap.containsKey(clo.getLinkObject().toOid)){
                int confirm = VCIOptionPane.showConfirmDialog(
                        parent, "“" + toMap.get(clo.getLinkObject().toOid).getBusinessObject().name 
                        +"”已经存在,继续粘贴将忽略“"+ toMap.get(clo.getLinkObject().toOid).getBusinessObject().name 
                        +"”.\n是否继续执行粘贴操作?", "系统提示",JOptionPane.YES_NO_OPTION);
                if(confirm == JOptionPane.NO_OPTION){
                    return false;
                } 
                continue;
            }
 
            clo.setFromBO(from);
            loList.add(clo);
        }
        // 批量创建link
        try {
            if(!loList.isEmpty()){
                boOperation.batchSaveCreateBuinessObject(
                        new ClientBusinessObject[0], loList.toArray(new ClientLinkObject[0]));
            }
        } catch (Exception e) {
            showErrorMessage(parent, e);
            return false;
        }
        return true;
    }
    
    
    /**
     * 克隆一个LO对象
     * @param source lo对象
     * @return
     * @throws Exception
     */
    public ClientLinkObject cloneClientLinkObject(LinkObject source){
        if(source == null){
            return null;
        }
        ClientLinkObject clo = new ClientLinkObject();
        clo.setLinkObject(source);
        return cloneClientLinkObject(clo);
    }
    
    /**
     * 克隆一个LO对象,建立一个新的对象,只复制属性
     * @param source lo对象
     * @return
     * @throws Exception
     */
    public ClientLinkObject cloneClientLinkObject(ClientLinkObject source){
        if(source == null){
            return null;
        }
        String loType = source.getLinkObject().ltName;
        if(loType == null || loType.equals("")){
            return null;
        }
        //获得空的lo对象
        ClientLinkObject newlo = null;
        try {
            newlo = loOperation.createLinkObject(loType);
            //lo对象所具有的属性
            AttributeValue[] attrs = newlo.getLinkObject().newAttrValList;
            //设置新的LO的信息
            newlo.setOid(ObjectUtility.getNewObjectID36());
            newlo.setCreator(ClientContextVariable.getInvocationInfo().userName);
            newlo.setCreateTime(System.currentTimeMillis());
            newlo.setLastModifier(ClientContextVariable.getInvocationInfo().userName);
            newlo.setLastModifyTime(System.currentTimeMillis());
            newlo.setLoName(loType);
            newlo.setFromBTMName(source.getLinkObject().fromBTName);
            newlo.setFromNameOid(source.getLinkObject().fromNameOid);
            newlo.setFromOid(source.getLinkObject().fromOid);
            newlo.setFromRevisionOid(source.getLinkObject().fromRevOid);
            newlo.setToBTMName(source.getLinkObject().toBTName);
            newlo.setToNameOid(source.getLinkObject().toNameOid);
            newlo.setToOid(source.getLinkObject().toOid);
            newlo.setToRevisionOid(source.getLinkObject().toRevOid);
            newlo.setTs(source.getLinkObject().ts);
            //设置lo的属性
            if(attrs != null && attrs.length > 0){
                for(int i = 0; i < attrs.length; i++){
                    AttributeValue  av = attrs[i];
                    String value = source.getAttributeValue(av.attrName);
                    if(value == null){
                        value = "";
                    }
                    av.attrVal = value;
                }
            }
        } catch (VCIError e) {
            e.printStackTrace();
        }
        return newlo;
    }
    
    /**
     * 深度克隆lo对象
     * @param lo 链接对象
     * @return
     */
    public static LinkObject cloneLinkObject(LinkObject lo) {
        LinkObject newLo = new LinkObject();
        newLo.oid = lo.oid;
        newLo.creator = lo.creator;
        newLo.createTime = lo.createTime;
        newLo.modifier = lo.modifier;
        newLo.modifyTime = lo.modifyTime;
        newLo.fromOid = lo.fromOid;
        newLo.fromRevOid = lo.fromRevOid;
        newLo.fromNameOid = lo.fromNameOid;
        newLo.fromBTName = lo.fromBTName;
        newLo.toOid = lo.toOid;
        newLo.toRevOid = lo.toRevOid;
        newLo.toNameOid = lo.toNameOid;
        newLo.toBTName = lo.toBTName;
        newLo.ts = lo.ts;    
        newLo.ltName = lo.ltName; 
        if(lo.newAttrValList != null && lo.newAttrValList.length > 0){
            AttributeValue[] avs = new AttributeValue[lo.newAttrValList.length];
            for(int i = 0; i < lo.newAttrValList.length; i++){
                AttributeValue boav = lo.newAttrValList[i];
                AttributeValue  av = new AttributeValue();
                av.attrName = boav.attrName;
                av.attrVal = boav.attrVal;
                avs[i] = av;
            }
            newLo.newAttrValList = avs;
        } else {
            newLo.newAttrValList = new AttributeValue[0];
        }
        if(lo.hisAttrValList != null && lo.hisAttrValList.length > 0){
            AttributeValue[] avs = new AttributeValue[lo.hisAttrValList.length];
            for(int i = 0; i < lo.hisAttrValList.length; i++){
                AttributeValue boav = lo.hisAttrValList[i];
                AttributeValue  av = new AttributeValue();
                av.attrName = boav.attrName;
                av.attrVal = boav.attrVal;
                avs[i] = av;
            }
            newLo.hisAttrValList = avs;
        } else {
            newLo.hisAttrValList = new AttributeValue[0];
        }
        return newLo;
    }
    
    public ClientBusinessObject cloneDBBusinessObject(ClientBusinessObject cbo) throws VCIError {
        return boOperation.cloneBusinessObject(cbo);
    }
    
    /**
     * 深度克隆一个BO对象
     * @param bo 业务对象
     * @return
     */
    public static BusinessObject cloneBusinessObject(BusinessObject bo) {
        BusinessObject newBo = new BusinessObject();
        newBo.oid = bo.oid;
        newBo.revisionid = bo.revisionid;
        newBo.nameoid = bo.nameoid;
        newBo.btName = bo.btName;
        newBo.isLastR = bo.isLastR;
        newBo.isFirstR = bo.isFirstR;
        newBo.isLastV = bo.isLastV;
        newBo.isFirstV = bo.isFirstV;
        newBo.creator = bo.creator;
        newBo.createTime = bo.createTime;
        newBo.modifier = bo.modifier;
        newBo.modifyTime = bo.modifyTime;
        newBo.revisionRule = bo.revisionRule;
        newBo.versionRule = bo.versionRule;
        newBo.revisionSeq = bo.revisionSeq;
        newBo.revisionValue = bo.revisionValue;
        newBo.versionSeq = bo.versionSeq;
        newBo.versionValue = bo.versionValue;
        newBo.lctId = bo.lctId;
        newBo.lcStatus = bo.lcStatus;
        newBo.ts = bo.ts;
        newBo.id = bo.id;
        newBo.name = bo.name;
        newBo.description = bo.description;
        newBo.owner = bo.owner;
//        newBo.checkinBy = bo.checkinBy;
//        newBo.checkinTime = bo.checkinTime;
//        newBo.checkoutBy = bo.checkoutBy;
//        newBo.checkoutTime = bo.checkoutTime;
        newBo.fromVersion = bo.fromVersion;
        if(bo.newAttrValList != null && bo.newAttrValList.length > 0){
            AttributeValue[] avs = new AttributeValue[bo.newAttrValList.length];
            for(int i = 0; i < bo.newAttrValList.length; i++){
                AttributeValue boav = bo.newAttrValList[i];
                AttributeValue  av = new AttributeValue();
                av.attrName = boav.attrName;
                av.attrVal = boav.attrVal;
                avs[i] = av;
            }
            newBo.newAttrValList = avs;
        } else {
            newBo.newAttrValList = new AttributeValue[0];
        }
        if(bo.hisAttrValList != null && bo.hisAttrValList.length > 0){
            AttributeValue[] avs = new AttributeValue[bo.hisAttrValList.length];
            for(int i = 0; i < bo.hisAttrValList.length; i++){
                AttributeValue boav = bo.hisAttrValList[i];
                AttributeValue  av = new AttributeValue();
                av.attrName = boav.attrName;
                av.attrVal = boav.attrVal;
                avs[i] = av;
            }
            newBo.hisAttrValList = avs;
        } else {
            newBo.hisAttrValList = new AttributeValue[0];
        }
        return newBo;
    }
    
    
    /**
     * 克隆一个新的BO对象,不调用
     * @param source 源对象
     * @param isNew 是否生成新的对象,
     *              如果为true则为克隆的对象生成新的oid、Revisionid、Nameoid
     * @return
     */
    public static BusinessObject cloneEmptyClientBusinessObject(BusinessObject source, boolean isNew){
        ClientBusinessObject cbo = new ClientBusinessObject();
        cbo.setBusinessObject(source);
        return cloneEmptyClientBusinessObject(cbo, isNew).getBusinessObject();
    }
    
 
    /**
     * 克隆一个新的CBO对象,不调用
     * @param source 源对象
     * @param isNew 是否生成新的对象,
     *              如果为true则为克隆的对象生成新的oid、Revisionid、Nameoid
     * @return
     */
    public static ClientBusinessObject cloneEmptyClientBusinessObject(ClientBusinessObject source, boolean isNew){
        if(source == null){
            return null;
        }
        ClientBusinessObject bo = new ClientBusinessObject();
        if(isNew){
            bo.setOid(ObjectUtility.getNewObjectID36());
            bo.setRevisionid(ObjectUtility.getNewObjectID36());
            bo.setNameoid(ObjectUtility.getNewObjectID36());
        } else {
            bo.setOid(source.getOid());
            bo.setRevisionid(source.getRevisionid());
            bo.setNameoid(source.getNameoid());
        }
        bo.setBtmName(source.getBtmName());
        bo.setIsLastR(source.getIsLastR());
        bo.setIsFirstR(source.getIsFirstR());
        bo.setIsFirstV(source.getIsFirstV());
        bo.setIsLastV(source.getIsLastV());
        bo.setCreator(source.getCreator());
        bo.setCreateTime(source.getCreateTime());
        bo.setLastModifier(source.getLastModifier());
        bo.setLastModifyTime(source.getLastModifyTime());
        bo.setRevisionRule(source.getRevisionRule());
        bo.setVersionRule(source.getVersionRule());
        bo.setRevisionSeq(source.getRevisionSeq());
        bo.setRevisionValue(source.getRevisionValue());
        bo.setVersionSeq(source.getVersionSeq());
        bo.setVersionValue(source.getVersionValue());
        bo.setLctId(source.getLctId());
        bo.setLcStatus(source.getLcStatus());
        bo.setId(source.getId());
        bo.setName(source.getName());
        bo.setDescription(source.getDescription());
        bo.setOwner(source.getOwner());
        //bo.setCheckinBy(source.getCheckinBy());
        bo.setCopyFromVersion(source.getCopyFromVersion());
        //设置BO自定义属性
        AttributeValue[] attrs = null;
        if(source.getBusinessObject().newAttrValList != null){
            int size = source.getBusinessObject().newAttrValList.length;
            attrs = new AttributeValue[size];
            AttributeValue[] sourceAttrs = source.getBusinessObject().newAttrValList;
            for(int i = 0; i < sourceAttrs.length; i++){
                AttributeValue  av = new AttributeValue();
                av.attrName = sourceAttrs[i].attrName;
                av.attrVal = "";
                attrs[i] = av;
            }
        }
        bo.getBusinessObject().newAttrValList = attrs;
        return bo;
    }
    
    /**
     * 克隆一个LO对象,建立一个新的对象,只复制属性
     * @param source lo对象
     * @return
     * @throws Exception
     */
    public static ClientLinkObject cloneEmptyClientLinkObject(ClientLinkObject source, boolean isNew){
        if(source == null){
            return null;
        }
        //获得空的lo对象
        //ClientLinkObject newlo = loOperation.createLinkObject(loType);
        ClientLinkObject newlo = new ClientLinkObject();
        //设置新的LO的信息
        if(isNew){
            newlo.setOid(ObjectUtility.getNewObjectID36());
        } else {
            newlo.setOid(source.getLinkObject().oid);
        }
        newlo.setCreator(source.getCreator());
        newlo.setCreateTime(source.getCreateTime());
        newlo.setLastModifier(source.getLastModifier());
        newlo.setLastModifyTime(source.getLastModifyTime());
        newlo.setLoName(source.getLoName());
        newlo.setFromBTMName(source.getLinkObject().fromBTName);
        newlo.setFromNameOid(source.getLinkObject().fromNameOid);
        newlo.setFromOid(source.getLinkObject().fromOid);
        newlo.setFromRevisionOid(source.getLinkObject().fromRevOid);
        newlo.setToBTMName(source.getLinkObject().toBTName);
        newlo.setToNameOid(source.getLinkObject().toNameOid);
        newlo.setToOid(source.getLinkObject().toOid);
        newlo.setToRevisionOid(source.getLinkObject().toRevOid);
        newlo.setTs(source.getLinkObject().ts);
        //设置lo的属性
        AttributeValue[] attrs = source.getLinkObject().newAttrValList;
        if(attrs != null){
            AttributeValue[] newAttrs = new AttributeValue[attrs.length];
            for(int i = 0; i < attrs.length; i++){
                AttributeValue  av = new AttributeValue();
                av.attrName = attrs[i].attrName;
                av.attrVal = "";
                newAttrs[i] = av;
            }
            newlo.getLinkObject().newAttrValList = newAttrs;
        }
        return newlo;
    }
    
    /**
     * 得到cbo对象的集合
     * @param objs IDataNode集合
     * @param direction 如果objs主对像是clo,则用于判断是下载from还是to端对象
     *                  正向下载to端对象
     * @return
     * @throws Exception
     */
    public ClientBusinessObject[] getClentBusinessObjects(
            Object[] objs, boolean direction) throws Exception {
        if(objs == null || objs.length < 1){
            return null;
        }
        ClientBusinessObject[] cobs = new ClientBusinessObject[objs.length];
        for(int i =0; i < objs.length; i++){
            if(objs[i] instanceof IDataNode){
                if(((IDataNode)objs[i]).getMaterObject() instanceof ClientBusinessObject){
                    cobs[i] = (ClientBusinessObject) ((IDataNode)objs[i]).getMaterObject();
                } else if(((IDataNode)objs[i]).getMaterObject() instanceof ClientLinkObject){
                    ClientLinkObject clo = (ClientLinkObject) ((IDataNode)objs[i]).getMaterObject();
                    String oid = "";
                    String btmName = "";
                    if(direction){
                        oid = clo.getLinkObject().toOid;
                        btmName = clo.getLinkObject().toBTName;
                    } else {
                        oid = clo.getLinkObject().fromOid;
                        btmName = clo.getLinkObject().fromBTName;
                    }
                    cobs[i] = boOperation.readBusinessObjectById(oid, btmName);
                }
            }
        }
        return cobs;
    }
    
    /**
     * 转换null为空字符
     * 去掉前后的空格
     * @param str
     * @return
     */
    public static String getStringNotNull(String str) {
        if(str == null) {
            str = "";
        }
        return str.trim();
    }
    /**
     * 查询BO对象
     * @param conditions 查询条件
     * @param btmName 业务对象类型
     * @return
     * @throws VCIError 
     */
    public static BusinessObject[] queryBusinessObject(
            Map<String, String> conditions, String btmName) throws VCIError  {
        return queryBusinessObjectLRLV(conditions, btmName, false);
    }
    
    /**
     * 查询BO对象
     * @param oid 业务对象OID
     * @param btmName 类型
     * @param queryChildren 是否查询子类型数据
     * @return
     * @throws VCIError 
     */
    public static ClientBusinessObject queryBusinessObject(
            String oid, String btmName, boolean queryChildren) throws VCIError  {
        Map<String, String> conditions = new HashMap<String, String>();
        conditions.put("oid", oid);
        BusinessObject[] bos = queryBusinessObject(
                conditions, btmName, queryChildren, Version.currentRevCurrentVer);
        ClientBusinessObject cbo = new ClientBusinessObject();
        if(bos != null && bos.length > 0) {
            cbo.setBusinessObject(bos[0]);
        }
        return cbo;
    }
    
    /**
     * 查询BO对象
     * 最新版本最新版次
     * @param conditions 查询条件
     * @param btmName 业务对象类型
     * @pabtmNamedren 是否查询子分类
     * @return
     * @throws VCIError 
     */
    public static BusinessObject[] queryBusinessObjectLRLV(Map<String, String> conditions,
            String btmName, boolean queryChildren) throws VCIError {
        return queryBusinessObject(conditions, btmName, queryChildren, Version.lastRevLastVer);
    }
    
    /**
     * 查询BO对象
     * 查询不经过数据权限校验
     * @param conditions 查询条件
     * @param btmName 业务对象类型
     * @pabtmNamedren 是否查询子分类
     * @return
     * @throws VCIError 
     * @throws Exception
     */
    public static BusinessObject[] queryBusinessObject(Map<String, String> conditions,
            String btmName, boolean queryChildren, int version) throws VCIError {
        QueryTemplate qt2 = new QueryTemplate();
        qt2.setId("btmQuery");
        qt2.setBtmType(btmName);
        qt2.setType("btm");
        qt2.setRightFlag(false);
        qt2.setVersion(version);
        qt2.setQueryChildrenFlag(queryChildren);
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt2.setClauseList(clauseList);
 
        Condition cond = OQTool
                .getCondition(conditions);
        qt2.setCondition(cond);
 
        BusinessObject[] bos = QTClient.getService().findBTMObjects(
                qt2.getId(), OQTool.qtTOXMl(qt2).asXML());
        return bos;
    }
    
    /**
     * 查询BO对象
     * 实现批量查询
     * 查询不经过数据权限校验
     * @param key 过滤属性名称
     * @param value 过滤属性值,多个用“,”号隔开
     * @param toType BO的类型
     * @return
     * @throws VCIError 
     * @throws Exception
     */
    public static BusinessObject[] queryBusinessObject(
            String key, String value, String toType) throws VCIError {
        QueryTemplate qt2 = new QueryTemplate();
        qt2.setId("btmQuery");
        qt2.setBtmType(toType);
        qt2.setType("btm");
        qt2.setRightFlag(false);
        qt2.setQueryChildrenFlag(true);
        qt2.setVersion(Version.lastRevLastVer);
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt2.setClauseList(clauseList);
        
        Condition cond = new Condition();
        cond.setRootCIName("ci1");
        Map<String, ConditionItem> cIMap = new HashMap<String, ConditionItem>();
        ConditionItem ci1 = new ConditionItem();
        ci1.setId("ci1");
        ci1.setLeafFlag(true);
        LeafInfo leafInfo = new LeafInfo();
        leafInfo.setClause(key);
        leafInfo.setOperator(Operator.IN);
        LeafValue value_ = new LeafValue();
        value_.setOrdinaryValue(value);
        leafInfo.setValue(value_ );
        ci1.setLeafInfo(leafInfo );
        cIMap.put("ci1", ci1 );
        cond.setCIMap(cIMap );
        qt2.setCondition(cond);
 
        BusinessObject[] bos = QTClient.getService().findBTMObjects(
                qt2.getId(), OQTool.qtTOXMl(qt2).asXML());
        return bos;
    }
    
    /**
     * 批量查询BO对象
     * @param btmName BO类型
     * @param key 过滤属性
     * @param valueList 属性值列表
     * @return 属性值+BO的Map
     * @throws Exception
     */
    public static Map<String, BusinessObject> queryBusinessObject(
            String btmName, String key,List<String> valueList) throws Exception{
        Map<String, BusinessObject> boMap = new HashMap<String, BusinessObject>();
        if(valueList == null || valueList.isEmpty()){
            return boMap;
        }
        int number = 0;
        do {
            int start = number;
            StringBuilder conditionValue = new StringBuilder("(");
            int end = number + 999 <= valueList.size() ? number + 999 : valueList.size();
            for(int i = start; i < end; i++){
                if(i != start){
                    conditionValue.append(",");
                }
                conditionValue.append("'").append(valueList.get(i)).append("'");
            }
            conditionValue.append(")");
            BusinessObject[] bos = UIFUtils
                    .queryBusinessObject(key, conditionValue.toString(), btmName);
            if(bos != null){
                for(BusinessObject bo : bos){
                    boMap.put(ObjectTool.getBOAttributeValue(bo, key), bo);
                }
            }
            number += 999;
        } while(number < valueList.size());
        return boMap;
    }
    
    /**
     * 批量查询BO对象
     * @param btmName BO类型
     * @param key 过滤属性
     * @param valueList 属性值列表
     * @return 包装成ClientBusinessObject
     * @throws VCIError 
     */
    public static List<ClientBusinessObject> queryBusinessObjectList(
            String btmName, String key,List<String> valueList) throws VCIError {
        List<ClientBusinessObject> cboList = new ArrayList<ClientBusinessObject>();
        if(valueList == null || valueList.isEmpty()){
            return cboList;
        }
        int number = 0;
        do {
            int start = number;
            StringBuilder conditionValue = new StringBuilder("(");
            int end = number + 999 <= valueList.size() ? number + 999 : valueList.size();
            for(int i = start; i < end; i++){
                if(i != start){
                    conditionValue.append(",");
                }
                conditionValue.append("'").append(valueList.get(i)).append("'");
            }
            conditionValue.append(")");
            BusinessObject[] bos = UIFUtils
                    .queryBusinessObject(key, conditionValue.toString(), btmName);
            if(bos != null){
                for(BusinessObject bo : bos){
                    ClientBusinessObject cbo = new ClientBusinessObject();
                    cbo.setBusinessObject(bo);
                    cboList.add(cbo);
                }
            }
            number += 999;
        } while(number < valueList.size());
        return cboList;
    }
    
    /**
     * 通过From查询LO和to端BO对象
     * 查询不经过数据权限校验
     * @param lintype
     * @param fromOrToOid
     * @param direction
     * @return
     * @throws VCIError
     */
    public static BOAndLO[] queryLOAddBO(String lintype, String btmType,
            Map<String, String> conditioin, boolean direction) throws VCIError{
        QueryTemplate qt2 = new QueryTemplate();
        qt2.setId("ltQuery");
        qt2.setLinkType(lintype);
        qt2.setType("link");
        qt2.setBtmType(btmType);
        qt2.setRightFlag(false);
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt2.setClauseList(clauseList);
        if(direction){
            qt2.setDirection("positive");
        }else{
            qt2.setDirection("opposite");
        }
        Condition cond = OQTool.getCondition(conditioin);
        qt2.setCondition(cond);
        
        BOAndLO[] loaddbo = QTClient.getService().getBOAndLOS(
                qt2.getId(), OQTool.qtTOXMl(qt2).asXML(),"");
        return loaddbo;
    }
    
    /**
     * 查询LO及BO对象 最新版本最新版次
     * @param lintype 查询的链接类型
     * @param btmName 查询的BO类型
     * @param startOid 起始OID
     * @param direction 正反向
     * @param level 查询层数
     * @return
     * @throws VCIError
     */
    public static BOAndLO[] queryLOAddBO(String lintype, String btmName,
            String startOid, boolean direction, int level) throws VCIError{
        return queryLOAddBO(lintype, btmName,
                startOid, direction, level, Version.lastRevLastVer);
    }
    
    /**
     * 查询LO及BO对象
     * @param lintype 查询的链接类型
     * @param btmName 查询的BO类型
     * @param startOid 起始OID
     * @param direction 正反向
     * @param level 查询层数
     * @param version 版本版次
     * @return
     * @throws VCIError
     */
    public static BOAndLO[] queryLOAddBO(String lintype, String btmName,
            String startOid, boolean direction, int level, int version) throws VCIError{
        QueryTemplate qt9 = new QueryTemplate();
        qt9.setId("ltQuery");
        qt9.setLinkType(lintype);
        qt9.setType("link");
        qt9.setBtmType(btmName);
        qt9.setRightFlag(false);
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt9.setClauseList(clauseList);
        qt9.setVersion(version);
        Map<String, String> conditions = new HashMap<String, String>();
        if(direction){
            qt9.setDirection("positive");
            conditions.put("f_oid", startOid);
        }else{
            qt9.setDirection("opposite");
            conditions.put("t_oid", startOid);
        }
        Condition cond = OQTool.getCondition(conditions);
        qt9.setCondition(cond);
        qt9.setLevel(level);
        
        BOAndLO[] loaddbo = QTClient.getService().getBOAndLOS(
                qt9.getId(), OQTool.qtTOXMl(qt9).asXML(),"");
        return loaddbo;
    }
    
    /**
     * 通过From查询LO和to端BO对象
     * 查询不经过数据权限校验
     * @param lintype
     * @param fromOrToOid
     * @param direction
     * @return
     * @throws VCIError
     */
    public static LinkObject[] queryLinkObejct(String lintype, String btmType,
            Map<String, String> conditioin, boolean direction) throws VCIError{
        QueryTemplate qt2 = new QueryTemplate();
        qt2.setId("ltQuery");
        qt2.setLinkType(lintype);
        qt2.setType("link");
        qt2.setRightFlag(false);
        if(btmType != null && !btmType.equals("")) {
            qt2.setBtmType(btmType);
        }
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt2.setClauseList(clauseList);
        if(direction){
            qt2.setDirection("positive");
        }else{
            qt2.setDirection("opposite");
        }
        Condition cond = OQTool.getCondition(conditioin);
        qt2.setCondition(cond);
        
        LinkObject[] los = QTClient.getService().findLTObjects(
                qt2.getId(), OQTool.qtTOXMl(qt2).asXML());
        return los;
    }
    
    /**
     * 获取表单数据
     * @param f
     * @return
     * @throws IOException 
     * @throws VCIError
     */
    public static List<SheetDataSet> getFileList(File f) throws Exception {
        // 获取流
        BufferedInputStream fileInputStream = new BufferedInputStream(
                new FileInputStream(f));
        String name = f.getName();
        // 获取表list
        List<SheetDataSet> sheetDataSets = ExcelDocumentUtils
                .readExcelDocument(name, fileInputStream, true);
        return sheetDataSets;
    }
    
    /**
     * 到处Excel文件
     * @param frame 所属窗口
     * @param datas Excel文件数据
     * @param sheetName 工作表名称
     * @return
     */
    public static File exportExcel(Window frame, String[][] datas, String sheetName) throws Exception{
        
        File file = getRequiredFile(frame, false);
        if(file == null) {
            return null;
        }
        String fileName = file.getAbsolutePath();
        // add by xchao 2014.05.15 end
        new ExcelFileOperation().writeExcelFileInfo(fileName, sheetName, datas,
            new ExcelCellStyleSettingCallback() {
                @Override
                public WorkboolStyleSetting doSetWorkbookStyle(
                        final Workbook workbook) {
                    WorkboolStyleSetting setting = new WorkboolStyleSetting() {
                        @Override
                        public LinkedHashMap<String, CellStyle> getStyleMap() {
                            LinkedHashMap<String, CellStyle> styleMap = new LinkedHashMap<String, CellStyle>();
 
                            org.apache.poi.ss.usermodel.CellStyle style = workbook
                                    .createCellStyle();
                            org.apache.poi.ss.usermodel.Font font = (org.apache.poi.ss.usermodel.Font) workbook
                                    .createFont();
                            font.setColor(HSSFFont.COLOR_RED);
                            style.setFont(font);
                            return styleMap;
                        }
                    };
                    return setting;
                }
            });
        
        return file;
    }
    
    public static File getRequiredFile(Window frame, boolean isRead){
           File files = getExcelFile(frame);
        // add by xchao 2014.04.15 begin
        // 有错误数据要输出时,必须选择有效的excel文件
        if(files == null) {
            return null;
        }
        String fileName = files.getAbsolutePath();
        // 需要写入时,必须选择一个有效的、可以写入的文件
        if(!isRead){
            // 如果文件被打开着,则必须选择其它的未打开着的文件
            while (files.exists() && !files.renameTo(new File(fileName))) {
                VCIJOptionPane.showMessageDialog(null,
                        "另一个程序正在使用此文件,进程无法访问,请重新选择!");
                // 重新选择文件时,也必须选择有效的excel文件
                files = null;
                while(files == null){
                    files = getExcelFile(frame);
                }
                fileName = files.getAbsolutePath();
            }
        }
        return files;
    }
    
    /**
     * 选择Excel文件
     * @param frame 所属窗口
     * @return
     */
    public static File getExcelFile(Window frame) {
        File file = null;
        String filePath = VCISwingUtil.getExcelFileURL(frame, true, "");
        if(filePath != null){
            file = new File(filePath);
        }
        return file;
    }   
    
    /**
     * 获得用户选择对象对应的CBO对象
     * @param selectedObjects 用户选择的对象
     * @param direction 是正向还是反向:正向取to端;反向取from端
     * @return
     * @throws Exception
     */
    public ClientBusinessObject getBusinessObject(
            Object[] selectedObjects, boolean direction) throws Exception{
        ClientBusinessObject cbo = null;
        if(selectedObjects == null || selectedObjects.length < 1){
            return cbo;
        }
        if(selectedObjects[0] instanceof IDataNode){
            IDataNode dtn = (IDataNode) selectedObjects[0];
            if(dtn.getMaterObject() instanceof ClientBusinessObject){
                cbo = (ClientBusinessObject) dtn.getMaterObject();             
            } else if(dtn.getMaterObject() instanceof ClientLinkObject){
                ClientLinkObject clo = (ClientLinkObject) dtn.getMaterObject();
                String oid = direction ? 
                        clo.getLinkObject().toOid : clo.getLinkObject().fromOid;
                String btmName = direction ?
                        clo.getLinkObject().toBTName : clo.getLinkObject().fromBTName;
                if(oid != null && !oid.equals("") 
                        && btmName != null && !btmName.equals("")) {
                    cbo = boOperation.readBusinessObjectById(oid, btmName);
                }
            
            }
        }
        return cbo;
    }
    
    /**
     * 获得用户选择对象对应的CBO对象
     * @param selectedObject 用户选择的对象
     * @param direction 是正向还是反向:正向取to端;反向取from端
     * @return
     * @throws Exception
     */
    public ClientBusinessObject getBusinessObject(
            Object selectedObject, boolean direction) throws Exception{
        ClientBusinessObject cbo = null;
        if(selectedObject == null ){
            return cbo;
        }
        if(selectedObject instanceof IDataNode){
            IDataNode dtn = (IDataNode) selectedObject;
            if(dtn.getMaterObject() instanceof ClientBusinessObject){
                cbo = (ClientBusinessObject) dtn.getMaterObject();             
            } else if(dtn.getMaterObject() instanceof ClientLinkObject){
                ClientLinkObject clo = (ClientLinkObject) dtn.getMaterObject();
                String oid = direction ? 
                        clo.getLinkObject().toOid : clo.getLinkObject().fromOid;
                String btmName = direction ?
                        clo.getLinkObject().toBTName : clo.getLinkObject().fromBTName;
                if(oid != null && !oid.equals("") 
                        && btmName != null && !btmName.equals("")) {
                    cbo = boOperation.readBusinessObjectById(oid, btmName);
                }
            
            }
        }
        return cbo;
    }
    
    /**
     * 获得系统中枚举类型对应的值
     * @param btmName 类型名称
     * @param attrName 属性名称
     * @param key 键值
     * @return
     * @throws Exception
     */
    public String transferEnum(String btmName, String attrName, String key) throws Exception{
        if(key == null || key.equals("")) {
            return "";
        }
        Map<String, String> sysEnumMap = UIFCache.getInstance().getSysEnumMap();
        if(sysEnumMap.containsKey(btmName + "#" + attrName + "#" + key)){
            return sysEnumMap.get(btmName + "#" + attrName + "#" + key); 
        } else {
            //BtmAndApName[] baans = BtmClient.getService().getBtmAndApNameArray(btmName);
            BtmItem bt = BtmClient.getService().getBtmItemByName(btmName);
            BtmAndApName baan = new BtmAndApName(bt.name, bt.apNameArray);
            
            //for(BtmAndApName baan : baans) {
                AttribItem[] arItems = APClient.getService().getAttribItemsByNames(baan.apName);
                for(AttribItem ai : arItems){
                    if(ai.name.equals(attrName)){
                        String[] others = ai.other.split(";");
                        for(String other : others){
                            String[] cvs = other.split("=");
                            if(cvs[0].trim().equalsIgnoreCase("enumName")){
                                String enumName = cvs[1].trim();
                                //EnumItemFilter filter = new EnumItemFilter(enumName);
                                EnumItem[] enumItems = ServiceProvider.getOMDService().getEnumService().getEmItems(enumName, 1, 1);
                                for(EnumItem ei : enumItems){
                                    for(EnumChild ec : ei.children){
                                        sysEnumMap.put(btmName + "#" + attrName + "#" + ec.value, ec.name);
                                    }
                                }
                            }
                        }
                    }
                }
            //}
            return sysEnumMap.get(btmName + "#" + attrName + "#" + key);
        }
    }
    
    /**
     * 转译生命周期状态
     * @param statusName 状态名称
     * @return
     */
    public String transferLifecycle(String statusName) {
        if(statusName == null) {
            return "";
        }
        String lcStatuc = "";
        try {
            boolean exist = false;
            StatePool[] statePools = UIFCache.getInstance().getStatePools();
            for(StatePool sp:statePools){
                if(sp.name.equals(statusName)){
                    lcStatuc = sp.tag; 
                    exist = true;
                    break;
                }
            }
            if(exist){
                return lcStatuc;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return statusName;
    }
    
    /**
     * 查询生命周期节点
     * @param lcName 生命周期名称
     * @param lcDestStatus 状态
     * @return
     */
    public static TransitionVO getTransitionVO(String lcName, String lcSourceStatus,String lcDestStatus) {
        if (lcSourceStatus == null || lcDestStatus == null) {
            return null;
        }
        lcSourceStatus = lcSourceStatus.trim();
        lcDestStatus = lcDestStatus.trim();
        LifeCycle lc = getLifeCycle(lcName);
        if(lc != null) {
            for (int i = 0; i < lc.routes.length; ++i) {
                TransitionVO route = lc.routes[i];
                if (route.destination.equals(lcDestStatus) && route.source.equals(lcSourceStatus)){
                    return route;
                }
            }
        }
        return null;
    }
    
    /**
     * 查询业务对象的生命周期
     * @param lcName 生命周期名称
     * @return
     */
    public static LifeCycle getLifeCycle(String lcName) {
        //得到所有LifeCyle对象
        try {
            LifeCycle[] lifeCyles = LifeCycleStart.getService().getLifeCycles();
            for(int i = 0; i < lifeCyles.length; i++){
                LifeCycle lc = lifeCyles[i];
                //得到业务对象的生命周期
                if(lc.name.equals(lcName)) {
                    return lc;
                }
            }
        } catch (VCIError e) {
            e.printStackTrace();
        }
        return null;
    }
    
    
    /**
     * 获得系统默认属性对应的系统数据类型
     * @param name 属性名称
     * @return 当属性不是系统默认属性时,返回null
     */
    public static String getDefaultAttributeDataType(String name) {
        if("oid".equalsIgnoreCase(name)
                || "revisionoid".equalsIgnoreCase(name)
                || "nameoid".equalsIgnoreCase(name)
                || "btmname".equalsIgnoreCase(name)
                || "islastr".equalsIgnoreCase(name)
                || "isfirstr".equalsIgnoreCase(name)
                || "islastv".equalsIgnoreCase(name)
                || "isfirstv".equalsIgnoreCase(name)
                || "creator".equalsIgnoreCase(name)
                || "lastmodifier".equalsIgnoreCase(name)
                || "revisionrule".equalsIgnoreCase(name)
                || "versionrule".equalsIgnoreCase(name)
                || "revisionseq".equalsIgnoreCase(name)
                || "revisionvalue".equalsIgnoreCase(name)
                || "versionseq".equalsIgnoreCase(name)
                || "versionvalue".equalsIgnoreCase(name)
                || "lctid".equalsIgnoreCase(name)
                || "lcstatus".equalsIgnoreCase(name)
                || "id".equalsIgnoreCase(name)
                || "name".equalsIgnoreCase(name)
                || "description".equalsIgnoreCase(name)
                || "owner".equalsIgnoreCase(name)
                || "checkinby".equalsIgnoreCase(name)
                || "checkoutby".equalsIgnoreCase(name)
                || "copyfromversion".equalsIgnoreCase(name)) {
            return VTDataType.VTSTRING;
        } else if ("createtime".equalsIgnoreCase(name)
                || "lastmodifytime".equalsIgnoreCase(name)
                || "ts".equalsIgnoreCase(name)
                || "checkintime".equalsIgnoreCase(name)
                || "checkouttime".equalsIgnoreCase(name)) {
            return VTDataType.VTDATETIME;
        }
        return null;
    }
    
    /**
     * 得到表单上field对应PRMItem集合
     * @param formPrm PRM对象
     * @return
     */
    public static Map<String, PRMItem> getColAndPRMItemMap(PRM formPrm){
        Map<String, PRMItem> prmItemMap = new HashMap<String, PRMItem>();
        List<PRMItem> prmItemList = formPrm.getPrmItemList();
        if(prmItemList == null || prmItemList.isEmpty()){
            return prmItemMap;
        }
        for(int i = 0; i < prmItemList.size(); i++){
            PRMItem p = prmItemList.get(i);
            if(p.getItemField() != null && !p.getItemField().equals("")){
                String field = p.getItemField();
                prmItemMap.put(field, p);
            }
        }
        return prmItemMap;
    }
    
    /**
     * 根据查询模板名称,返回查询模板
     * @param queryTemplateName 查询模板
     * @return
     */
    public static QueryTemplate getQueryTemplateByName(String queryTemplateName){
        QueryTemplate qt = null;
        try{
            QTInfo wrapper = ServiceProvider.getOMDService().getQTDService().getQT(queryTemplateName);
            qt = OQTool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplateName);
        } catch (VCIError e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return qt;
    }
 
    /**
     * 显示异常信息 
     *             使用资源文件 UIFModelAction
     * 其它异常信息使用资源文件UIFModelAction:uifmodel.plm.uif.actions.syserror
     * @param parent 父窗口
     * @param e VCIException 
     * @deprecated 本接口默认使用 properties/UIFModelAction.properties作为国际化资源文件,不具备通用性,
     * 被 <code>showErrorMessage(parent, e, resourceFileName) 替代</code>
     */
    @Deprecated
    public static void showErrorMessage(Component parent, VCIException e){
        showErrorMessage(parent, e, UIFMODEL_RESOURCE_FILE_NAME);
    }
 
    /**
     * 显示异常信息 
     * 其它异常信息使用资源文件UIFModelAction:uifmodel.plm.uif.actions.syserror
     * @param parent 父窗口
     * @param e VCIException 
     * @param resourceFileName 国际化资源文件名称
     */
    public static void showErrorMessage(Component parent, VCIException e, String resourceFileName){
        showErrorMessage(parent, "uifmodel.plm.uif.actions.syserror", e, resourceFileName);
    }
    
    /**
     * 显示异常信息 枚举
     *             使用资源文件 UIFModelAction
     * Client端的 VCIError是已经转化后的,error_code为国际化后的异常信息
     * 其它异常信息使用资源文件UIFModelAction:uifmodel.plm.uif.actions.syserror
     * @param parent 父窗口
     * @param e
     * @deprecated 本接口默认使用 properties/UIFModelAction.properties作为国际化资源文件,不具备通用性,
     * 被 <code>showErrorMessage(parent, e, resourceFileName) 替代</code>
     */
    @Deprecated
    public static void showErrorMessage(Component parent, Throwable e){
        showErrorMessage(parent, e, UIFMODEL_RESOURCE_FILE_NAME);
    }
 
    /**
     * 显示异常信息 枚举
     * Client端的 VCIError是已经转化后的,error_code为国际化后的异常信息
     * 其它异常信息使用资源文件UIFModelAction:uifmodel.plm.uif.actions.syserror
     * @param parent 父窗口
     * @param e
     * @param resourceFileName 国际化资源文件名称
     */
    @Deprecated
    public static void showErrorMessage(Component parent, Throwable e, String resourceFileName){
        showErrorMessage(parent, "uifmodel.plm.uif.actions.syserror", e, resourceFileName);
    }
    
    /**
     * 显示异常信息 
     * @param parent 父窗口
     * @param code 国际化文件对应编码
     *             使用资源文件 UIFModelAction
     * @param e 异常信息
     * @param resourceFileName 国际化资源文件名称
     * @deprecated 本接口默认使用 properties/UIFModelAction.properties作为国际化资源文件,不具备通用性,
     * 被 <code>showErrorMessage(parent, code, e, resourceFileName)</code>
     */
    public static void showErrorMessage(Component parent, String code, Throwable e){
        showErrorMessage(parent, code, e, UIFMODEL_RESOURCE_FILE_NAME);
    }
    
    /**
     * 显示异常信息
     * @param parent 父窗口
     * @param code 国际化文件对应编码
     * @param e 异常信息
     * @param resourceFileName 国际化资源文件名称
     */
    public static void showErrorMessage(Component parent, String code, Throwable e, String resourceFileName){
        writeClientLog(e);
        if(parent == null){
            parent = ClientContextVariable.getFrame();
        }
        String message = getExceptionMessage(e, resourceFileName);
        showMessageDetails(parent, message, true);
    }
    
    /**
     * 显示异常信息
     * @param parent 父窗口
     * @param code 国际化文件对应编码
     * @param resourceFileName 国际化资源文件名称
     * @param args
     */
    public static void showErrorMessage(Component parent, String code, String resourceFileName, Object...args){
        if(parent == null){
            parent = ClientContextVariable.getFrame();
        }
        String message = LocaleDisplay.getI18nString(code, resourceFileName, Locale.getDefault());
        message = MessageFormat.format(message, args);
        showMessageDetails(parent, message, true);
    }
    
    /**
     * 获得异常信息
     * @param e 异常
     * @return
     */
    private static String getExceptionMessage(Throwable e, String resourceFileName) {
        if (e == null) {
            return "";
        }
        String str = "";
        String code = "";
        Object[] messages = new String[0];
        // TODO 待异常对象改造完毕(对象自我说明,对应的error_code在哪个国际化资源文件),
        boolean isErrorOrException = false;
        if (e instanceof VCIError) {
            code = ((VCIError) e).code;
            //打印异常信息
            messages = ((VCIError) e).messages;
            isErrorOrException = true;
        } else if (e instanceof VCIException) {
            code = ((VCIException) e).getException_code();
            //打印异常信息
            messages = ((VCIException) e).getException_objArray();
            isErrorOrException = true;
        }
        if(isErrorOrException){
            if(messages != null) {
                for(Object temp : messages) {
                    System.out.println(temp);
                }
            }
            String message = LocaleDisplay.getI18nString(code, resourceFileName, Locale.getDefault());
            message = MessageFormat.format(message, messages);
            str = message;
        } else {
            if (e.getCause() != null)
                str = e.getCause().toString();
            else {
                str = e.toString();
            }
            if (str == null) {
                str = "";
            }
        }
        return str;
     }
    
    /**
     * 显示消息
     * 使用文件 UIFModelAction
     * @param parent 展示窗口
     * @param code 国际化文件对应编码
     * @param args 参数
     * @deprecated 本接口默认使用 properties/UIFModelAction.properties作为国际化资源文件,不具备通用性,
     * 被 <code>showMessage(parent, code, resourceFileName, args) 替代</code>
     */
    @Deprecated
    public static void showMessage(Component parent, String code, Object ... args){
        showMessageBySpecifyFileName(parent, code, UIFMODEL_RESOURCE_FILE_NAME, args);
    }
 
    /**
     * 显示消息
     * 使用文件 UIFModelAction
     * @param parent 展示窗口
     * @param code 国际化文件对应编码
     * @param resourceFileName 国际化文件名称(该文件需要位于 src/properties 文件夹下,打包后该文件位于jar包根目录里properties文件夹下)
     * @param args 参数
     */
    public static void showMessageBySpecifyFileName(Component parent, String code, String resourceFileName, Object...args){
        if(parent == null){
            parent = ClientContextVariable.getFrame();
        }
        showMessageDetails(parent, getI18nString(code, resourceFileName, args), false);
    }
    /**
     * 显示普通消息
     * 不需要国际化
     * @param parent 父窗口
     * @param message 消息
     */
    public static void showCommonMessage(Component parent, String message){
        if(parent == null){
            parent = ClientContextVariable.getFrame();
        }
        showMessageDetails(parent, message, false);
    }
    
    /**
     * 显示消息   
     * *内部类,不可修改*
     * @param parent 父窗口
     * @param message 显示的消息
     */
    private static void showMessageDetails(Component parent, String message, boolean isError) {
        //获得系统配置,判断是弹出框还是右下角提示信息
        String displayModes = ConfigUtils.getConfigValue("PromptMessage.DisplayModes");
        if(displayModes != null && displayModes.trim().equals("popup")) {
            if(isError){
                VCIJOptionPane.showError(parent, message);
            } else{
                VCIJOptionPane.showMessage(parent, message);
            }
        } else {
            showPositionMessageDetails(message, isError);
        }
    }
    
    /**
     * 在窗口右下角显示提示信息
     * *内部类,不可修改*
     * @param message
     */
    private static void showPositionMessageDetails(String message, boolean isError){
        //获得弹出窗口显示时间
        int displayTime = 3000;
        String displayTimeStr = ConfigUtils.getConfigValue("PromptMessage.DisplayTime");
        if(displayTimeStr == null || displayTimeStr.trim().equals("")) {
            displayTimeStr = "3000";
            try {
                displayTime = Integer.parseInt(displayTimeStr);
            } catch (Exception e) {
            }
        }
        PositionMessager msger = new PositionMessager();
        //TODO 待完善注入设置是否显示错误
        //msger.setError(isError);
        // 消息显示停留时间,单位为毫秒
        msger.setShowTimes(displayTime);
        msger.show(message);
    }
    
 
    /**
     * 返回 客户端是否启用日志输出
     * @return
     */
    private static boolean isEnableClientLog(){
        return true;
    }
 
    /**
     * 输出客户端日志
     * @param e
     */
    public static void writeClientLog(Throwable e){
        if(isEnableClientLog()){
            //TODO 需要调用日志接口输出
            // 暂时往往控制台输出
            e.printStackTrace();
        }
    }
    
    /**
     * 输出客户端日志
     * @param message
     */
    public static void writeClientLog(String message){
        if(isEnableClientLog()){
            //TODO 需要调用日志接口输出
            // 暂时往往控制台输出
            System.out.println(message);
        }
    }
    /**
     * 输出耗时日志
     * @param message
     * @param start 
     * @param end
     */
    public static void writeClientLog(String message, long start, long end){
        long sp = (end - start) / 1000;
        if(sp <= 0){
            return;
        }
        writeClientLog(message + String.valueOf(sp) + "s");
    }
    
    
    /**
     * 检查指定的字符串是否是Freemarker公式表达式
     * @param itemValue 
     * @return
     */
    public static boolean isFreemarkTemplateContent(String itemValue){
        int startPos = itemValue.indexOf("${");
        int endPos = itemValue.indexOf("}");
        return (startPos >= 0 && endPos >= 0 && startPos < endPos);
    }
    
    /**
     * 根据Freemarker公式表达式,从IDataData中返回解析后的灵气
     * @param itemValue
     * @param sourceData
     * @return
     */
    public static String getRuleValue(String itemValue, IDataNode sourceData, IRegionPanel regionPanel){
        Map<String, String> valueMap = sourceData.getValueMap();
        String defaultValue = "";
        // ${t_oid.notfound}-${f_oid.notfound}
        String rule = itemValue;
        int start = rule.indexOf("${");
        int end = rule.indexOf("}");
        boolean allFieldExistInMap = true;
        while(start >= 0 && end >= 0 && start < end && end < rule.length()){
            String fieldRule = rule.substring(start+2, end);
            rule = rule.substring(end+1);
            if(!valueMap.containsKey(fieldRule)){
                allFieldExistInMap = false;
                defaultValue = "";
                break;
            }
            start = rule.indexOf("${");
            end = rule.indexOf("}");
        }
        // update by xchao 2014.03.26 end 
        if(allFieldExistInMap){
            Map<String, FreemarkerParamObject> rootMap = convertValueMapToFPOMap(valueMap, regionPanel);
            defaultValue = FreeMarkerCommon.getValueByTempRule(rootMap, itemValue.replace(".", "_"));
        }
        return defaultValue;
    }
    private static Map<String, FreemarkerParamObject> convertValueMapToFPOMap(Map<String, String> map, IRegionPanel regionPanel){
        Map<String, FreemarkerParamObject> rootMap = new LinkedHashMap<String, FreemarkerParamObject>();
        Iterator<String> it = map.keySet().iterator();
        while(it.hasNext()){
            String key = it.next();
            String value = map.get(key);
            if(regionPanel != null){
                String valueFromUILayout = regionPanel.getBaseLayoutPanel().getValue(key);
                if(!valueFromUILayout.equals(key)){
                    value = valueFromUILayout;
                }
            }
            if(value == null){
                value = "";
            }
            String newKey = key.replace(".", "_");
            FreemarkerParamObject fpo = new FreemarkerParamObject(newKey, value);
            rootMap.put(newKey, fpo);
        }
        return rootMap;
    }
    
    /**
     * 返回 ComboBox 自定义DataProvider实例
     * @param className 自定义DataProvider类完整名称 如: a.b.c?btmname=xx&name=${name}-${id}-${code}
     * @return
     */
    public static IComboBoxDataProvider getComboBoxDataProvider(String className){
        IComboBoxDataProvider res = null;
        try{
            if(className == null || "".equals(className)) return res;
            Class<?>[] paramClass = new Class<?>[]{String.class};
            String[] paramValue = new String[]{""};
            if(className.contains("?")){
                int index = className.indexOf("?");
                paramValue[0] = className.substring(index + 1);
                className = className.substring(0, index);
            }
            Object obj = Class.forName(className).getConstructor(paramClass).newInstance(paramValue);
            if(obj == null) return res;
            if(obj instanceof IComboBoxDataProvider){
                res = (IComboBoxDataProvider) obj;
            }
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return res;
    }
 
    /**
     * 检查字符串是否为null或空
     * @param value 待检查的字符串
     * @return 如果 待检查字符串为null或空(value.equals("")),返回true
     */
    public static boolean isNullOrEmpty(String value){
        return (value == null || "".equals(value));
    }
    
 
    /**
     * 
     * @param key
     * @return
     * @deprecated 本接口默认使用 properties/UIFModelAction.properties作为国际化资源文件,不具备通用性,
     * 被 <code>getI18nString(key, resourceFileName, args) 替代</code>
     */
    @Deprecated
    public static String getI18nString(String key) {
        return getI18nString(key, UIFMODEL_RESOURCE_FILE_NAME);
    }
    
    /**
     * 返回指定KEY在应用的国际化文件 resourceFileName 里的内容
     * @param key 国际化文件对应编码
     * @param resourceFileName 国际化文件名称(该文件需要位于 src/properties 文件夹下,打包后该文件位于jar包根目录里properties文件夹下)
     * @param args 参数
     * @return
     */
    public static String getI18nString(String key, String resourceFileName, Object...args){
        String res = LocaleDisplay.getI18nString(key, resourceFileName, Locale.getDefault());
        if(res == null){
            return "";
        }
        res = MessageFormat.format(res, args);
        return res;
    }
    
    public static ClientBusinessObject[] convertBOs(BusinessObject[] bos){
        ClientBusinessObject[] cbos = new ClientBusinessObject[bos.length];
        for (int i = 0; i < bos.length; i++) {
            cbos[i] = convertBO(bos[i]);
        }
        return cbos;
    }
    public static ClientBusinessObject convertBO(BusinessObject bo){
        ClientBusinessObject cbo = new ClientBusinessObject();
        cbo.setBusinessObject(bo);
        return cbo;
    }
 
    
    protected static UIFUtils _uifUtilsInstance = null;
    public static UIFUtils getInstance(){
        if(_uifUtilsInstance == null){
            synchronized (UIFUtils.class) {
                if(_uifUtilsInstance == null){
                    _uifUtilsInstance = new UIFUtils();
                }
            }
        }
        return _uifUtilsInstance;
    }
    @Override
    public ObjectQueryServicePrx getQTService() throws VCIError {
        return QTClient.getService();
    }
}