📄 casehandler.java
字号:
Operator operator = caseDiagramPanel.getOperator(a_NodeID);
if (operator == null)
{
throw new SysException("Invalid Operator Handle. NodeID: [" + a_NodeID + "]");
}
return operator;
}
/**
* Get OperatorNode by case id and node id. Return null if not found.
* @param a_CaseID
* @param a_NodeID
* @return
* @throws SysException
*/
public IOperatorNode getOperatorNode(String a_CaseID, String a_NodeID) throws SysException
{
BICase selectedCase = null;
// Get case object instance
try {
selectedCase = getCase(a_CaseID, false);
} catch (BaseException e) {
throw new SysException("Case Handler Execution Error.");
}
OperatorNode aNode = (OperatorNode)selectedCase.getNode(NodeFactory.OPERATOR, a_NodeID);
return aNode;
}
/**
* Excutes a Node. If input information of the node is not enough, excute its
* parent nodes to obtain necessary information.
* @param a_CaseID ID of the case of the node.
* @param a_NodeID ID of the node being executed.
*/
public void executeNode(String a_CaseID, String a_NodeID)
throws SysException, AppException {
Object[] obj = { a_CaseID, a_NodeID};
try
{
BICase selectedCase = getCase(a_CaseID, false);
CaseWindow window = null;
Observer observer = null;
for (int i = 0; i < m_Observers.size(); i++) {
observer = (Observer) m_Observers.elementAt(i);
if (observer instanceof CaseWindow) {
if (((CaseWindow) observer).getCaseID().equals(a_CaseID)) {
window = (CaseWindow) observer;
break;
}
}
}
if (window == null)
return;
HashSet nodeIDSet = new HashSet();
try
{
Node[] allNodes = selectedCase.getOperatorNodeListArray();
for (int i=0;i<allNodes.length;i++)
{
window.sendNotify("finish node|" + allNodes[i].getNodeID());
}
Vector<String> nodeIDs = new Vector<String>(1);
nodeIDs.add(a_NodeID);
executeNode(selectedCase, nodeIDs, window, nodeIDSet);
} catch (MiningException me)
{
// MiningException already handled inside executeNode(), do nothing here
/* window.sendNotify("error node|" + a_NodeID);
MessageDialog.showError(me.getMessage(),"Node Execution Error");*/
throw new SysException(me, obj, me.getMessage());
} catch (AppException ae)
{
// AppException already handled inside executeNode(), do nothing here
/* window.sendNotify("error node|" + a_NodeID);
MessageDialog.showWarning(ae.getMessage(),"Node Execution Error");*/
throw new AppException(ae, obj, ae.getMessage());
} catch (SysException e)
{
// SysException already handled inside executeNode(), do nothing here
e.printStackTrace();
/* window.sendNotify("error node|" + a_NodeID);
MessageDialog.showError(e.getMessage(),"Node Execution Error");*/
throw new SysException(e, obj, e.getMessage());
}
} catch (BaseException e)
{
throw new SysException(e, obj, e.getMessage());
}
}
public void executeNode(String a_CaseID, Vector<String> nodeIDs) throws SysException, AppException{
if(nodeIDs==null) {
throw new NullPointerException();
}
if(nodeIDs.size()==0) {
return;
}
Object[] obj = new Object[nodeIDs.size()+1];
obj[0] = a_CaseID;
int size = nodeIDs.size();
for(int i=0;i<size;i++) {
obj[i+1] = nodeIDs.get(i);
}
try
{
BICase selectedCase = getCase(a_CaseID, false);
CaseWindow window = null;
Observer observer = null;
for (int i = 0; i < m_Observers.size(); i++) {
observer = (Observer) m_Observers.elementAt(i);
if (observer instanceof CaseWindow) {
if (((CaseWindow) observer).getCaseID().equals(a_CaseID)) {
window = (CaseWindow) observer;
break;
}
}
}
if (window == null)
return;
HashSet nodeIDSet = new HashSet();
try
{
Node[] allNodes = selectedCase.getOperatorNodeListArray();
for (int i=0;i<allNodes.length;i++)
{
window.sendNotify("finish node|" + allNodes[i].getNodeID());
}
executeNode(selectedCase, nodeIDs, window, nodeIDSet);
} catch (MiningException me)
{
// MiningException already handled inside executeNode(), do nothing here
/* window.sendNotify("error node|" + a_NodeID);
MessageDialog.showError(me.getMessage(),"Node Execution Error");*/
throw new SysException(me, obj, me.getMessage());
} catch (AppException ae)
{
// AppException already handled inside executeNode(), do nothing here
/* window.sendNotify("error node|" + a_NodeID);
MessageDialog.showWarning(ae.getMessage(),"Node Execution Error");*/
throw new AppException(ae, obj, ae.getMessage());
} catch (SysException e)
{
// SysException already handled inside executeNode(), do nothing here
e.printStackTrace();
/* window.sendNotify("error node|" + a_NodeID);
MessageDialog.showError(e.getMessage(),"Node Execution Error");*/
throw new SysException(e, obj, e.getMessage());
}
} catch (BaseException e)
{
throw new SysException(e, obj, e.getMessage());
}
}
/**
* @param a_CaseID ID of the case of the node.
* @param a_NodeID ID of the node being executed.
*/
public void applyTree(String a_CaseID, String a_NodeID)
throws BaseException {
Object[] obj = { a_CaseID, a_NodeID};
try
{
BICase selectedCase = getCase(a_CaseID, false);
CaseWindow window = null;
Observer observer = null;
for (int i = 0; i < m_Observers.size(); i++) {
observer = (Observer) m_Observers.elementAt(i);
if (observer instanceof CaseWindow) {
if (((CaseWindow) observer).getCaseID().equals(a_CaseID)) {
window = (CaseWindow) observer;
break;
}
}
}
if (window == null)
return;
try
{
processApplyTree((OperatorNode)selectedCase.getNode(NodeFactory.OPERATOR, a_NodeID), window, selectedCase);
window.sendNotify("succeed node|" + a_NodeID);
} catch (MiningException me)
{
JOptionPane.showMessageDialog(window,
"Can't execute node (" + me.getMessage() +
")", "Error", JOptionPane.ERROR_MESSAGE);
}
}
catch (AppException ae)
{
throw new AppException(ae, obj);
}
catch (Exception e)
{
throw new SysException(e, obj);
}
}
/* public static void clearTempResults(String a_CaseID, String a_NodeID)
{
Vector childs = getChildOperators(a_CaseID, a_NodeID);
if (childs==null)
return;
for (int i=0; i<childs.size(); i++)
{
Operator op = (Operator)childs.elementAt(i);
op.clearDependentParameters();
}
}*/
/**
* Gets a Case from local storage or KBBI server.
* @param a_CaseID ID of the case to be retrieved.
* @param a_IsRefreshed true to retrieve case from KBBI server;
* false to retrive local copy of the case.
* @return the Case retrieved.
*/
public BICase getCase(String a_CaseID, boolean a_IsRefreshed)
throws BaseException {
Object[] obj = { a_CaseID, new Boolean(a_IsRefreshed)};
/* Try retrieve case locally to see if the case is a new case*/
if (m_CaseList != null && m_CaseList.containsKey(a_CaseID)) {
//System.out.println("get case from local: " + a_CaseID);
BICase localCase = (BICase) m_CaseList.get(a_CaseID);
if ("new".equals(localCase.getStatus()) || !a_IsRefreshed)
{
// If this is a new case that has not been saved yet or
// isRefresh is false, return local copy
return localCase;
}
}
/* Retrieve case from server while user specify to load it from server,
or case is not found locally */
if (a_IsRefreshed
|| (!a_IsRefreshed && !m_CaseList.containsKey(a_CaseID))) {
//System.out.println("get case from server");
try {
BICase aCase =
CommunicationHandlerBridge.getInstance().getCase(a_CaseID);
setCase(aCase);
return aCase;
} catch (AppException e) {
throw new AppException(e, obj);
} catch (Exception e) {
throw new SysException(e, obj);
}
}
/* Case is not found locally or from server */
else {
throw new CaseNotFoundException(obj, a_CaseID);
}
}
/**
* Gets a CaseHandler.
* @return a CaseHandler instance
*/
public static CaseHandler getInstance() {
/* Create a new CaseHandler only if it does not exist */
if (m_CaseHandler == null) {
m_CaseHandler = new CaseHandler();
m_CaseHandler.initialization();
}
return m_CaseHandler;
}
/**
* Removes a specific case from the local storage and the server.
* @param a_CaseID ID of the case to be removed.
*/
public void removeCase(String a_CaseID) throws BaseException {
Object[] obj = {a_CaseID};
try
{
if (CommunicationHandlerBridge.getInstance().removeCase(a_CaseID))
{
m_CaseList.remove(a_CaseID);
//System.out.println("remove success");
File f = new File(SysConfig.getProperty("TEMP_CASES"), "case_"+a_CaseID);
if (f.exists())
{
File[] files = f.listFiles();
if (files!=null)
{
for (int i=0; i<files.length; i++)
files[i].delete();
}
f.delete();
}
}
else
System.err.println("remove fail");
}
/*catch (AppException ae)
{
throw new AppException(ae, obj);
}*/
catch (Exception e)
{
throw new SysException(e, obj);
}
}
/**
* Removes a specific connection between two node in a case.
* @param a_CaseID ID of the case containing the connection to be removed.
* @param a_HeadNodeID ID of the head node in the connection.
* @param a_TailNodeID ID of the tail node in the connection.
*/
public void removeConnection(
String a_CaseID,
String a_HeadNodeID,
String a_TailNodeID)
throws BaseException {
Object[] obj = { a_CaseID, a_HeadNodeID, a_TailNodeID};
try
{
BICase selectedCase = getCase(a_CaseID, false);
/**
* If a connection is removed, remove all parameters in tail node.
* TWang. Feb 26, 2005.
*/
// Node tailNode = selectedCase.getNode(a_TailNodeID);
// if (tailNode instanceof OperatorNode){
// ((OperatorNode)tailNode).clearParameters();
// }
selectedCase.removeConnection(a_HeadNodeID, a_TailNodeID);
setCase(selectedCase);
}
catch (AppException ae)
{
throw new AppException(ae, obj);
}
catch (Exception e)
{
throw new SysException(e, obj);
}
}
/**
* Removes a specific operator node from a case.
* @param a_CaseID ID of the case of the node to be removed.
* @param a_NodeID ID of the node to be removed.
*/
public void removeNode(String a_CaseID, String a_NodeID)
throws BaseException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -