1 package org.jbpm.bpel.par; 2 3 import java.io.ByteArrayInputStream ; 4 import java.util.List ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.xml.sax.InputSource ; 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 22 public class ParDescriptorArchiveParser implements ProcessArchiveParser { 23 24 public static final String PAR_DESCRIPTOR_NAME = "META-INF/bpel-definition.xml"; 25 private static final Log log = LogFactory.getLog(ParDescriptorArchiveParser.class); 26 27 28 public ProcessDefinition readFromArchive(ProcessArchive archive, ProcessDefinition processDefinition) { 29 BpelDefinition bpelDefinition = new BpelDefinition(); 30 byte[] entry = archive.removeEntry(PAR_DESCRIPTOR_NAME); 32 if (entry != null) { 33 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 ( new ByteArrayInputStream (entry) )); 39 archive.getProblems().addAll(readerProblems.getProblems()); 41 if(! readerProblems.hasErrors() ) { 42 bpelDefinition.setLocation(parDescriptor.getLocation()); 44 List imports = parDescriptor.getImports(); 46 if (!imports.isEmpty()) { 47 readDocuments(imports, archive); 48 bpelDefinition.getImports().setImports(imports); 49 } 50 } 51 } 52 else { 53 String 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 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 archive.getProblems().addAll(wsdlProblems.getProblems()); 73 } 74 } 75 | Popular Tags |