KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > jpdl > par > JpdlArchiveParser


1 package org.jbpm.jpdl.par;
2
3 import java.io.*;
4
5 import org.jbpm.graph.def.*;
6 import org.jbpm.jpdl.*;
7 import org.jbpm.jpdl.xml.*;
8
9 public class JpdlArchiveParser implements ProcessArchiveParser {
10
11   public ProcessDefinition readFromArchive(ProcessArchive processArchive, ProcessDefinition processDefinition) {
12     try {
13       // getting the value
14
byte[] processBytes = processArchive.removeEntry("processdefinition.xml");
15       
16       if (processBytes==null) {
17         throw new JpdlException("no processdefinition.xml inside process archive");
18       }
19       
20       // creating the JpdlXmlReader
21
InputStream processInputStream = new ByteArrayInputStream(processBytes);
22       Reader processReader = new InputStreamReader(processInputStream);
23       JpdlXmlReader jpdlReader = new JpdlXmlReader(processReader);
24       
25       try {
26         // pump the problems from the jpdlReader over to the processArchive
27
processDefinition = jpdlReader.readProcessDefinition();
28       } catch (JpdlException e) {
29         e.printStackTrace();
30         // pump the problems from the jpdlReader over to the processArchive
31
processArchive.getProblems().addAll(e.getProblems());
32       }
33
34       // close all the streams
35
jpdlReader.close();
36       processReader.close();
37       processInputStream.close();
38       
39     } catch (IOException e) {
40       processArchive.addWarning("io problem while reading processdefinition.xml: "+e.getMessage() );
41     }
42     
43     return processDefinition;
44   }
45 }
46
Popular Tags