1 package org.jbpm.bpel.ant; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.IOException ; 6 import java.util.ArrayList ; 7 import java.util.Iterator ; 8 import java.util.List ; 9 import java.util.zip.ZipInputStream ; 10 11 import javax.naming.Context ; 12 import javax.naming.InitialContext ; 13 import javax.naming.NamingException ; 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 27 public class JndiProcessDeployerTask extends MatchingTask { 28 29 private String file = null; 30 private List fileSets = new ArrayList (); 31 32 public void execute() throws BuildException { 33 Context initialContext = null; 34 try { 35 initialContext = new InitialContext (); 36 JndiProcessDeployer deployer = new JndiProcessDeployer(initialContext); 37 38 if (file!=null) { 39 deployProcessArchive(deployer, new File (file)); 40 } 41 else if (!fileSets.isEmpty()) { 42 Iterator iter = fileSets.iterator(); 43 while (iter.hasNext()) { 44 FileSet fileSet = (FileSet) iter.next(); 45 DirectoryScanner dirScanner = fileSet.getDirectoryScanner(getProject()); 46 String [] fileNames = dirScanner.getIncludedFiles(); 48 for (int i = 0; i < fileNames.length; i++) { 49 String fileName = fileNames[i]; 50 File file = new File (fileName); 51 if ( !file.isFile() ) { 52 file = new File ( dirScanner.getBasedir(), fileName ); 53 } 54 deployProcessArchive(deployer, file); 55 } 56 } 57 } 58 } 59 catch (Exception e) { 60 throw new BuildException(e); 61 } 62 finally { 63 try { 64 initialContext.close(); 65 } 66 catch (NamingException 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 par) { 77 this.file = par; 78 } 79 80 protected void deployProcessArchive(JndiProcessDeployer deployer, File file) throws IOException { 81 ZipInputStream archiveStream = null; 82 try { 83 archiveStream = new ZipInputStream (new FileInputStream (file)); 84 deployer.deployProcessArchive(new ProcessArchive(archiveStream)); 85 } 86 finally { 87 if (archiveStream != null) { 88 try { 89 archiveStream.close(); 90 } 91 catch (IOException e) { 92 log("could not close file: " + e); 93 } 94 } 95 } 96 } 97 } 98 | Popular Tags |