1 22 package org.objectweb.petals.engine.csv; 23 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.IOException ; 27 import java.util.HashMap ; 28 import java.util.Map ; 29 import java.util.Properties ; 30 import java.util.logging.Level ; 31 import java.util.logging.Logger ; 32 33 import javax.jbi.component.ComponentContext; 34 import javax.jbi.management.DeploymentException; 35 import javax.xml.namespace.QName ; 36 37 import org.objectweb.petals.component.common.serviceunitmanager.handler.PetalsServiceUnitHandler; 38 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager; 39 import org.objectweb.petals.component.common.util.ManagementMessageUtil; 40 import org.objectweb.petals.component.common.util.WSDLHelper; 41 42 import org.w3c.dom.Document ; 43 44 59 public class CsvSUHandler extends PetalsServiceUnitHandler { 60 61 62 protected Map <String , Properties > mapServiceCsv; 63 64 protected Map <String , String > mapServiceUnitCsv; 65 66 67 private CsvSUHandler() { 68 super(); 69 SERVICE_UNIT_TYPE="csvServiceUnit"; 70 } 71 72 public CsvSUHandler(ComponentContext context, 73 HashMap <String , Properties > mapServiceCsv, Logger logger) { 74 super(context, logger); 75 this.mapServiceCsv= mapServiceCsv; 76 this.mapServiceUnitCsv = new HashMap <String , String >(); 77 SERVICE_UNIT_TYPE="csvServiceUnit"; 78 } 79 80 81 85 public String deploy(String serviceUnitName, String serviceUnitType, 86 String serviceUnitRootPath) { 87 if (SERVICE_UNIT_TYPE.equals(serviceUnitType)) { 88 logger.info(" DEPLOY serviceUnitName " + serviceUnitName 89 + " serviceUnitRootPath " + serviceUnitRootPath); 90 return ManagementMessageUtil.getComponentTaskResult(context 91 .getComponentName(), "deploy", 92 ManagementMessageUtil.TASK_RESULT_SUCCESS); 93 } else { 94 return null; 95 } 96 } 97 98 101 public void init(String serviceUnitName, String serviceUnitRootPath) 102 throws DeploymentException { 103 this.serviceUnitInstallationRootPath.put(serviceUnitName, serviceUnitRootPath); 104 } 105 106 109 public String undeploy(String serviceUnitName, String serviceUnitRootPath) 110 throws DeploymentException { 111 return ManagementMessageUtil.getComponentTaskResult(context 112 .getComponentName(), "undeploy", 113 ManagementMessageUtil.TASK_RESULT_SUCCESS); 114 } 115 116 119 public void shutDown(String serviceUnitName, PetalsServiceUnitManager epHandler) throws DeploymentException { 120 String csv = this.mapServiceUnitCsv.remove(serviceUnitName); 121 this.mapServiceCsv.remove(csv); 122 } 123 124 125 128 public void start(String serviceUnitName, PetalsServiceUnitManager epHandler) throws DeploymentException { 129 logger.log(Level.FINE, "start serviceUnitName " + serviceUnitName); 130 131 String serviceUnitRootPath = serviceUnitInstallationRootPath.get(serviceUnitName); 134 File [] files = new File (serviceUnitRootPath).listFiles(); 135 Document serviceDesc = null; 136 String propFileName = null; 137 QName service= null; 138 139 for (File file : files) { 140 if (file.getName().endsWith(".wsdl")) { 141 serviceDesc = WSDLHelper.createDocumentFromWSDL(file); 143 } else if (file.getName().endsWith(".properties")){ 144 propFileName = file.getAbsolutePath(); 146 } 147 } 148 149 if (serviceDesc != null) { 151 try { 152 activateEndpointsFromJBIDescription(epHandler, serviceDesc, 153 serviceUnitName, serviceUnitRootPath); 154 service = WSDLHelper.getServiceNameFromWSDLDocument(serviceDesc)[0]; 155 } catch (Exception ex) { 156 logger.log(Level.SEVERE, FAILED_ACTIVATE_ENDPOINT + ex); 157 throw new DeploymentException(FAILED_ACTIVATE_ENDPOINT, ex); 158 } 159 } else { 160 throw new DeploymentException(INCOMPLETE_SERVICE_UNIT_PACKAGE); 161 } 162 163 if (service!=null && propFileName != null) { 165 Properties csvReaderProps = new Properties (); 166 try { 167 csvReaderProps.load(new FileInputStream (propFileName)); 168 } catch (IOException e) { 169 logger.log(Level.SEVERE, FAILED_ACTIVATE_ENDPOINT, e); 170 throw new DeploymentException(FAILED_ACTIVATE_ENDPOINT, e); 171 } 172 mapServiceUnitCsv.put(serviceUnitName, service.getLocalPart()); 173 mapServiceCsv.put(service.getLocalPart(), csvReaderProps); 174 } 175 } 176 177 178 181 public void stop(String serviceUnitName, PetalsServiceUnitManager epHandler) throws DeploymentException { 182 String csv = this.mapServiceUnitCsv.remove(serviceUnitName); 184 this.mapServiceCsv.remove(csv); 185 } 186 } 187 | Popular Tags |