1 22 package org.objectweb.petals.component.common.serviceunitmanager.handler; 23 24 import java.io.File ; 25 import java.util.logging.Level ; 26 import java.util.logging.Logger ; 27 28 import javax.jbi.component.ComponentContext; 29 import javax.jbi.management.DeploymentException; 30 31 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager; 32 import org.objectweb.petals.component.common.util.ManagementMessageUtil; 33 import org.objectweb.petals.component.common.util.WSDLHelper; 34 35 import org.w3c.dom.Document ; 36 37 44 45 public class ExternalServiceManager extends PetalsServiceUnitHandler { 46 47 50 public ExternalServiceManager() { 51 super(); 52 SERVICE_UNIT_TYPE = "external_service"; 53 } 54 55 63 public ExternalServiceManager(ComponentContext context, Logger logger) { 64 super(context, logger); 65 SERVICE_UNIT_TYPE = "external_service"; 66 } 67 68 71 public String deploy(String serviceUnitName, String serviceUnitType 72 , String serviceUnitRootPath) { 73 String result = null; 74 if (SERVICE_UNIT_TYPE.equals(serviceUnitType)) { 75 logger.log(Level.FINE, "deploy serviceUnitName " 76 + serviceUnitName + "serviceUnitRootPath" + serviceUnitRootPath); 77 result = ManagementMessageUtil.getComponentTaskResult(context 78 .getComponentName(), "deploy", 79 ManagementMessageUtil.TASK_RESULT_SUCCESS); 80 } 81 return result; 82 } 83 84 public void init(String serviceUnitName, String serviceUnitRootPath) 85 throws DeploymentException { 86 87 logger.log(Level.FINE, "init serviceUnitName " + serviceUnitName 88 + " serviceUnitRootPath " + serviceUnitRootPath); 89 90 if(serviceUnitInstallationRootPath.put(serviceUnitName, serviceUnitRootPath) != null){ 91 logger.log(Level.SEVERE,ERROR_DUPLICATE_SERVICE_UNIT); 92 throw new DeploymentException(ERROR_DUPLICATE_SERVICE_UNIT); 93 } 94 } 95 96 protected Document getServiceUnitWSDL(String suRootPath) { 97 Document result = null; 98 File [] files = new File (suRootPath).listFiles(); 99 for (File file : files) { 100 if (file.getName().endsWith(".wsdl")) { 101 result = WSDLHelper.createDocumentFromWSDL(file); 102 break; 103 } 104 } 105 return result; 106 } 107 108 public void shutDown(String serviceUnitName, 109 PetalsServiceUnitManager epHandler) throws DeploymentException { 110 logger.log(Level.FINE, "shutdown serviceUnitName " + serviceUnitName); 111 } 112 113 public void start(String serviceUnitName, PetalsServiceUnitManager epHandler) 114 throws DeploymentException { 115 logger.log(Level.FINE, "start serviceUnitName " + serviceUnitName); 116 String suRootPath = serviceUnitInstallationRootPath.get(serviceUnitName); 117 Document serviceDesc = getServiceUnitWSDL(suRootPath); 118 if (serviceDesc != null) { 119 try { 120 activateEndpointsFromJBIDescription(epHandler, serviceDesc, 121 serviceUnitName,suRootPath); 122 } catch (Exception ex) { 123 logger.log(Level.SEVERE, FAILED_ACTIVATE_ENDPOINT + ex); 124 throw new DeploymentException(FAILED_ACTIVATE_ENDPOINT, ex); 125 } 126 } else { 127 throw new DeploymentException(INCOMPLETE_SERVICE_UNIT_PACKAGE); 128 } 129 } 130 131 public void stop(String serviceUnitName, PetalsServiceUnitManager epHandler) 132 throws DeploymentException { 133 try { 134 serviceUnitInstallationRootPath.remove(serviceUnitName); 135 deactivateEndpointsFromJBIDescription(serviceUnitName, epHandler); 136 } catch (Exception e) { 137 throw new DeploymentException(FAILED_DEACTIVATE_ENDPOINT,e); 138 } 139 logger.log(Level.FINE, "stop serviceUnitName " + serviceUnitName); 140 } 141 142 public String undeploy(String serviceUnitName, String serviceUnitRootPath) 143 throws DeploymentException { 144 return ManagementMessageUtil.getComponentTaskResult(context 145 .getComponentName(), "undeploy", 146 ManagementMessageUtil.TASK_RESULT_SUCCESS); 147 } 148 149 } 150 | Popular Tags |