KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > par > ParDescriptorArchiveParser


1 package org.jbpm.bpel.par;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.xml.sax.InputSource JavaDoc;
9
10 import org.jbpm.graph.def.ProcessDefinition;
11 import org.jbpm.jpdl.par.ProcessArchive;
12 import org.jbpm.jpdl.par.ProcessArchiveParser;
13
14 import org.jbpm.bpel.def.BpelDefinition;
15 import org.jbpm.bpel.def.Import;
16 import org.jbpm.bpel.xml.*;
17
18 /**
19  * @author Alejandro Guízar
20  * @version $Revision: 1.5 $ $Date: 2005/06/23 20:45:05 $
21  */

22 public class ParDescriptorArchiveParser implements ProcessArchiveParser {
23  
24   public static final String JavaDoc PAR_DESCRIPTOR_NAME = "META-INF/bpel-definition.xml";
25   private static final Log log = LogFactory.getLog(ParDescriptorArchiveParser.class);
26   
27   /** {@inheritDoc} */
28   public ProcessDefinition readFromArchive(ProcessArchive archive, ProcessDefinition processDefinition) {
29     BpelDefinition bpelDefinition = new BpelDefinition();
30     // look for descriptor file
31
byte[] entry = archive.removeEntry(PAR_DESCRIPTOR_NAME);
32     if (entry != null) {
33       // read descriptor
34
ParDefinition parDescriptor = new ParDefinition();
35       ParDescriptorReader reader = ParDescriptorReader.getInstance();
36       ProblemCollector readerProblems = new ProblemCollector(PAR_DESCRIPTOR_NAME);
37       reader.setProblemHandler(readerProblems);
38       reader.read(parDescriptor, new InputSource JavaDoc( new ByteArrayInputStream JavaDoc(entry) ));
39       //pump the problems from the par descriptor reader over to the processArchive
40
archive.getProblems().addAll(readerProblems.getProblems());
41       if(! readerProblems.hasErrors() ) {
42         // create bpel definition
43
bpelDefinition.setLocation(parDescriptor.getLocation());
44         // read imported documents
45
List JavaDoc imports = parDescriptor.getImports();
46         if (!imports.isEmpty()) {
47           readDocuments(imports, archive);
48           bpelDefinition.getImports().setImports(imports);
49         }
50       }
51     }
52     else {
53       String JavaDoc message = "descriptor file not found: " + PAR_DESCRIPTOR_NAME;
54       log.error(message);
55       archive.addError(message);
56     }
57     return bpelDefinition;
58   }
59   
60   public void readDocuments(List JavaDoc imports, ProcessArchive archive) {
61     BpelReader bpelReader = BpelReader.getInstance();
62     ArchiveWsdlLocator wsdlLocator = new ArchiveWsdlLocator("", archive);
63     ProblemCollector wsdlProblems = new ProblemCollector();
64     wsdlLocator.setProblemHandler(wsdlProblems);
65     for (int i = 0, n = imports.size(); i < n; i++) {
66       Import imp = (Import) imports.get(i);
67       if (Import.Type.WSDL.equals(imp.getType())) {
68         bpelReader.readWsdlDocument(imp, wsdlLocator);
69       }
70     }
71     //pump the problems from the wsdl reader over to the processArchive
72
archive.getProblems().addAll(wsdlProblems.getProblems());
73   }
74 }
75
Popular Tags