KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > tools > ant > managers > ServiceAssemblyAntTaskAbstract


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
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 (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: AntTaskServiceAssemnly.java 09:12:57 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.tools.ant.managers;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.remote.JMXConnector JavaDoc;
26
27 import org.apache.tools.ant.BuildException;
28 import org.objectweb.petals.tools.ant.util.JBIJMXConnectorUtil;
29
30 /**
31  * This class gathers the action on a service assembly
32  *
33  * @author ddesjardins - eBMWebsourcing
34  */

35 public abstract class ServiceAssemblyAntTaskAbstract extends JBIAntTaskAbstract {
36
37     /**
38      * Action : shutdown a service assembly
39      */

40     protected static final String JavaDoc SHUTDOWN = "shutDown";
41
42     /**
43      * Action : start a service assembly
44      */

45     protected static final String JavaDoc START = "start";
46
47     /**
48      * Action : stop a service assembly
49      */

50     protected static final String JavaDoc STOP = "stop";
51
52     /**
53      * Action : undeploy a service assembly
54      */

55     protected static final String JavaDoc UNDEPLOY = "undeploy";
56
57     /**
58      * Name of the service assembly
59      */

60     protected String JavaDoc name;
61
62     /**
63      * Perform an action on a service assembly
64      * @param action
65      */

66     protected void performAction(String JavaDoc action) {
67         if (name == null) {
68             throw new BuildException("Required attribute : name");
69         }
70         try {
71             JMXConnector JavaDoc connector = JBIJMXConnectorUtil.getConnection(host,
72                     port, username, password);
73             MBeanServerConnection JavaDoc connection = connector
74                     .getMBeanServerConnection();
75             Object JavaDoc[] objects = new Object JavaDoc[1];
76             objects[0] = name;
77             String JavaDoc[] strings = new String JavaDoc[1];
78             strings[0] = "java.lang.String";
79             Object JavaDoc result = connection.invoke(JBIJMXConnectorUtil
80                     .getDeploymentServiceMBeanName(connection), action,
81                     objects, strings);
82             if (result instanceof String JavaDoc) {
83                 // Extract the service assembly name
84
String JavaDoc xml = (String JavaDoc) result;
85                 if (xml.indexOf("Successfully") > -1) {
86                     String JavaDoc saName = "";
87                     saName = xml.substring(xml.indexOf("<loc-param>") + 11, xml
88                             .indexOf("</loc-param>"));
89                     try {
90                         log("Started service assembly name : " + saName);
91                     } catch (NullPointerException JavaDoc e) {
92                         // Exception thrown when execute outisde of the ant
93
// context
94
}
95                 } else {
96                     try {
97                         log("Problem during the " + action + " :\n"
98                                 + (String JavaDoc) result);
99                     } catch (NullPointerException JavaDoc e) {
100                         // Exception thrown when execute outisde of the ant
101
// context
102
}
103                 }
104             }
105             connector.close();
106         } catch (Exception JavaDoc e) {
107             if (Boolean.parseBoolean(failOnError)) {
108                 throw new BuildException(e.getMessage(), e.getCause());
109             }
110         }
111     }
112
113     public void setName(String JavaDoc name) {
114         this.name = name;
115     }
116
117 }
118
Popular Tags