KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.objectweb.petals.tools.ant;
23
24 import java.io.FileInputStream JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Properties JavaDoc;
29
30 import javax.management.Attribute JavaDoc;
31 import javax.management.MBeanServerConnection JavaDoc;
32 import javax.management.ObjectName JavaDoc;
33 import javax.management.remote.JMXConnector JavaDoc;
34
35 import org.apache.tools.ant.BuildException;
36 import org.apache.tools.ant.taskdefs.XSLTProcess.Param;
37 import org.objectweb.petals.tools.ant.managers.InstallerAntTaskAbstract;
38 import org.objectweb.petals.tools.ant.util.JBIJMXConnectorUtil;
39
40 /**
41  * Task used to install a jbi component
42  *
43  * @author ddesjardins - eBMWebsourcing
44  */

45 public class InstallComponentTask extends InstallerAntTaskAbstract {
46
47     private List JavaDoc<Param> param = new ArrayList JavaDoc<Param>();
48
49     /**
50      * Name of the param file
51      */

52     private String JavaDoc params;
53
54     public InstallComponentTask() {
55         super();
56     }
57
58     /**
59      * Execute the ant task
60      *
61      * @throws IOException
62      */

63     public void execute() throws BuildException {
64         try {
65             JMXConnector JavaDoc connector = JBIJMXConnectorUtil.getConnection(host,
66                     port, username, password);
67             MBeanServerConnection JavaDoc connection = connector
68                     .getMBeanServerConnection();
69             Object JavaDoc result = performInstall(connection,
70                     InstallerAntTaskAbstract.LOAD_NEW_INSTALLED);
71             if (result instanceof ObjectName JavaDoc) {
72                 ObjectName JavaDoc installerName = (ObjectName JavaDoc) result;
73                 // Install the component
74
Object JavaDoc[] objects = new Object JavaDoc[0];
75                 String JavaDoc[] strings = new String JavaDoc[0];
76                 connection.invoke(installerName, "install", objects, strings);
77                 try {
78                     log("Installed component name : "
79                             + installerName.getKeyProperty("name"));
80                 } catch (NullPointerException JavaDoc e) {
81                     // Exception thrown when execute outisde of the ant context
82
}
83                 // Get the installer configuration
84
Object JavaDoc result1 = connection.getAttribute(installerName,
85                         "InstallerConfigurationMBean");
86                 if (result1 instanceof ObjectName JavaDoc) {
87                     ObjectName JavaDoc configurationMBean = (ObjectName JavaDoc) result1;
88                     // Set the properties of the params file
89
Properties JavaDoc props = new Properties JavaDoc();
90                     props.load(new FileInputStream JavaDoc(params));
91                     for (Map.Entry JavaDoc entry : props.entrySet()) {
92                         Attribute JavaDoc attribute = new Attribute JavaDoc((String JavaDoc) entry
93                                 .getKey(), (String JavaDoc) entry.getValue());
94                         connection.setAttribute(configurationMBean, attribute);
95                     }
96                     // Set the properties of the <param> element
97
for (Param p : param) {
98                         Attribute JavaDoc attribute = new Attribute JavaDoc((String JavaDoc) p
99                                 .getName(), (String JavaDoc) p.getExpression());
100                         connection.setAttribute(configurationMBean, attribute);
101                     }
102                 }
103             }
104             connector.close();
105         } catch (Exception JavaDoc e) {
106             if (Boolean.parseBoolean(failOnError)) {
107                 throw new BuildException(e.getMessage(), e.getCause());
108             }
109         }
110     }
111
112     public void setParams(String JavaDoc params) {
113         this.params = params;
114     }
115 }
116
Popular Tags