KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > tools > ant > DeployServiceAssemblyTask


1 /**
2  * PETALS: PETALS Services Platform
3  * Copyright (C) 2005 EBM WebSourcing
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): EBM WebSourcing
21  * --------------------------------------------------------------------------
22  * $Id: DeployServiceAssemblyTask.java,v 1.2 2005/07/22 10:24:27 ddesjardins Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.petals.tools.ant;
26
27 import java.net.URL JavaDoc;
28
29 import javax.management.MBeanServerConnection JavaDoc;
30 import javax.management.remote.JMXConnector JavaDoc;
31
32 import org.apache.tools.ant.BuildException;
33 import org.objectweb.petals.tools.ant.managers.InstallerAntTaskAbstract;
34 import org.objectweb.petals.tools.ant.util.JBIJMXConnectorUtil;
35
36 /**
37  * Task used to deploy a service asembly
38  *
39  * @author ddesjardins - eBMWebsourcing
40  */

41 public class DeployServiceAssemblyTask extends InstallerAntTaskAbstract {
42
43     public DeployServiceAssemblyTask() {
44         super();
45     }
46
47     /**
48      * Execute the ant task
49      *
50      * @throws IOException
51      */

52     public void execute() throws BuildException {
53         if (file == null) {
54             throw new BuildException("Required attribute : file");
55         }
56         try {
57             // Test if the provided file name is a correct URL
58
new URL JavaDoc(file);
59             JMXConnector JavaDoc connector = JBIJMXConnectorUtil.getConnection(host,
60                     port, username, password);
61             MBeanServerConnection JavaDoc connection = connector
62                     .getMBeanServerConnection();
63             Object JavaDoc[] objects = new Object JavaDoc[1];
64             objects[0] = file;
65             String JavaDoc[] strings = new String JavaDoc[1];
66             strings[0] = "java.lang.String";
67             Object JavaDoc result = connection.invoke(JBIJMXConnectorUtil
68                     .getDeploymentServiceMBeanName(connection), "deploy",
69                     objects, strings);
70             if (result instanceof String JavaDoc) {
71                 // Extract the service assembly name
72
String JavaDoc xml = (String JavaDoc) result;
73                 if (xml.indexOf("Successfully") > -1) {
74                     String JavaDoc saName = "";
75                     saName = xml.substring(xml.indexOf("<loc-param>") + 11, xml
76                             .indexOf("</loc-param>"));
77                     try {
78                         log("Deployed service assembly name : " + saName);
79                     } catch (NullPointerException JavaDoc e) {
80                         // Exception thrown when execute outisde of the ant
81
// context
82
}
83                 } else {
84                     try {
85                         log("Problem during deployement :\n" + (String JavaDoc) result);
86                     } catch (NullPointerException JavaDoc e) {
87                         // Exception thrown when execute outisde of the ant
88
// context
89
}
90                 }
91             }
92             connector.close();
93         } catch (Exception JavaDoc e) {
94             if (Boolean.parseBoolean(failOnError)) {
95                 throw new BuildException(e.getMessage(), e.getCause());
96             }
97         }
98     }
99 }
100
Popular Tags