田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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
package com.vci.server.omd.enumtype.service;
 
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
 
import org.apache.commons.lang3.StringUtils;
import org.dom4j.DocumentException;
import org.dom4j.Element;
 
import com.vci.common.log.ServerWithLog4j;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.etm.EnumChild;
import com.vci.corba.omd.etm.EnumItem;
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
import com.vci.server.cache.ConfigCacheProvider;
import com.vci.server.mw.ServerContextVariable;
import com.vci.server.omd.enumtype.EnumServiceImplHelper;
 
public class EnumService {
    private static final String ENUM_SECURITYENUM = "securityenum";
    private static final String ENUM_USERSECURITYENUM = "usersecurityenum";
    private static final String ENUM_IPSECURITYENUM = "ipsecurityenum";
 
    private static EnumService instance;
    
    public static EnumService getInstance() {
        if (instance == null) {
            instance = new EnumService();
            instance.checkSysEnum();
        }
        
        return instance;
    }
    
    /**
     * 检查系统枚举是否存在,不存在则创建
     * @return
     */
    private void checkSysEnum() {
        
        //System.out.println("=========checkSysEnum:Begin==========");
 
        try{
            // 缺少用户密级枚举
            if (!checkRowIsExists(ENUM_USERSECURITYENUM)){
                AddUserSecurityEnum();
            }
        }
        catch (Throwable e) {
            e.printStackTrace();
        }
 
//        try{
//            // 缺少密级枚举
//            if (!checkRowIsExists(ENUM_SECURITYENUM)){
//                AddSecurityEnum();
//            }
//        }
//        catch (Throwable e) {
//            e.printStackTrace();
//        }
        
        try{
            // 缺少密级枚举
            if (!checkRowIsExists(ENUM_IPSECURITYENUM)){
                AddIpSecurityEnum();
            }
        }
        catch (Throwable e) {
            e.printStackTrace();
        }
 
        //System.out.println("=========checkSysEnum:End==========");
        return;
    }
 
 
    /**
     * 增加枚举
     * @throws SQLException 
     * @throws IOException 
     */
    public boolean addEmItem(EnumItem emItem) throws VCIError, SQLException, IOException {
        boolean flag = false;
        String insertSql = "insert into plenum values(?,?,?,?,?,?,?,?,xmltype(?))";
        Connection connection = HibernateSessionFactory.getSessionConnection();
        PreparedStatement pst = connection.prepareStatement(insertSql);
        pst.setString(1, ObjectUtility.getNewObjectID36());
        pst.setString(2, emItem.name);
        pst.setString(3, emItem.label);
        long time = Calendar.getInstance().getTimeInMillis();
        Timestamp ts = new Timestamp(time);
        pst.setTimestamp(4, ts);
        pst.setString(5, emItem.creator);
        pst.setTimestamp(6, ts);
        pst.setString(7, emItem.modifier);
        pst.setTimestamp(8, ts);
        String xmlText = EnumServiceImplHelper.getInstance().getXmlText(emItem);
        //CLOB content = EnumServiceImplHelper.getInstance().getXmlTypeContent(xmlText, connection);
        //pst.setObject(9, content);
        pst.setString(9, xmlText);
        pst.executeUpdate();
        pst.close();
        flag = true;
        return flag;
    }
 
    /**
     * 修改枚举
     * @throws IOException 
     * @throws SQLException 
     */
    public boolean modifyEmItem(EnumItem emItem) throws VCIError, SQLException, IOException {
        boolean flag = false;
        String sql = "update plenum t set t.name=?, t.label=?, t.ts=?, t.creator=?, t.createtime=?, t.modifier=?, t.modifytime=?, t.content=xmltype(?) where t.oid=? and t.ts = ?";
        Connection conn = HibernateSessionFactory.getSessionConnection();
        PreparedStatement pst = conn.prepareStatement(sql);
        pst.setString(1, emItem.name);
        pst.setString(2, emItem.label);
        long time = Calendar.getInstance().getTimeInMillis();
        Timestamp ts = new Timestamp(time);
        pst.setTimestamp(3, ts);
        pst.setString(4, emItem.creator);
        pst.setTimestamp(5, new Timestamp(emItem.createTime));
        pst.setString(6, emItem.modifier);
        pst.setTimestamp(7, ts);
        String xmlText = EnumServiceImplHelper.getInstance().getXmlText(emItem);
        //CLOB content = EnumServiceImplHelper.getInstance().getXmlTypeContent(xmlText, conn);
        //pst.setObject(8, content);
        pst.setString(8, xmlText);
        pst.setString(9, emItem.oid);
        pst.setTimestamp(10, Timestamp.valueOf(emItem.ts));
        pst.executeUpdate();
        pst.close();
        flag = true;
        return flag;
    }
 
