package com.vci.client.omd.statepool;
|
|
import java.awt.Dimension;
|
import java.awt.Toolkit;
|
|
import javax.swing.JFrame;
|
import javax.swing.JPanel;
|
|
import com.vci.client.omd.statepool.itf.InterState;
|
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.statepool.pubimpl.InterStateManager;
|
import com.vci.client.omd.statepool.ui.StatePoolUI;
|
import com.vci.client.ui.frame.UIConstructorInterface;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.omd.stm.StatePoolServicePrx;
|
|
|
public class StatePoolStart implements UIConstructorInterface{
|
private static StatePoolServicePrx statePoolService = null;
|
private static StatePoolStart statePoolStart = null;
|
|
private static StatePoolStart getInstance(){
|
if(statePoolStart == null){
|
statePoolStart = new StatePoolStart();
|
}
|
return statePoolStart;
|
}
|
|
public static void main(String[] args) {
|
try {
|
StatePoolStart.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,d.height);
|
// frame.setBounds(d.width/4, d.height/4, d.width/2, d.height/2);
|
StatePoolUI statepoolUI = null;
|
try {
|
statepoolUI = (StatePoolUI) StatePoolStart.getInstance().start();
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
frame.add(statepoolUI);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setVisible(true);
|
|
}
|
|
|
@Override
|
public void destory() throws VCIError {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void init() throws VCIError {
|
if(statePoolService != null){
|
return;
|
}
|
if(inject()){
|
ClientLog4j.logger.info("注入外界对生命周期中接口的实现成功");
|
}else{
|
ClientLog4j.logger.warn("注入外界对生命周期中接口的实现失败");
|
}
|
try {
|
statePoolService = ServiceProvider.getOMDService().getStateService();
|
} catch (Exception e) {
|
throw new VCIError("", new String[0]);
|
}
|
|
}
|
|
@Override
|
public JPanel start() throws VCIError {
|
|
StatePoolUI.cleanInstance();
|
StatePoolUI statepoolUI = StatePoolUI.getInstance();
|
return statepoolUI;
|
}
|
|
public static StatePoolServicePrx getService(){
|
if(statePoolService == null){
|
try {
|
StatePoolStart.getInstance().init();
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
}
|
return statePoolService;
|
}
|
|
|
/**
|
* 注入外界对状态池中接口的实现
|
*/
|
private boolean inject(){
|
boolean flag = false;
|
String impls = ClasspathConfig.getProperty("interStateImpl");
|
String[] implArray = impls.split(";");
|
for(int i = 0; i < implArray.length; i++){
|
InterState interState = null;
|
try {
|
String classpath = implArray[i];
|
if(classpath == null || classpath.equals("")){
|
continue;
|
}
|
interState = (InterState)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;
|
}
|
InterStateManager.getInstance().registerInter(interState);
|
flag = true;
|
}
|
return flag;
|
}
|
}
|