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
package com.vci.client.omd.btm.ui;
 
import javax.swing.JPanel;
 
import com.vci.client.omd.inter.ClasspathConfig;
import com.vci.client.omd.btm.toOutside.Datacenter;
import com.vci.client.omd.btm.toOutside.InterBtm;
import com.vci.client.omd.btm.toOutside.InterBtmManager;
import com.vci.client.omd.lifecycle.ui.LifeCycleList;
import com.vci.client.omd.versionrule.ui.VersionRuleList;
import com.vci.client.ui.frame.UIConstructorInterface;
import com.vci.client.common.ClientLog4j;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.corba.omd.btm.BTMServicePrx;
import com.vci.corba.common.VCIError;
 
public class BtmClient implements UIConstructorInterface{
 
    private static BTMServicePrx btmService = null;
    private static BtmClient btmClient = null;
    
    private static BtmClient getInstance(){
        if(btmClient == null){
            btmClient = new BtmClient();
        }
        return btmClient;
    }
    
    /**
     * @param args
     */
//    public static void main(String[] args){
//        try {
//            getInstance().init();
//        } catch (VCIError e2) {
//            e2.printStackTrace();
//        }
//        
//        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
//        
//        JFrame frame = new JFrame();
//        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        frame.setTitle("业务类型管理");
//        frame.setBounds(d.width/4, d.height/4, d.width/2, d.height/2);
//        
//        BtmPanel btmPanel = null;
//        try {
//            btmPanel = (BtmPanel) getInstance().start();
//        } catch (VCIError e2) {
//            e2.printStackTrace();
//        }
//        frame.add(btmPanel);
//        frame.setVisible(true);
//        
//        String apContent = "";
//        try {
//            apContent = APClient.getService().getAPData();
//        } catch (VCIError e1) {
//            e1.printStackTrace();
//        }
//        String btmContent = null;
//        try {
//            btmContent = BtmClient.btmService.getBTMData();
//        } catch (VCIError e) {
//            e.printStackTrace();
//        }
//        //生成DDL 虽然每次改变业务类型都应该重写生成的DDL, 但考虑到此DDL文件只是留作记录
//        //频繁重写会影响整体性能, 所以在退出程序时重新DDL
//        DDLToolClient.getService().generatorODDLForBt(apContent, btmContent);
//        DDLToolClient.getService().generatorSDDLForBt(apContent, btmContent);
//    }
 
    @Override
    public void destory() throws VCIError {
        // TODO Auto-generated method stub
        
    }
 
    @Override
    public void init() throws VCIError {
        if(btmService != null){
            return;
        }
        
        if(inject()){
            ClientLog4j.logger.info("注入外界对业务类型中接口的实现成功");
        }else{
            ClientLog4j.logger.info("注入外界对业务类型中接口的实现失败");
        }
        try {
 
            btmService = ServiceProvider.getOMDService().getBTMService();
        } catch (Exception e) {
            e.printStackTrace();
            throw new VCIError("", new String[0]);
        }
    }
 
    @Override
    public JPanel start() throws VCIError {
        if(setData()){
            ClientLog4j.logger.info("设置版本规则, 生命周期成功");
        }else{
            ClientLog4j.logger.info("设置版本规则, 生命周期失败");
        }
        BtmPanel.cleanInstance();
        BtmPanel btmPanel = BtmPanel.getInstance();
        return btmPanel;
    }
    
    public static BTMServicePrx getService(){
        if(btmService == null){
            try {
                BtmClient.getInstance().init();
            } catch (VCIError e) {
                e.printStackTrace();
            }
        }
        
        return btmService;
    }
    
 
    /**
     * 设置版本规则, 生命周期
     * @return
     */
    private boolean setData(){
        try{
            LifeCycleList l = null;
            VersionRuleList v = null;
            l = new LifeCycleList();
            v = new VersionRuleList();
            Datacenter.getInstance().setLCyleNames(l.getLifeCycles());
            Datacenter.getInstance().setRevNames(v.getVersionRules());
        }catch(Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }
    
    /**
     * 注入外界对业务类型中接口的实现
     */
    private boolean inject(){
        boolean flag = false;
        String impls = ClasspathConfig.getProperty("interBtmImpl");
        String[] implArray = impls.split(";");
        for(int i = 0; i < implArray.length; i++){
            InterBtm interBtm = null;
            try {
                String classpath = implArray[i];
                if(classpath == null || classpath.equals("")){
                    continue;
                }
                interBtm = (InterBtm)Class.forName(classpath).newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
                return flag;
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                return flag;
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
                return flag;
            }
            InterBtmManager.getInstance().registerInter(interBtm);
            flag = true;
        }
        return flag;
    }
}