001: /*
002: * $Id: DeployTask.java,v 1.4 2004/12/06 07:53:36 fornp1 Exp $
003: *
004: * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
005: * Berne University of Applied Sciences
006: * School of Engineering and Information Technology
007: * All rights reserved.
008: */
009: package bexee.ant;
010:
011: import java.io.File;
012: import java.util.ArrayList;
013: import java.util.Iterator;
014: import java.util.List;
015: import java.util.Vector;
016:
017: import org.apache.tools.ant.BuildException;
018: import org.apache.tools.ant.DirectoryScanner;
019: import org.apache.tools.ant.Task;
020: import org.apache.tools.ant.types.FileSet;
021: import org.apache.tools.ant.util.FileUtils;
022:
023: import bexee.admin.Admin;
024: import bexee.admin.AdminException;
025:
026: /**
027: * Deploys a BPEL process to bexee.
028: *
029: * @version $Revision: 1.4 $, $Date: 2004/12/06 07:53:36 $
030: * @author Patric Fornasier
031: * @author Pawel Kowalski
032: */
033: public class DeployTask extends Task {
034:
035: private String url;
036:
037: private File bpel;
038:
039: private File wsdl;
040:
041: private Vector partnerWSDL = new Vector();
042:
043: /**
044: * BPEL file to deploy.
045: *
046: * @param bpel
047: * a <code>File</code>
048: */
049: public void setBpel(File bpel) {
050: this .bpel = bpel;
051: }
052:
053: /**
054: * Location of the Manager Web Service.
055: *
056: * @param url
057: * a <code>URL</code>
058: */
059: public void setUrl(String url) {
060: this .url = url;
061: }
062:
063: /**
064: * WSDL file describing the BPEL process.
065: *
066: * @param wsdl
067: * a <code>File</code>
068: */
069: public void setWSDL(File wsdl) {
070: this .wsdl = wsdl;
071: }
072:
073: /**
074: * Additional WSDL files describing partner Web Services.
075: *
076: * @param set
077: * <code>FileSet</code>
078: */
079: public void addPartnerWSDL(FileSet set) {
080: partnerWSDL.addElement(set);
081: }
082:
083: /**
084: * Deploys the process to bexee.
085: */
086: public void execute() throws BuildException {
087:
088: // check if the required parameter have been set
089: if (url == null || bpel == null || wsdl == null) {
090: throw new BuildException(
091: "All of url, bpel and wsdl are required");
092: }
093:
094: // get partner wsdl files if any available
095: List partnerWSDL = getPartnerWSDL();
096:
097: // create admin client with url to Manager service
098: Admin admin = new Admin(url);
099:
100: // deploy to Manager
101: try {
102: String result = admin.deploy(bpel, wsdl, partnerWSDL);
103: log(result);
104: } catch (AdminException e) {
105: throw new BuildException(e);
106: }
107: }
108:
109: /**
110: * Helper method to get partner WSDL files.
111: */
112: private List getPartnerWSDL() {
113:
114: List result = new ArrayList();
115:
116: // get partner wsdl files
117: FileUtils fileUtils = FileUtils.newFileUtils();
118: for (Iterator iter = partnerWSDL.iterator(); iter.hasNext();) {
119:
120: FileSet fs = (FileSet) iter.next();
121: DirectoryScanner ds = fs.getDirectoryScanner(getProject());
122:
123: String[] files = ds.getIncludedFiles();
124: File dir = fs.getDir(getProject());
125: for (int i = 0; i < files.length; i++) {
126: String name = files[i];
127: if (!name.equals("")) {
128: File file = fileUtils.resolveFile(dir, name);
129: result.add(file);
130: }
131: }
132: }
133:
134: return result;
135: }
136: }
|