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
package com.vci.client.omd.lifecycle;
 
import java.awt.Dimension;
import java.awt.Toolkit;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
 
import com.vci.client.omd.lifecycle.itf.InterLCy;
import com.vci.client.common.ClientLog4j;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.client.omd.inter.ClasspathConfig;
import com.vci.client.omd.lifecycle.pubimpl.InterLCyManager;
import com.vci.client.omd.lifecycle.ui.LifeCyclePanel;
import com.vci.client.ui.frame.UIConstructorInterface;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.lcm.LifeCycleServicePrx;
 
public class LifeCycleStart implements UIConstructorInterface{
    private static LifeCycleServicePrx lifeCycleService = null;
    private static LifeCycleStart lifeCycleStart = null;
    
    private static LifeCycleStart getInstance(){
        if(lifeCycleStart == null){
            lifeCycleStart = new LifeCycleStart();
        }
        return lifeCycleStart;
    }
    
    public static void main(String[] args) {
        try {
        //    StatePoolStart.main(args);
            LifeCycleStart.getInstance().init();
        } catch (VCIError e) {
            e.printStackTrace();
        }
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame();
        frame.setTitle("生命周期管理");
        frame.setSize(d.width/2, d.height/2);
        
        LifeCyclePanel lifecycleui = null;
        try {
            lifecycleui = (LifeCyclePanel) LifeCycleStart.getInstance().start();
        } catch (VCIError e) {
            e.printStackTrace();
        }
        
        frame.add(lifecycleui);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
 
    @Override
    public void destory() {
        // TODO Auto-generated method stub
        
    }
 
    @Override
    public void init() throws VCIError{
        if(lifeCycleService != null){
            return;
        }
        
        if(inject()){
            ClientLog4j.logger.info("注入外界对生命周期中接口的实现成功");
        }else{
            ClientLog4j.logger.warn("注入外界对生命周期中接口的实现失败");
        }
        
        try {
 
            lifeCycleService = ServiceProvider.getOMDService().getLifeCycleService();
        } catch (Exception e) {
            throw new VCIError("", new String[0]);
        }
    }
 
    @Override
    public JPanel start() throws VCIError {
        //LifeCyclePanel.cleanInstance();
        LifeCyclePanel lcPanel=LifeCyclePanel.getInstance();
        //LifeCyclePanel lcPanel = new LifeCyclePanel();
        return lcPanel;
    }
    
    public static LifeCycleServicePrx getService(){ 
        if(lifeCycleService == null){
            try {
                LifeCycleStart.getInstance().init();
            } catch (VCIError e) {
                e.printStackTrace();
            }
        }
        return lifeCycleService;
    }
    
    /**
     * 注入外界对生命周期中接口的实现
     */
    private boolean inject(){
        boolean flag = false;
        String impls = ClasspathConfig.getProperty("interLCyImpl");
        String[] implArray = impls.split(";");
        for(int i = 0; i < implArray.length; i++){
            InterLCy interLCy = null;
            try {
                String classpath = implArray[i];
                if(classpath == null || classpath.equals("")){
                    continue;
                }
                interLCy = (InterLCy)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;
            }
            InterLCyManager.getInstance().registerInter(interLCy);
            flag = true;
        }
        return flag;
    }
}