KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > ant > PortComponentsTask


1 package org.jbpm.bpel.ant;
2
3 import java.io.FileInputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.util.zip.ZipInputStream JavaDoc;
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 /**
16  * ant task for generating wsdl ports
17  */

18 public class PortComponentsTask extends Task {
19
20   private String JavaDoc processfile = null;
21   private String JavaDoc 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 JavaDoc processStream = null;
37     try {
38       processStream = new FileInputStream JavaDoc(processfile);
39       return new ProcessArchive(new ZipInputStream JavaDoc(processStream));
40     }
41     catch (IOException JavaDoc e) {
42       throw new BuildException(e);
43     }
44     finally {
45       if (processStream != null) {
46         try {
47           processStream.close();
48         }
49         catch (IOException JavaDoc e) {
50           log(e.toString());
51         }
52       }
53     }
54   }
55
56   public void setProcessfile(String JavaDoc processfile) {
57     this.processfile = processfile;
58   }
59   
60   public void setOutputdir(String JavaDoc outputdir) {
61     this.outputdir = outputdir;
62   }
63 }
64
Popular Tags