KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > ant > DeployParTask


1 package org.jbpm.ant;
2
3 import java.io.File JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5 import java.io.FileNotFoundException JavaDoc;
6 import java.io.IOException JavaDoc;
7 import java.util.ArrayList JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import java.util.List JavaDoc;
10 import java.util.zip.ZipInputStream JavaDoc;
11
12 import org.apache.tools.ant.BuildException;
13 import org.apache.tools.ant.DirectoryScanner;
14 import org.apache.tools.ant.taskdefs.MatchingTask;
15 import org.apache.tools.ant.types.FileSet;
16 import org.jbpm.db.JbpmSessionFactory;
17 import org.jbpm.jpdl.par.ProcessArchiveDeployer;
18
19 /**
20  * ant task for deploying process archives.
21  */

22 public class DeployParTask extends MatchingTask {
23
24   private String JavaDoc cfg = null;
25   private String JavaDoc properties = null;
26   private String JavaDoc par = null;
27   private List JavaDoc fileSets = new ArrayList JavaDoc();
28
29   public void execute() throws BuildException {
30     try {
31       // get the JbpmSessionFactory
32
JbpmSessionFactory jbpmSessionFactory = AntTaskJbpmSessionFactory.getJbpmSessionFactory(cfg,properties);
33       
34       // if attribute par is set, deploy that par file
35
if (par!=null) {
36         log( "deploying par "+par+" ..." );
37         File JavaDoc file = new File JavaDoc(par);
38         deploy(file, jbpmSessionFactory);
39       }
40       
41       // loop over all files that are specified in the filesets
42
Iterator JavaDoc iter = fileSets.iterator();
43       while (iter.hasNext()) {
44         FileSet fileSet = (FileSet) iter.next();
45         DirectoryScanner dirScanner = fileSet.getDirectoryScanner(getProject());
46         String JavaDoc[] fileSetFiles = dirScanner.getIncludedFiles();
47
48         for (int i = 0; i < fileSetFiles.length; i++) {
49           String JavaDoc fileName = fileSetFiles[i];
50           File JavaDoc file = new File JavaDoc(fileName);
51           if ( !file.isFile() ) {
52             file = new File JavaDoc( dirScanner.getBasedir(), fileName );
53           }
54
55           // deploy the file, specified in a fileset element
56
log( "deploying process archive "+file+" ..." );
57           deploy(file, jbpmSessionFactory);
58         }
59       }
60
61     } catch (Exception JavaDoc e) {
62       e.printStackTrace();
63       throw new BuildException( "couldn't deploy process archives : " + e.getMessage() );
64     }
65   }
66
67   private void deploy(File JavaDoc file, JbpmSessionFactory jbpmSessionFactory) throws IOException JavaDoc, FileNotFoundException JavaDoc {
68     ZipInputStream JavaDoc zipInputStream = new ZipInputStream JavaDoc(new FileInputStream JavaDoc(file));
69     ProcessArchiveDeployer.deployZipInputStream(zipInputStream,jbpmSessionFactory);
70   }
71   
72   public void addFileset(FileSet fileSet) {
73     this.fileSets.add(fileSet);
74   }
75   public void setCfg(String JavaDoc cfg) {
76     this.cfg = cfg;
77   }
78   public void setProperties(String JavaDoc properties) {
79     this.properties = properties;
80   }
81   public void setPar(String JavaDoc par) {
82     this.par = par;
83   }
84 }
85
Popular Tags