Fire Workflow 模組的最後一部分 `org.fireflow.model.io` 專注於流程定義文件 (FPDL) 的序列化與解析。本文詳細剖析序列化器、解析器的雙重實現 (Dom4J/JAXP) 以及輔助工具類。
定義 FPDL 的命名空間、元素名稱與屬性常數,是流程文件格式的規範基石。FPDL 基於 XPDL 擴展,詳細規範參見 官方文檔。
public void serialize(WorkflowProcess workflowProcess, OutputStream out)
throws IOException, FPDLSerializerException {
Document document = workflowProcessToDom(workflowProcess);
OutputFormat format = new OutputFormat(" ", true);
format.setEncoding("UTF-8");
XMLWriter writer = new XMLWriter(out, format);
writer.write(document);
out.flush();
}
public WorkflowProcess parse(InputStream in) throws IOException, FPDLParserException {
try {
SAXReader reader = new SAXReader(new DocumentFactory());
reader.setEntityResolver(new EntityResolver() {
String emptyDtd = "";
ByteArrayInputStream bytels = new ByteArrayInputStream(emptyDtd.getBytes());
public InputSource resolveEntity(String publicId, String systemId) {
return new InputSource(bytels);
}
});
Document document = reader.read(in);
return parse(document);
} catch (DocumentException e) {
throw new FPDLParserException("Error parsing document.", e);
}
}
| 類別 | 用途 |
|---|---|
| DateUtilities | 日期格式識別與解析,單例模式,支援 ISO8601、XPDL 等多種格式 |
| MySigleton4DocumentFactory | Dom4J DocumentFactory 單例策略實現 |
| FPDLSerializerException / FPDLParserException | 序列化/解析專用異常,包裝底層錯誤 |
| Util4Serializer / Util4JAXPSerializer | 序列化基礎元素操作封裝 |
| Util4Parser / Util4JAXPParser | 解析基礎元素操作封裝 |
至此 Fire Workflow Model 專案核心模組分析完畢,下一階段將進入 `FireflowEngine` 運行時服務剖析。