1 22 package org.objectweb.petals.tools.ant; 23 24 import java.io.FileInputStream ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.Properties ; 29 30 import javax.management.Attribute ; 31 import javax.management.MBeanServerConnection ; 32 import javax.management.ObjectName ; 33 import javax.management.remote.JMXConnector ; 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 45 public class InstallComponentTask extends InstallerAntTaskAbstract { 46 47 private List <Param> param = new ArrayList <Param>(); 48 49 52 private String params; 53 54 public InstallComponentTask() { 55 super(); 56 } 57 58 63 public void execute() throws BuildException { 64 try { 65 JMXConnector connector = JBIJMXConnectorUtil.getConnection(host, 66 port, username, password); 67 MBeanServerConnection connection = connector 68 .getMBeanServerConnection(); 69 Object result = performInstall(connection, 70 InstallerAntTaskAbstract.LOAD_NEW_INSTALLED); 71 if (result instanceof ObjectName ) { 72 ObjectName installerName = (ObjectName ) result; 73 Object [] objects = new Object [0]; 75 String [] strings = new String [0]; 76 connection.invoke(installerName, "install", objects, strings); 77 try { 78 log("Installed component name : " 79 + installerName.getKeyProperty("name")); 80 } catch (NullPointerException e) { 81 } 83 Object result1 = connection.getAttribute(installerName, 85 "InstallerConfigurationMBean"); 86 if (result1 instanceof ObjectName ) { 87 ObjectName configurationMBean = (ObjectName ) result1; 88 Properties props = new Properties (); 90 props.load(new FileInputStream (params)); 91 for (Map.Entry entry : props.entrySet()) { 92 Attribute attribute = new Attribute ((String ) entry 93 .getKey(), (String ) entry.getValue()); 94 connection.setAttribute(configurationMBean, attribute); 95 } 96 for (Param p : param) { 98 Attribute attribute = new Attribute ((String ) p 99 .getName(), (String ) p.getExpression()); 100 connection.setAttribute(configurationMBean, attribute); 101 } 102 } 103 } 104 connector.close(); 105 } catch (Exception e) { 106 if (Boolean.parseBoolean(failOnError)) { 107 throw new BuildException(e.getMessage(), e.getCause()); 108 } 109 } 110 } 111 112 public void setParams(String params) { 113 this.params = params; 114 } 115 } 116 | Popular Tags |