ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
package com.vci.server.omd.common;
 
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.Element;
 
import com.vci.corba.omd.atm.AttribItem;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.omd.ltm.LinkTypeService;
import com.vci.corba.common.VCIError;
import com.vci.server.base.utility.OmdHelper;
import com.vci.server.cache.OMCacheProvider;
import com.vci.server.omd.ddlTool.DDLHelper;
import com.vci.server.omd.linktype.LinkTypeServiceImpl;
 
 
/**
 * 获取属性的数据类型, 属性: 系统属性, 属性池属性
 * 
 */
public class LinkTypeHelper {
    private static LinkTypeHelper linkTypeHelper = null;
    /**
     * 链接类型table名的前缀
     */
    private static LinkTypeService linkTypeService = null;
    /**
     * oracle中table名的最大长度
     */
//    private static final int TABLEMAXLENTGH = 30;
    
//    public static DateFormat tsDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
//    public static DateFormat timeDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
//    private String[] sysAttibutes = {"OID","Creator","CreateTime","LastModifier","LASTMODIFYTIME","F_OID","F_REVISIONOID","F_NAMEOID","F_BtwName",
//                                    "T_OID","T_REVISIONOID","T_NAMEOID","T_BtwName","TS"};
    private final String otherFieldLt = "\n\tOID VARCHAR2(36) not null," + 
            "\n\tCreator VARCHAR2(36),\n\tCreateTime TIMESTAMP,\n\tLastModifier VARCHAR2(36)," +
            "\n\tLastModifyTime TIMESTAMP,\n\tF_OID VARCHAR2(36) not null,\n\tF_REVISIONOID VARCHAR2(36)," + 
            "\n\tF_NAMEOID VARCHAR2(36),\n\tF_BtwName VARCHAR2(36),\n\tT_OID VARCHAR2(36) not null,\n\tT_REVISIONOID VARCHAR2(36)," + 
            "\n\tT_NAMEOID VARCHAR2(36),\n\tT_BtwName VARCHAR2(36),\n\tTS TIMESTAMP,\n\t";
    
//    private AttribItem[] _sysAttrItems = null;
    
//    public static final String OID = "oid";
//    public static final String NAME = "name";
//    public static final String LABEL = "label";
//    public static final String DESCRIPTION = "description";
//    public static final String TS = "ts";
//    public static final String CREATOR = "creator";
//    public static final String CREATETIME = "createTime";
//    public static final String MODIFIER = "modifier";
//    public static final String MODIFYTIME = "modifyTime";
    /**
     * 缓存已经调用new LinkTypeProvider();
     * 因此不能定义 私有的LinkTypeProvider();
     * @return
     */
    public static LinkTypeHelper getInstance(){
        if(linkTypeHelper == null){
            linkTypeHelper = new LinkTypeHelper();
        }
        return linkTypeHelper;
    }
    
 
    
