1 17 package org.apache.servicemix.jbi.management.task; 18 19 import java.io.File ; 20 import java.io.FileInputStream ; 21 import java.io.IOException ; 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.Properties ; 26 27 import org.apache.servicemix.jbi.framework.AdminCommandsServiceMBean; 28 import org.apache.tools.ant.BuildException; 29 30 35 public class InstallComponentTask extends JbiTask { 36 37 private String file; private String paramsFile; 39 private List nestedParams; 40 41 44 public String getFile() { 45 return file; 46 } 47 50 public void setFile(String file) { 51 this.file = file; 52 } 53 54 public String getParams() { 55 return paramsFile; 56 } 57 public void setParams(String paramsFile) { 58 this.paramsFile = paramsFile; 59 } 60 61 public Param createParam() { 62 Param p = new Param(); 63 if (nestedParams == null) { 64 nestedParams = new ArrayList (); 65 } 66 nestedParams.add(p); 67 return p; 68 } 69 70 74 public void doExecute(AdminCommandsServiceMBean acs) throws Exception { 75 if (file == null){ 76 throw new BuildException("null file - file should be an archive"); 77 } 78 if (!file.endsWith(".zip") && !file.endsWith(".jar")) { 79 throw new BuildException("file: " + file + " is not an archive"); 80 } 81 File archive = new File (file); 82 String location = archive.getAbsolutePath(); 83 if (!archive.isFile()) { 84 location = file; 86 } 87 Properties props = getProperties(); 88 acs.installComponent(location, props); 89 } 90 91 private Properties getProperties() throws IOException { 92 Properties props = new Properties (); 93 if (paramsFile != null) { 94 props.load(new FileInputStream (paramsFile)); 95 } 96 if (nestedParams != null) { 97 for (Iterator iter = nestedParams.iterator(); iter.hasNext();) { 98 Param p = (Param) iter.next(); 99 props.setProperty(p.getName(), p.getValue()); 100 } 101 } 102 return props; 103 } 104 105 public static class Param { 106 private String name; 107 private String value; 108 public String getName() { 109 return name; 110 } 111 public void setName(String name) { 112 this.name = name; 113 } 114 public String getValue() { 115 return value; 116 } 117 public void setValue(String value) { 118 this.value = value; 119 } 120 } 121 122 } | Popular Tags |