1 package org.jbpm.bpel.ant; 2 3 import java.io.FileInputStream ; 4 import java.io.IOException ; 5 import java.util.zip.ZipInputStream ; 6 7 import org.apache.tools.ant.BuildException; 8 import org.apache.tools.ant.Task; 9 10 import org.jbpm.bpel.def.BpelDefinition; 11 import org.jbpm.bpel.wsdl.util.PortComponentsGenerator; 12 import org.jbpm.jpdl.par.ProcessArchive; 13 import org.jbpm.jpdl.xml.Problem; 14 15 18 public class PortComponentsTask extends Task { 19 20 private String processfile = null; 21 private String outputdir = null; 22 23 public void execute() throws BuildException { 24 ProcessArchive archive = createProcessArchive(); 25 BpelDefinition definition = (BpelDefinition) archive.parseProcessDefinition(); 26 boolean invalidArchive = Problem.containsProblemsOfLevel(archive.getProblems(), Problem.LEVEL_ERROR); 27 if( invalidArchive ) { 28 throw new BuildException("Process definition is invalid"); 29 } 30 PortComponentsGenerator generator = new PortComponentsGenerator(); 31 generator.setOutputDirectory(outputdir); 32 generator.generatePortComponents(definition); 33 } 34 35 private ProcessArchive createProcessArchive() throws BuildException { 36 FileInputStream processStream = null; 37 try { 38 processStream = new FileInputStream (processfile); 39 return new ProcessArchive(new ZipInputStream (processStream)); 40 } 41 catch (IOException e) { 42 throw new BuildException(e); 43 } 44 finally { 45 if (processStream != null) { 46 try { 47 processStream.close(); 48 } 49 catch (IOException e) { 50 log(e.toString()); 51 } 52 } 53 } 54 } 55 56 public void setProcessfile(String processfile) { 57 this.processfile = processfile; 58 } 59 60 public void setOutputdir(String outputdir) { 61 this.outputdir = outputdir; 62 } 63 } 64 | Popular Tags |