    /**
     * 删除枚举
     * @throws SQLException 
     */
    public boolean deleteEmItems(EnumItem[] emItems) throws VCIError, SQLException {
        boolean flag = false;
        for(EnumItem em : emItems){
            deleteEmItem(em);
        }
        flag = true;
        return flag;
    }
    
    public boolean deleteEmItem(EnumItem em)throws VCIError, SQLException {
        boolean flag = false;
        String sql = "delete from plenum where oid = ? and ts = ?";
        Connection connection = HibernateSessionFactory.getSessionConnection();
        PreparedStatement pst = connection.prepareStatement(sql);
        pst.setString(1, em.oid);
        String ts = em.ts;
        pst.setTimestamp(2, Timestamp.valueOf(ts));
        pst.executeUpdate();
        pst.close();
        flag = true;
        return flag;
        
    }
    
    public boolean deleteEmItemNoCache(EnumItem em)throws VCIError, SQLException {
        boolean flag = false;
        String sql = "delete from plenum where oid = ? and ts = ?";
        Connection connection = HibernateSessionFactory.getSessionConnection();
        PreparedStatement pst = connection.prepareStatement(sql);
        pst.setString(1, em.oid);
        String ts = em.ts;
        pst.setTimestamp(2, Timestamp.valueOf(ts));
        pst.executeUpdate();
        pst.close();
        ServerWithLog4j.logger.debug(sql);
        flag = true;
        return flag;
    }
    
    /**
     * 查询枚举
     * @throws DocumentException 
     * @throws SQLException 
     */
    public EnumItem[] getEmItems(String filter, int start, int rows)
            throws VCIError, SQLException, DocumentException {
        //String sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, t.content.getclobval() content from plenum t ";
        
        String sql = "";
        switch (HibernateSessionFactory.getDbType()) {
            case DM8:
                sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, content from plenum t ";
                break;
            case ORACL:
            default:
                sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, t.content.getclobval() content from plenum t ";
                break;
        }
        
        if(StringUtils.isNotBlank(filter)){
            sql = sql + " where t.name like '" + filter + "%'"; //add by caill 在filter后面添加“.name”
        }
        sql += " ORDER BY upper(name)";
        
        ServerWithLog4j.logger.debug(sql);
        
        Connection connection = HibernateSessionFactory.getSessionConnection();
        PreparedStatement pst = connection.prepareStatement(sql);
        ResultSet rs = pst.executeQuery();
        List<EnumItem> ems = new ArrayList<EnumItem>();
        while(rs.next()){
            EnumItem em = EnumServiceImplHelper.getInstance().getEnum(rs);
            em = this.FilterSecretGrade(em);
            ems.add(em);
        }
        rs.close();
        pst.close();
        return ems.toArray(new EnumItem[0]);
    }
 
    /**
     * 检查枚举名是否存在
     * @throws SQLException 
     */
    public boolean checkRowIsExists(String name)
            throws VCIError, SQLException {
        String sql = "select count(name) count from plenum t where t.name = ?";
        Connection connection = HibernateSessionFactory.getSessionConnection();
        PreparedStatement pst = connection.prepareStatement(sql);
        pst.setString(1, name);
        ResultSet rs = pst.executeQuery();
        while(rs.next()){
            int count = rs.getInt("count");
            if(count > 0){
                return true;
            }else{
                return false;
            }
        }
        rs.close();
        pst.close();
        return false;
    }
    
