📄 statemachine.java
字号:
package org.shaoye.workflow.state;
import java.io.Serializable;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Attribute;
import org.jdom.JDOMException;
import org.shaoye.workflow.flow.*;
import org.shaoye.workflow.item.*;
/**
*
* <p>Title: ״̬�� </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attr ibutable
* @version 1.0
*/
public class StateMachine implements Serializable {
private static Element root = null;
private static List flowList = null;
public StateMachine() {}
/**
* ��� XML �� DOM ����
* @throws JDOMException
* @throws Exception
*/
public static Element getRoot()
throws JDOMException, Exception
{
try
{
root = InitFlow.getRootXML();
}
catch(Exception ex)
{
throw new Exception ("��� xml �ļ� root ����: " + ex.toString());
}
finally
{
return root;
}
}
/**
* �õ������ȫ��������
* @return List
* @throws JDOMException
* @throws Exception
*/
public static List getFlowArray()
throws JDOMException, Exception
{
return root.getChildren();
}
/**
* ����ض�һ��������Ϣ
* @param id String
* @return FlowItem
* @throws JDOMException
* @throws Exception
*/
public static FlowItem getFlowItem(String id)
throws JDOMException, Exception
{
FlowItem item = new FlowItem();
try
{
List workflows = getRoot().getChildren();
for (int i = 0; i < workflows.size(); i++) {
Element workflow = (Element) root.getChildren().get(i);
Attribute workflowId = workflow.getAttribute("id");
String workflowId_value = workflowId.getValue();
if (workflowId_value.equals(id)) {
item.setFlowID(workflowId_value);
Element childElement = workflow.getChild("create-date");
item.setCreateDate(childElement.getValue());
childElement = workflow.getChild("modify-date");
item.setModifyDate(childElement.getValue());
childElement = workflow.getChild("creator");
item.setCreator(childElement.getValue());
childElement = workflow.getChild("wdescr");
item.setFlowDescr(childElement.getValue());
childElement = workflow.getChild("wname");
item.setFlowName(childElement.getValue());
childElement = workflow.getChild("nodes");
item.setNodeSize(childElement.getAttribute("count").
getValue());
item.setNodeMap(getNodeInfo(childElement));
} else
continue;
}
}
catch(Exception ex)
{
throw new Exception("��ù�������Ϣ����: "+ex.toString());
}
finally
{
return item;
}
}
/**
* ����ض�һ���������̽ڵ���Ϣ
* @param _node Element: <nodes/> �ڵ�
* @return HashMap
* @throws JDOMException
* @throws Exception
*/
public static HashMap getNodeInfo(Element _nodes)
throws JDOMException, Exception
{
HashMap nodeMap = new HashMap();
try
{
for (int i = 0; i < _nodes.getChildren().size(); i++) {
NodeItem nodeItem = new NodeItem();
Element _node = (Element) _nodes.getChildren().get(i);
nodeItem.set_final(_node.getChild("final").getValue());
nodeItem.setCodeID(_node.getChild("nid").getValue());
nodeItem.setCodeName(_node.getChild("nname").getValue());
nodeItem.setCaseMap(getCaseInfo(_node.getChild("cases")));
nodeMap.put(_node.getChild("nid").getValue(), nodeItem);
}
}
catch(Exception ex)
{
throw new Exception("��ýڵ���Ϣ����: "+ex.toString());
}
finally
{
return nodeMap;
}
}
/**
* �����̽ڵ��µĸ������Ϣ
* @param _cases Element
* @return HashMap
* @throws JDOMException
* @throws Exception
*/
public static HashMap getCaseInfo(Element _cases)
throws JDOMException, Exception
{
HashMap caseMap = new HashMap();
try
{
for (int i = 0; i < _cases.getChildren().size(); i++) {
CaseItem caseItem = new CaseItem();
Element _case = (Element) _cases.getChildren().get(i);
caseItem.setIfCase(_case.getChild("if").getValue());
caseItem.setNextNode(_case.getChild("next-node-id").getValue());
caseItem.setOper(_case.getChild("oper").getValue());
caseItem.setReason(_case.getChild("reason").getValue());
caseMap.put(_case.getChild("if").getValue(), caseItem);
}
}
catch(Exception ex)
{
throw new Exception("��� CASE ��Ϣ����: "+ex.toString());
}
finally
{
return caseMap;
}
}
/**
* �������״̬
* @return int
* @throws Exception
*/
public int loadStateFlow()
throws Exception
{
int i = 0;
return i;
}
/**
* ���ؽڵ�״̬
* @return int
* @throws Exception
*/
public int getNodelist()
throws Exception
{
int i = 0;
return i;
}
public static void main(String[] args)
throws Exception
{
StateMachine statemachine =
new StateMachine();
statemachine.getRoot();
statemachine.getFlowItem("w1");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -