01: package org.emforge.jbpm.parser;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.IOException;
05: import java.io.InputStream;
06:
07: import org.jbpm.graph.def.ProcessDefinition;
08: import org.jbpm.jpdl.JpdlException;
09: import org.jbpm.jpdl.par.JpdlArchiveParser;
10: import org.jbpm.jpdl.par.ProcessArchive;
11: import org.xml.sax.InputSource;
12:
13: /** Own implementation of JbpmParser
14: *
15: * Required only to create own instance of JbpmReader
16: */
17: public class EmForgeJbpmParser extends JpdlArchiveParser {
18: private static final long serialVersionUID = -1121951708449044407L;
19:
20: public ProcessDefinition readFromArchive(
21: ProcessArchive processArchive,
22: ProcessDefinition processDefinition) throws JpdlException {
23: try {
24: // getting the value
25: byte[] processBytes = processArchive
26: .getEntry("processdefinition.xml");
27:
28: if (processBytes == null) {
29: throw new JpdlException(
30: "no processdefinition.xml inside process archive");
31: }
32:
33: // creating the JpdlXmlReader
34: InputStream processInputStream = new ByteArrayInputStream(
35: processBytes);
36: InputSource processInputSource = new InputSource(
37: processInputStream);
38: EmForgeJpdlReader jpdlXmlReader = new EmForgeJpdlReader(
39: processInputSource, processArchive);
40:
41: processDefinition = jpdlXmlReader.readProcessDefinition();
42:
43: // close all the streams
44: jpdlXmlReader.close();
45: processInputStream.close();
46:
47: } catch (IOException e) {
48: throw new JpdlException(
49: "io problem while reading processdefinition.xml: "
50: + e.getMessage(), e);
51: }
52:
53: return processDefinition;
54: }
55: }
|