    /**
     * 
     * @return
     */
    public String getLTData(){
        String content = "";
        try {
            content = getService().getLTData(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return content;
    }
    
    /***
     * 
     *  获取所有链接类型对象数组
     *  
     */
    public LinkType [] getLinkTypes(){
        return OMCacheProvider.getLinkTypes();
//            LinkType[] linkTypes = null;
//        try {
//            linkTypes = getService().getLinkTypes(null);
//        } catch (VCIError e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//        return linkTypes;
    }
    /***
     * 
     * 根据链接类型名称获取链接类型对象
     */
    public LinkType getLinkTypeByName(String name){
        return OMCacheProvider.getLinkType(name);
//        LinkType[] linkTypes = null;
//        try {
//            linkTypes = getService().getLinkTypes(null);
//            for(LinkType lt:linkTypes){
//                if(lt.name.equals(name)){
//                    return lt;
//                }
//            }
//        } catch (VCIError e) {
//            e.printStackTrace();
//        }
//        return null;
        
    }
    
    public LinkType[] getLinkTypeByBtmName(String btmName, String direction) {
        LinkType[] linkTypes = null;
        try {
            linkTypes = getService().getLinkTypeByBtmName(btmName, direction, null);
        } catch (VCIError e) {
            e.printStackTrace();
        }
        return linkTypes;
    }
    
    public LinkTypeService getService(){
        try {
            linkTypeService = new LinkTypeServiceImpl();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return linkTypeService;
    }
 
    
    /**
     * 返回创建链接类型的sql
     * @param linkType
     * @return
     */
    public String getCreateLtSql(LinkType linkType){
        String tableName = OmdHelper.getLTTableName(linkType.name);
        String sql = "create table " + tableName + "(" + otherFieldLt;
        
        String[] abInfo = linkType.attributes;
        
        for(int i = 0; i < abInfo.length; i++){
            com.vci.corba.omd.atm.AttribItem abItem = null;
            abItem = OMCacheProvider.getAttribute(abInfo[i]);
 
            String abSql = DDLHelper.getAbSql(abItem);
            sql += abSql;
        }
        sql = sql.substring(0, sql.lastIndexOf(","));
        sql += "\n)";
        return sql;
    }
    
    /**
     * 获取增加主键sql
     * @param typeName
     * @return
     */
    public String getAddPKSql(String typeName){
        return "alter table " + OmdHelper.getLTTableName(typeName) + " add constraint PKLT_" + typeName + " primary key (OID)\n";
    }
    
//    public String getAbSql(AttribItem abItem){
//        String sql = "";
//        if(abItem == null){
//            return sql;
//        }
//        String abName = abItem.name;
//        String vtType = abItem.vtDataType;
//        String other = abItem.other;
//        String defValue = abItem.defValue;
//        
//        if(vtType.equals("VTString")){
//            int length = 50;
//            String lengthStr = getOtherValueByType(other, "length");
//            if(lengthStr != null && !lengthStr.equals("")){
//                length = Integer.valueOf(lengthStr);
//            }
//            sql += abName.toUpperCase() + " VARCHAR2(" + length + ")";
//            if(!defValue.equals("")){
//                sql += " default '" + defValue + "'";
//            }
//            sql += ",\n\t";
//        }else if(vtType.equals("VTInteger")){
//            sql += abName.toUpperCase() + " NUMBER";
//            if(!defValue.equals("")){
//                sql += " default " + defValue;
//            }
//            sql += ",\n\t";
//        }else if(vtType.equals("VTDouble")){
//            int length = 20;
//            String lengthStr = getOtherValueByType(other, "length");
//            if(lengthStr != null && !lengthStr.equals("")){
//                length = Integer.valueOf(lengthStr);
//            }
//            
//            int accuracy = 2;
//            String accuracyStr = getOtherValueByType(other, "accuracy");
//            if(accuracyStr != null && !accuracyStr.equals("")){
//                accuracy = Integer.valueOf(accuracyStr);
//            }
//            sql += abName.toUpperCase() + " NUMBER(" + length + ", " + accuracy +")";
//            if(!defValue.equals("")){
//                sql += " default " + defValue;
//            }
//            sql += ",\n\t";
//        }else if(vtType.equals("VTBoolean")){
//            sql += abName.toUpperCase() + " VARCHAR2(8)";
//            if(!defValue.equals("")){
//                sql += " default '" + defValue + "'";
//            }
//            sql += ",\n\t";
//        }else if(vtType.equals("VTImage")){
//            sql += abName.toUpperCase() + " VARCHAR2(255)";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTDate")){
//            sql += abName.toUpperCase() + " DATE";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTTime")){
//            sql += abName.toUpperCase() + " TIMESTAMP";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTDateTime")){
//            sql += abName.toUpperCase() + " TIMESTAMP";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTNote")){
//            sql += abName.toUpperCase() + " VARCHAR2(255)";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTFilePath")){
//            sql += abName.toUpperCase() + " VARCHAR2(255)";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTClob")){
//            sql += abName.toUpperCase() + " CLOB";
//            sql += ",\n\t";
//        }
//        
//        return sql;
//    }
    
    /**
     * 获取属性other中type的值
     * @param other
     * @param type
     * @return
     */
//    public String getOtherValueByType(String other, String type){
//        String[] otherArray = other.split(";");
//        for(int i = 0; i < otherArray.length; i++){
//            String otherValue = otherArray[i];
//            if(otherValue.contains(type)){
//                return otherValue.substring(otherValue.indexOf("=") + 2, otherValue.length());
//            }
//        }
//        return null;
//        
//    }
//    
    /**
     * Array-->List
     * @param array
     * @return
     */
//    public List<String> parseArrayToList(String[] array){
//        List<String> list = new ArrayList<String>();
//        for(int i = 0; i < array.length; i++){
//            list.add(array[i]);
//        }
//        return list;
//    }
    
    /**
     * 指定的链接类型是否使用了指定的业务类型
     * @param link
     * @param btmName
     * @return
     */
    public boolean containsBtm(LinkType link, String btmName){
        String[] btms = link.btmItemsFrom;
        for(int i = 0; i < btms.length; i++){
            if(btmName.equalsIgnoreCase(btms[i])){
                return true;
            }
        }
        btms = link.btmItemsTo;
        for(int i = 0; i < btms.length; i++){
            if(btmName.equalsIgnoreCase(btms[i])){
                return true;
            }
        }
        return false;
    }
    
    /**
     * 
     * 获取链接类型的全部属性(包括系统属性)数组
     * @return
     */
    public List<String> getAllAbNames(LinkType link){
        List<String> abList = new ArrayList<String>();
        for(String attr : OmdHelper.getLTSysAbItems()){
            abList.add(attr);
        }
        String[] abNames = getAbNames(link);
        for(int i = 0; i < abNames.length; i++){
            abList.add(abNames[i]);
        }
        
        return abList;
    }
    
    /**
     * 获取链接类型的属性(不包括系统属性)数组
     * @param btmName
     * @return
     */
    public String[] getAbNames(LinkType link){
        return link.attributes;
    }
    
    /**
     * 获取链接类型对应的属性
     * @param linkTypeName
     * @return
     */
    public AttribItem[] getLTAbItems(String linkTypeName) {
        return OMCacheProvider.getAttribItemsByLinkType(linkTypeName);
//        LinkType linkType = getLinkTypeByName(linkTypeName);
//        if (linkType.attributes == null || linkType.attributes.length == 0) {
//            return new AttribItem[0];
//        }
//        AttribItem[] abItems = AttributeHelper.getAttribItemsByNames(linkType.attributes);
//        
//        return abItems;
    }
//    
//    public boolean expData(String dir, LinkType[] lts){
//        Set<String> attNameSet = new HashSet<String>();
//        Set<String> btNameSet = new HashSet<String>();
//        BufferedWriter bw = null;
//        FileOutputStream fos = null;
//        OutputStreamWriter osw =null;
//        try{
//            File file = new File(dir + "/lt.txt");
//            //将clob字段写到单独的文件中
//            new File(dir + "/lt").mkdir();
//            //add by caill start 2015.12.24     导出时将txt文件设置为“utf-8”格式
//            fos = new FileOutputStream(file);
//            osw = new OutputStreamWriter(fos, "utf-8");
//            bw = new BufferedWriter(osw);
//            //add by caill end
//            /*w = new FileWriter(file);
//            bw = new BufferedWriter(w);*/
//            for(LinkType lt : lts){
//                String[] apNames = lt.attributes;
//                if(apNames.length > 0){
//                    attNameSet.addAll(Arrays.asList(apNames));
//                }
//                for(String btName : lt.btmItemsFrom){
//                    btNameSet.add(btName);
//                }
//                for(String btName : lt.btmItemsTo){
//                    btNameSet.add(btName);
//                }
//                //若str小于缓冲区大小, 将写到缓冲区; 
//                //若str大于缓冲区大小, 将刷新缓冲区(将缓冲区内容写到底层流), 然后str直接写到底层流.
//                String text = getObjectText(lt);
//                bw.write(text);
//                bw.newLine();
//                BufferedWriter clobBW = null;
//                FileOutputStream fo = null;
//                OutputStreamWriter pw =null;
//                try{
//                    File clobFile = new File(dir + "/lt/" + lt.oid + ".xml");
//                    //add by caill start 2015.12.24 将xml内容和xml文件格式统一
//                    fo = new FileOutputStream(clobFile);
//                    pw = new OutputStreamWriter(fo, "utf-8");
//                    clobBW = new BufferedWriter(pw);
//                    clobBW.write( "<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
//                    clobBW.write(getXmlText(lt));
//                    clobBW.flush();
//                    //add by caill end
//                    /*clobW = new FileWriter(clobFile);
//                    clobBW = new BufferedWriter(clobW);
//                    clobBW.write( "<?xml version=\"1.0\" encoding=\"gb2312\" ?>");//gb2312
//                    clobBW.write(getXmlText(lt));
//                    clobBW.flush();*/
//                }catch(IOException e2){
//                    e2.printStackTrace();
//                }finally{
//                    try{
//                        if(clobBW != null){
//                            fo.close();        //add by caill 2015.12.24 将fo关闭
//                            pw.close();        //add by caill 2015.12.24 将pw关闭
//                            clobBW.close();
//                        }
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
//                }
//            }
//            bw.flush();
//            //导出属性
//            AttribItem[] abs = AttributeHelper.getAttribItemsByNames(attNameSet.toArray(new String[0]));            
//            boolean apFlag = AttributeHelper.expData(dir, abs);
//            
//            //导出业务类型
//            List<BtmItem> bts = new ArrayList<BtmItem>();
//            for(String btName : btNameSet){
//                BtmItem bt = BtmHelper.getBtmItemByName(btName);
//                bts.add(bt);
//            }
//            boolean btFlag = BtmHelper.expData(dir, bts.toArray(new BtmItem[0]));
//            if(true & apFlag & btFlag){
//                System.out.println("**************链接类型导出成功************");
//            }else{
//                System.out.println("**************链接类型导出失败************");
//            }
//            return true & apFlag & btFlag;
//        }catch(IOException e){
//            e.printStackTrace();
//        }finally{
//            try {
//                if(bw != null){
//                    fos.close();        //add by caill 2015.12.24 将fos关闭
//                    osw.close();        //add by caill 2015.12.24 将osw关闭
//                    bw.close();
//                }
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        return false;
//    }
//    
//    /**
//     * 将对象转化成字符串
//     * {oid:qqq, name:q}
//     * @param lt
//     * @return
//     */
//    public String getObjectText(LinkType lt) {
//        StringBuilder stb = new StringBuilder("{");
//        stb.append(OmdTools.OID + ":" + lt.oid + ",");
//        stb.append(OmdTools.NAME + ":" + lt.name + ",");
//        stb.append(OmdTools.LABEL + ":" + lt.tag + ",");
//        stb.append(OmdTools.DESCRIPTION + ":" + lt.description + ",");
//        stb.append(OmdTools.TS + ":" + lt.ts + ",");
//        stb.append(OmdTools.CREATOR + ":" + lt.creator + ",");
//        stb.append(OmdTools.CREATETIME + ":" + lt.createTime + ",");
//        stb.append(OmdTools.MODIFIER + ":" + lt.modifier + ",");
//        stb.append(OmdTools.MODIFYTIME + ":" + lt.modifyTime);
//        stb.append("}");
//        return stb.toString();
//    }
//    
    /**
     * 将LinkType lt转化成xmltext
     * @param bt
     * @return
     */
    public String getXmlText(LinkType lt){
        StringBuilder stb = new StringBuilder("<linkType>");
        stb.append("<name>" + lt.name + "</name>");
        stb.append("<tag>" + lt.tag + "</tag>");
        stb.append("<description>" + lt.description + "</description>");
        for(String btmFrom : lt.btmItemsFrom){
            stb.append("<btmFrom>" + btmFrom + "</btmFrom>");
        }
        for(String btmTo : lt.btmItemsTo){
            stb.append("<btmTo>" + btmTo + "</btmTo>");
        }
        stb.append("<primitivesFrom>" + lt.primitivesFrom + "</primitivesFrom>");
        stb.append("<primitivesTo>" + lt.primitivesTo + "</primitivesTo>");
        stb.append("<relationFrom>" + lt.relationFrom + "</relationFrom>");
        stb.append("<relationTo>" + lt.relationTo + "</relationTo>");
        stb.append("<relation>" + lt.relation + "</relation>");
        stb.append("<implClass>" + lt.implClass + "</implClass>");
        stb.append("<shape>" + lt.shape + "</shape>");
        for(String attibute : lt.attributes){
            stb.append("<attibute>" + attibute + "</attibute>");
        }
        stb.append("</linkType>");
        return stb.toString();
    }
//    
//    public List<LinkType> getLTFromFile(String dir) {
//        File file = new File(dir + "/lt.txt");
//        List<LinkType> list = new ArrayList<LinkType>();
//        BufferedReader br = null;
//        FileInputStream fo = null;
//        InputStreamReader isw =null;
//        try {
//            /*r = new FileReader(file);
//            br = new BufferedReader(r);*/
//            //add by caill start 2015.12.24     导入时将txt文件内容设置为“utf-8”格式
//            fo = new FileInputStream(file);
//            isw = new InputStreamReader(fo, "utf-8");
//            br = new BufferedReader(isw);
//            //add by caill end
//            String str = null;
//            while((str = br.readLine()) != null){
//                Map<String, String> map = getMapFormText(str);
//                String oid = map.get("oid");
//                if(oid != null && !oid.equals("")){
//                    File contentFile = new File(dir + "/lt/" + oid + ".xml");
//                    if(!contentFile.exists()){
//                        System.out.println(dir + "/lt/" + oid + ".xml不存在");
//                        break;
//                    }
//                    LinkType lt = new LinkType();
//                    lt.oid = oid;
//                    lt.name = map.get("name");
//                    lt.tag = map.get("label");
//                    lt.description = map.get("description");
//                    lt.ts = map.get("ts");
//                    lt.creator = map.get("creator");
//                    lt.createTime = map.get("createTime");
//                    lt.modifier = map.get("modifier");
//                    lt.modifyTime = map.get("modifyTime");
//                    SAXReader sa = new SAXReader();
//                    //add by caill 2015.12.24    导入时将saxReader对象设置为“utf-8”格式
//                    sa.setEncoding("utf-8");
//                    Document document = sa.read(contentFile);
//                    setLTValueFormDoc(lt, document.getRootElement());
//                    list.add(lt);
//                }else{
//                    System.out.println(dir + "bt.txt中存在oid为空的错误记录");
//                    break;
//                }
//            }
//            return list;
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } catch (DocumentException e) {
//            e.printStackTrace();
//        } finally{
//            if(br != null){
//                try {
//                    fo.close();        //add by caill 2015.12.24    将fo关闭
//                    isw.close();    //add by caill 2015.12.24    将isw关闭
//                    br.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//        return null;
//    }
//    /**
//     * 将文件中一条记录解析成key-value
//     * @param str
//     * @return
//     */
//    public Map<String, String> getMapFormText(String str) {
//        str = str.trim();
//        if(!str.startsWith("{") || !str.endsWith("}")){
//            return null;
//        }
//        Map<String, String> map = new HashMap<String, String>();
//        str = str.substring(1, str.length() - 1);
//        String[] kvs = str.split(",");
//        for(String kv : kvs){
//            String[] kv_ = kv.split(":");
//            if(kv_.length == 1){
//                map.put(kv_[0].trim(), "");    
//            }else{
//                map.put(kv_[0].trim(), kv_[1].trim());
//            }
//        }
//        return map;
//    }
//    
    /**
     * 设置EnumItem存在
     * @param att
     * @param element
     */
    public void setLTValueFormDoc(LinkType lt, Element element){
        List<Element> fromElements = element.elements("btmFrom");
        List<String> froms = new ArrayList<String>();
        for(Element fromElement : fromElements){
            froms.add(fromElement.getText());
        }
        lt.btmItemsFrom = froms.toArray(new String[0]);
        List<Element> toElements = element.elements("btmTo");
        List<String> tos = new ArrayList<String>();
        for(Element toElement : toElements){
            tos.add(toElement.getText());
        }
        lt.btmItemsTo = tos.toArray(new String[0]);
        String value = element.elementText("primitivesFrom");
        lt.primitivesFrom = (value == null ? "" : value);
        value = element.elementText("primitivesTo");
        lt.primitivesTo = (value == null ? "" : value);
        value = element.elementText("relationFrom");
        lt.relationFrom = (value == null ? "" : value);
        value = element.elementText("relationTo");
        lt.relationTo = (value == null ? "" : value);
        value = element.elementText("relation");
        lt.relation = (value == null ? "" : value);
        value = element.elementText("implClass");
        lt.implClass = (value == null ? "" : value);
        value = element.elementText("shape");
        lt.shape = (value == null ? "" : value);
        List<Element> attElements = element.elements("attibute");
        List<String> atts = new ArrayList<String>();
        for(Element attElement : attElements){
            atts.add(attElement.getText());
        }
        lt.attributes = atts.toArray(new String[0]);
    }
//    
//    public boolean impData(String dir, LinkType[] lts) {
//        try {
//            List<AttribItem> atts = AttributeHelper.getAttFromFile(dir);
//            boolean attFlag = AttributeHelper.impData(dir, atts.toArray(new AttribItem[0]));
//            if(!attFlag){
//                System.out.println("链接类型使用的属性导入失败。导入中止。");
//                return false;
//            }
//            
//            List<BtmItem> bts = BtmHelper.getBTFromFile(dir);
//            boolean btFlag = BtmHelper.impData(dir, bts.toArray(new BtmItem[0]));
//            if(!btFlag){
//                System.out.println("链接类型使用的业务类型导入失败。导入中止。");
//                return false;
//            }
//            
//            for(LinkType lt : lts){
//                LinkType lt_ = getService().getLinkType(lt.name);
//                //已经存在
//                if(!lt_.oid.equals("")){
//                    getService().deleteLinkTypeNoCache(lt_);
//                    getService().addLinkTypeNoCache(lt);
//                    System.out.println(lt.name + "在数据库中已经存在, 覆盖。");
//                }else{
//                    getService().addLinkTypeNoCache(lt);
//                }
//            }
//            return true;
//        } catch (VCIError e) {
//            e.printStackTrace();
//        }
//        return false;
//    }
    /**将linktype导出为.sql文件
     * add by caill 2015.12.22
     * 
     * */
    public boolean expLinkSqlData(String dir, LinkType[] linkTypes) throws VCIError {
        new File(dir).mkdir();
        File file = new File(dir + "/platformLink.sql");
        FileWriter w = null;;
        BufferedWriter bw = null;
        try {
            w = new FileWriter(file);
            bw = new BufferedWriter(w);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        for(int i = 0; i < linkTypes.length; i++){
            String sql = getLinkTableSqlByName(linkTypes[i]);
            try {
                bw.write(sql);
                bw.write("\r\n");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }    
        }
        try {
            bw.flush();
            bw.close();
            return true;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        
        return false;
    }
    /**
     * 生成链接类型导出为.sql文件的sql语句 add by caill 2015.12.22
     * @param linkType
     * @return
     */
    public String getLinkTableSqlByName(LinkType linkType){
        String tableName = OmdHelper.getLTTableName(linkType.name);
        String sql = "create table " + tableName +"(" + otherFieldLt;    
        String[] abInfo = linkType.attributes;        
        for(int i = 0; i < abInfo.length; i++){
            com.vci.corba.omd.atm.AttribItem abItem = null;
 
            abItem = OMCacheProvider.getAttribute(abInfo[i]);
 
            String abSql = DDLHelper.getAbSql(abItem);
            sql += abSql;
        }
        sql = sql.substring(0, sql.lastIndexOf(","));
        sql += "\n);";
        sql += "\r\ncomment on table "+tableName+" is '"+ linkType.tag+"';";    //添加表注释
        for(int i = 0; i < abInfo.length; i++){
            com.vci.corba.omd.atm.AttribItem abItem = null;
 
            abItem = OMCacheProvider.getAttribute(abInfo[i]);    //添加列注释
 
            sql += "\r\ncomment on column "+tableName+"."+abItem.name+" is '"+ abItem.label +"';";
        }
        return sql;
    }
    
}