    /**
     * 根据枚举类型查询枚举
     * @throws DocumentException 
     * @throws SQLException 
     */
    public EnumItem[] getEmItemsByType(String type) throws VCIError, SQLException, DocumentException {
        //String sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, t.content.getclobval() content from plenum t where extractvalue(content, '/enum/type') = ? order by name";
        
        String sql = "";
        switch (HibernateSessionFactory.getDbType()) {
            case DM8:
                sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, content from plenum t " + 
                            "where extractvalue(content, '/enum/type') = ? order by name";
                break;
            case ORACL:
            default:
                sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, t.content.getclobval() content from plenum t " + 
                        "where extractvalue(content, '/enum/type') = ? order by name";
                break;
        }
        
        Connection connection = HibernateSessionFactory.getSessionConnection();
        PreparedStatement pst = connection.prepareStatement(sql);
        pst.setString(1, type);
        ResultSet rs = pst.executeQuery();
        List<EnumItem> ems = new ArrayList<EnumItem>();
        while(rs.next()){
            EnumItem em = EnumServiceImplHelper.getInstance().getEnum(rs);
            em = FilterSecretGrade(em);
            ems.add(em);
        }
        rs.close();
        pst.close();
        return ems.toArray(new EnumItem[0]);
    }
    
    
    public EnumItem getCloneEnumItem(EnumItem ei){
        EnumItem res = new EnumItem();
        res.oid = ei.oid;
        res.ts = ei.ts;
        res.creator = ei.creator;
        res.createTime = ei.createTime;
        res.modifier = ei.modifier;
        res.modifyTime = ei.modifyTime;
        res.name = ei.name;
        res.label = ei.label;
        res.type = ei.type;
        res.length = ei.length;
        
        EnumChild[] childs = new EnumChild[ei.children.length];
        for (int i = 0; i < childs.length; i++) {
            childs[i] = ei.children[i];
        }
        res.children = childs;
        return res;
    }
    /*
     * 密级的枚举名称是固定的,统一为Enumsecretgrade,仅仅针对这个进行处理
     * 
     * */
    public EnumItem FilterSecretGrade(EnumItem ei) throws VCIError, SQLException 
    {
        EnumItem em = getCloneEnumItem(ei);
        if (HibernateSessionFactory.getVciSessionInfo() != null) {
            int userType = getUserType(HibernateSessionFactory.getVciSessionInfo().userID);
            String curUserName = HibernateSessionFactory.getVciSessionInfo().userName;
            if(curUserName != null && curUserName.equals("developer") || userType <= 1) {
                return em;
            }
        } else {
            return em;
        }
        
        //特殊处理"Enumsecretgrade"密级枚举取值
        if (  ( !em.name.isEmpty() ) &&  ( em.name.trim().equals("Enumsecretgrade") ) && ( em.children != null ) && ( em.children.length >0) ) {
            //特殊处理业务对象密级枚举值:“业务对象密级”<=“机器密级”<=“人员密级”,by zhonggy 2015-07-23
            try {
                int compareSecret = 0;
                boolean ipSecuritySwitch = ConfigCacheProvider.isIpSecurity();//ServerContextVariable.getIpSecretSwitch();//机器密级是否有效
                boolean userSecuritySwith = ConfigCacheProvider.isUserSecurity();//ServerContextVariable.getUserSecretSwith();//用户密级是否有效
                //AppConfigDetailInfo userSecuritySwith=new AppConfigDetailDelegate(new UserEntityInfo()).getAppConfigDetailByKey("userSecuritySwith");//用户密级是否有效
                //AppConfigDetailInfo ipSecuritySwitch=new AppConfigDetailDelegate(new UserEntityInfo()).getAppConfigDetailByKey("ipSecuritySwitch");//机器密级是否有效
                if(ipSecuritySwitch){
                    String machineSecret= ServerContextVariable.getMachineSecret();//机器密级
                    if(machineSecret == null || machineSecret.equals("")){
                        machineSecret = "10";
                    }
                    if(userSecuritySwith){
                        String userSecret = ServerContextVariable.getUserSecret();//用户密级
                        if (userSecret == null || userSecret.trim().equals("")) {
                            userSecret = "10";
                        }
                        int int1 = Integer.parseInt(userSecret);
                        int int2 = Integer.parseInt(machineSecret);
                        if (int1>=int2) {
                            compareSecret = int2;
                        }else {
                            compareSecret = int1;
                        }
                    }else{
                        compareSecret=Integer.parseInt(machineSecret);
                    }
                }else{
                    if(userSecuritySwith){
                        String userSecret = ServerContextVariable.getUserSecret();//用户密级
                        if (userSecret == null || userSecret.trim().equals("")) {
                            userSecret = "10";
                        }
                        compareSecret=Integer.parseInt(userSecret);
                    }else{
                        return em;
                    }
                }
                EnumChild[] children = em.children;
                List<EnumChild> revisedEnumChild = new ArrayList<EnumChild>();
                for (EnumChild enumItem : children) {
                    Integer enumIntValue = Integer.parseInt(enumItem.value);
                    if (compareSecret >= enumIntValue) {
                        revisedEnumChild.add(enumItem);
                    }
                }
                em.children = revisedEnumChild.toArray(new EnumChild[]{});
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return em;
    }
    
    /**
     * 根据枚举名字查询枚举
     * @throws DocumentException 
     * @throws SQLException 
     */
    public EnumItem getEmItemByName(String name) throws VCIError, SQLException, DocumentException {
        //String sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, t.content.getclobval() content from plenum t where name = ?";
        
        String sql = "";
        switch (HibernateSessionFactory.getDbType()) {
            case DM8:
                sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, content from plenum t where name = ?";
                break;
            case ORACL:
            default:
                sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, t.content.getclobval() content from plenum t where name = ?";
                break;
        }
        
        Connection connection = HibernateSessionFactory.getSessionConnection();
        PreparedStatement pst = connection.prepareStatement(sql);
        pst.setString(1, name);
        ResultSet rs = pst.executeQuery();
        EnumItem em = null;
        while(rs.next()){
            em = EnumServiceImplHelper.getInstance().getEnum(rs);
        }
        if(em == null){
            em = new EnumItem();
            em.length = 0;
            em.children = new EnumChild[0];
        }
        rs.close();
        rs = null;
        pst.close();
        pst = null;
        return FilterSecretGrade(em);
    }
 
    public boolean xml2DB(String userName) throws VCIError {
//        List<EnumItem> news = null;
//        try {
//            news = Xml2DBDelegate.getInstance().getNews(userName);
//        } catch (Throwable e1) {
//            e1.printStackTrace();
//        }
//        if(news == null){
//            return true;
//        }
//        for(EnumItem o : news){
//            try{
//                addEmItemNoCache(o);
//            }catch(Throwable e){
//                e.printStackTrace();
//                return false;
//            }
//        }
        return true;        
    }
    
    public boolean addEmItemNoCache(EnumItem emItem) throws VCIError, SQLException, IOException {
        boolean flag = false;
        String insertSql = "insert into plenum values(?,?,?,?,?,?,?,?,xmltype(?))";
        Connection connection = HibernateSessionFactory.getSessionConnection();
        PreparedStatement pst = connection.prepareStatement(insertSql);
        pst.setString(1, ObjectUtility.getNewObjectID36());
        pst.setString(2, emItem.name);
        pst.setString(3, emItem.label);
        long time = Calendar.getInstance().getTimeInMillis();
        Timestamp ts = new Timestamp(time);
        pst.setTimestamp(4, ts);
        pst.setString(5, emItem.creator);
        pst.setTimestamp(6, ts);
        pst.setString(7, emItem.modifier);
        pst.setTimestamp(8, ts);
        String xmlText = EnumServiceImplHelper.getInstance().getXmlText(emItem);
        //CLOB content = EnumServiceImplHelper.getInstance().getXmlTypeContent(xmlText, connection);
        //pst.setObject(9, content);
        pst.setString(9, xmlText);
        pst.executeUpdate();
        pst.close();
        flag = true;
        return flag;
    }
    
    /**
     * 设置EnumItem存在
     * @param em
     * @param element
     */
    public void setEnumValueFormDoc(EnumItem em, Element element){
        String value = element.elementText("type");
        em.type = (value == null ? "" : value);
        value = element.elementText("length");
        em.length = (value == null ? 0 : Integer.valueOf(value));
        List<Element> children = element.elements("child");
        List<EnumChild> ecList = new ArrayList<EnumChild>();
        for(Element child : children){
            EnumChild ec = new EnumChild();
            value = child.elementText("name");
            ec.name = (value == null ? "" : value);
            value = child.elementText("value");
            ec.value = (value == null ? "" : value);
            value = child.elementText("description");
            ec.description = (value == null ? "" : value);
            ecList.add(ec);
        }
        em.children = ecList.toArray(new EnumChild[0]);
    }
    
    //private static final String PROP_SECURITY = "secret";
    //private static final String PROP_ENABLE = "enable";
    //private static final String PROP_IPSECURITY = "ipsecret";
    /**
     * @Title        :判断机器密级是否有效
     * @Description    :
     * @return
     */
//    public boolean  isIPSecretValid(){
//        boolean isOpen = false;
//        try {
//            String queryTemp = "ipstopmanagerQueryFinalValue";
//            QTServiceImpl qtServiceImpl = new QTServiceImpl();
//            QTWrapper qt = qtServiceImpl.getQT(queryTemp);
//            QueryTemplate qtByQTText1 = Tool.getQTByQTText(qt.qtName, qt.qtText);
//            qtByQTText1.setRightFlag(false);
//            BusinessObject[] findBTMObjects = qtServiceImpl.findBTMObjects(qtByQTText1.getId(), Tool.getQTTextByQT(qtByQTText1));
//            if(findBTMObjects != null && findBTMObjects.length == 1){
//                String enableValue = BTMUtils.getBtmArrValue(findBTMObjects[0], EnumServiceConstant.PROP_ENABLE);
//                if(enableValue != null && enableValue.equalsIgnoreCase("true")){
//                    isOpen = true;
//                }
//            }
//        } catch (Throwable e) {
//            e.printStackTrace();
//        }
//        return isOpen;
//    }
    
    public EnumItem getEnumItemByOid(String oid) throws VCIError, SQLException, IOException, DocumentException {
//        String sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, t.content.getclobval() content " +
//                "from plenum t where t.oid =?";
        
        String sql = "";
        switch (HibernateSessionFactory.getDbType()) {
            case DM8:
                sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, content " +
                        "from plenum t where t.oid =?";
                break;
            case ORACL:
            default:
                sql = "select oid, name, label, ts, creator, createtime, modifier, modifytime, t.content.getclobval() content " +
                        "from plenum t where t.oid =?";
                break;
        }
        
        Connection connection = HibernateSessionFactory.getSessionConnection();
        PreparedStatement pst = connection.prepareStatement(sql);
        pst.setString(1, oid);
        ResultSet rs = pst.executeQuery();
        EnumItem em = null;
        while(rs.next()){
            em = EnumServiceImplHelper.getInstance().getEnum(rs);
        }
        rs.close();
        pst.close();
        if(em == null){
            em = new EnumItem();
        }
        return em;
    }
    
    private int getUserType(String userId) throws VCIError, SQLException {
        String sql = "select plusertype from pluser t where t.pluid=?";
        Connection connection = HibernateSessionFactory.getSessionConnection();
        PreparedStatement pst = connection.prepareStatement(sql);
        pst.setString(1, userId);
        ResultSet rs = pst.executeQuery();
        int userType = 2;
        if (rs.next()) {
            userType = rs.getInt("plusertype");
        }
        rs.close();
        pst.close();
        return userType;
    }
 
    /**
     * 创建密级枚举对象
     * @return
     */
    private EnumItem AddSecurityEnum() {
        EnumItem em = new EnumItem();
        em.name = ENUM_SECURITYENUM;
        em.label = "密级";
        em.type = "Integer";
        em.length = 10;
        
        EnumChild[] items = new EnumChild[7]; 
        em.children = items;
        
        items[0] = new EnumChild("公开", "1", "公开");
        items[1] = new EnumChild("内部", "2", "内部");
        items[2] = new EnumChild("秘密", "3", "秘密");
        items[3] = new EnumChild("机密", "4", "机密");
        items[4] = new EnumChild("绝密", "5", "绝密");
        
        try{
            if (addEmItem(em))
                return em;
        }
        catch (Throwable e) {
            e.printStackTrace();
        }
        
        // TODO Auto-generated method stub
        return null;
    }
    
    /**
     * 创建IP密级枚举对象
     * @return
     */
    private EnumItem AddIpSecurityEnum() {
        EnumItem em = new EnumItem();
        em.name = ENUM_IPSECURITYENUM;
        em.label = "IP密级枚举";
        em.type = "Integer";
        em.length = 10;
        
        EnumChild[] items = new EnumChild[3]; 
        em.children = items;
        
        items[0] = new EnumChild("公开", "10", "公开");
        items[1] = new EnumChild("秘密", "20", "秘密");
        items[2] = new EnumChild("机密", "30", "机密");
        
        try{
            if (addEmItem(em))
                return em;
        }
        catch (Throwable e) {
            e.printStackTrace();
        }
        
        return null;
    }
 
    /**
     * 创建用户密级枚举对象
     * @return
     */
    private EnumItem AddUserSecurityEnum() {
        EnumItem em = new EnumItem();
        em.name = ENUM_USERSECURITYENUM;
        em.label = "用户密级枚举";
        em.type = "Integer";
        em.length = 10;
        
        EnumChild[] items = new EnumChild[3]; 
        em.children = items;
        
        items[0] = new EnumChild("公开", "10", "公开");
        items[1] = new EnumChild("秘密", "20", "秘密");
        items[2] = new EnumChild("机密", "30", "机密");
        
        try{
            if (addEmItem(em))
                return em;
        }
        catch (Throwable e) {
            e.printStackTrace();
        }
        
        return null;
    }
 
    /**
     * 将emItem转化成xmltext
     * @param emItem
     * @return
     */
    public String getXmlText(EnumItem emItem) {
        StringBuilder stb = new StringBuilder("<enum>");
        stb.append("<name>" + emItem.name + "</name>");
        stb.append("<label>" + emItem.label + "</label>");
        stb.append("<type>" + emItem.type + "</type>");
        stb.append("<length>" + emItem.length + "</length>");
        for(EnumChild ec : emItem.children){
            stb.append("<child>");
            stb.append("<name>" + ec.name + "</name>");
            stb.append("<value>" + ec.value + "</value>");
            stb.append("<description>" + ec.description + "</description>");
            stb.append("</child>");
        }
        stb.append("</enum>");
        return stb.toString();
    }
}