KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.ant;
2
3 import java.io.File JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Iterator JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.zip.ZipInputStream JavaDoc;
10
11 import javax.naming.Context JavaDoc;
12 import javax.naming.InitialContext JavaDoc;
13 import javax.naming.NamingException JavaDoc;
14
15 import org.apache.tools.ant.BuildException;
16 import org.apache.tools.ant.DirectoryScanner;
17 import org.apache.tools.ant.taskdefs.MatchingTask;
18 import org.apache.tools.ant.types.FileSet;
19
20 import org.jbpm.jpdl.par.ProcessArchive;
21
22 import org.jbpm.bpel.par.JndiProcessDeployer;
23
24 /**
25  * ant task for deploying process archives in jndi.
26  */

27 public class JndiProcessDeployerTask extends MatchingTask {
28
29   private String JavaDoc file = null;
30   private List JavaDoc fileSets = new ArrayList JavaDoc();
31
32   public void execute() throws BuildException {
33     Context JavaDoc initialContext = null;
34     try {
35       initialContext = new InitialContext JavaDoc();
36       JndiProcessDeployer deployer = new JndiProcessDeployer(initialContext);
37       
38       if (file!=null) {
39         deployProcessArchive(deployer, new File JavaDoc(file));
40       }
41       else if (!fileSets.isEmpty()) {
42         Iterator JavaDoc iter = fileSets.iterator();
43         while (iter.hasNext()) {
44           FileSet fileSet = (FileSet) iter.next();
45           DirectoryScanner dirScanner = fileSet.getDirectoryScanner(getProject());
46           // process file names in fileSet
47
String JavaDoc[] fileNames = dirScanner.getIncludedFiles();
48           for (int i = 0; i < fileNames.length; i++) {
49             String JavaDoc fileName = fileNames[i];
50             File JavaDoc file = new File JavaDoc(fileName);
51             if ( !file.isFile() ) {
52               file = new File JavaDoc( dirScanner.getBasedir(), fileName );
53             }
54             deployProcessArchive(deployer, file);
55           }
56         }
57       }
58     }
59     catch (Exception JavaDoc e) {
60       throw new BuildException(e);
61     }
62     finally {
63       try {
64         initialContext.close();
65       }
66       catch (NamingException JavaDoc e) {
67         log("could not close naming context: " + e);
68       }
69     }
70   }
71   
72   public void addFileset(FileSet fileSet) {
73     fileSets.add(fileSet);
74   }
75   
76   public void setFile(String JavaDoc par) {
77     this.file = par;
78   }
79   
80   protected void deployProcessArchive(JndiProcessDeployer deployer, File JavaDoc file) throws IOException JavaDoc {
81     ZipInputStream JavaDoc archiveStream = null;
82     try {
83       archiveStream = new ZipInputStream JavaDoc(new FileInputStream JavaDoc(file));
84       deployer.deployProcessArchive(new ProcessArchive(archiveStream));
85     }
86     finally {
87       if (archiveStream != null) {
88         try {
89           archiveStream.close();
90         }
91         catch (IOException JavaDoc e) {
92           log("could not close file: " + e);
93         }
94       }
95     }
96   }
97 }
98
Popular Tags