View Javadoc

1   /*
2    * $Id: DeployTask.java,v 1.1 2004/12/15 14:18:17 patforna Exp $
3    *
4    * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
5    * Berne University of Applied Sciences
6    * School of Engineering and Information Technology
7    * All rights reserved.
8    */
9   package bexee.ant;
10  
11  import java.io.File;
12  import java.util.ArrayList;
13  import java.util.Iterator;
14  import java.util.List;
15  import java.util.Vector;
16  
17  import org.apache.tools.ant.BuildException;
18  import org.apache.tools.ant.DirectoryScanner;
19  import org.apache.tools.ant.Task;
20  import org.apache.tools.ant.types.FileSet;
21  import org.apache.tools.ant.util.FileUtils;
22  
23  import bexee.admin.Admin;
24  import bexee.admin.AdminException;
25  
26  /***
27   * Deploys a BPEL process to bexee.
28   * 
29   * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:17 $
30   * @author Patric Fornasier
31   * @author Pawel Kowalski
32   */
33  public class DeployTask extends Task {
34  
35      private String url;
36  
37      private File bpel;
38  
39      private File wsdl;
40  
41      private Vector partnerWSDL = new Vector();
42  
43      /***
44       * BPEL file to deploy.
45       * 
46       * @param bpel
47       *            a <code>File</code>
48       */
49      public void setBpel(File bpel) {
50          this.bpel = bpel;
51      }
52  
53      /***
54       * Location of the Manager Web Service.
55       * 
56       * @param url
57       *            a <code>URL</code>
58       */
59      public void setUrl(String url) {
60          this.url = url;
61      }
62  
63      /***
64       * WSDL file describing the BPEL process.
65       * 
66       * @param wsdl
67       *            a <code>File</code>
68       */
69      public void setWSDL(File wsdl) {
70          this.wsdl = wsdl;
71      }
72  
73      /***
74       * Additional WSDL files describing partner Web Services.
75       * 
76       * @param set
77       *            <code>FileSet</code>
78       */
79      public void addPartnerWSDL(FileSet set) {
80          partnerWSDL.addElement(set);
81      }
82  
83      /***
84       * Deploys the process to bexee.
85       */
86      public void execute() throws BuildException {
87  
88          // check if the required parameter have been set
89          if (url == null || bpel == null || wsdl == null) {
90              throw new BuildException("All of url, bpel and wsdl are required");
91          }
92  
93          // get partner wsdl files if any available
94          List partnerWSDL = getPartnerWSDL();
95  
96          // create admin client with url to Manager service
97          Admin admin = new Admin(url);
98  
99          // deploy to Manager
100         try {
101             String result = admin.deploy(bpel, wsdl, partnerWSDL);
102             log(result);
103         } catch (AdminException e) {
104             throw new BuildException(e);
105         }
106     }
107 
108     /***
109      * Helper method to get partner WSDL files.
110      */
111     private List getPartnerWSDL() {
112 
113         List result = new ArrayList();
114 
115         // get partner wsdl files
116         FileUtils fileUtils = FileUtils.newFileUtils();
117         for (Iterator iter = partnerWSDL.iterator(); iter.hasNext();) {
118 
119             FileSet fs = (FileSet) iter.next();
120             DirectoryScanner ds = fs.getDirectoryScanner(getProject());
121 
122             String[] files = ds.getIncludedFiles();
123             File dir = fs.getDir(getProject());
124             for (int i = 0; i < files.length; i++) {
125                 String name = files[i];
126                 if (!name.equals("")) {
127                     File file = fileUtils.resolveFile(dir, name);
128                     result.add(file);
129                 }
130             }
131         }
132 
133         return result;
134     }
135 }