1 22 package org.objectweb.petals.engine.edifact; 23 24 import java.io.File ; 25 26 import java.util.HashMap ; 27 import java.util.Map ; 28 import java.util.logging.Level ; 29 import java.util.logging.Logger ; 30 31 import javax.jbi.component.ComponentContext; 32 import javax.jbi.management.DeploymentException; 33 import javax.xml.namespace.QName ; 34 35 import org.objectweb.petals.component.common.serviceunitmanager.handler.PetalsServiceUnitHandler; 36 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager; 37 import org.objectweb.petals.component.common.util.ManagementMessageUtil; 38 import org.objectweb.petals.component.common.util.WSDLHelper; 39 import org.objectweb.petals.component.common.util.XMLHelper; 40 41 import org.w3c.dom.Document ; 42 import org.w3c.dom.Node ; 43 44 51 public class EdifactSUHandler extends PetalsServiceUnitHandler { 52 53 protected Map <QName , QName > mapEndpointXslt; 54 55 protected Map <String , QName > mapServiceUnitEndpoint; 56 57 public EdifactSUHandler(ComponentContext context, 58 Map <QName , QName > mapServiceXslt, Logger logger) { 59 this.context = context; 60 this.logger = logger; 61 this.mapEndpointXslt = mapServiceXslt; 62 this.mapServiceUnitEndpoint = new HashMap <String , QName >(); 63 SERVICE_UNIT_TYPE = "EdiServiceUnit"; 64 } 65 66 private EdifactSUHandler() { 67 SERVICE_UNIT_TYPE = "EdiServiceUnit"; 68 } 69 70 public void init(String serviceUnitName, String serviceUnitRootPath) 71 throws DeploymentException { 72 logger.log(Level.FINE, "init serviceUnitName " + serviceUnitName); 73 this.serviceUnitInstallationRootPath.put(serviceUnitName, 74 serviceUnitRootPath); 75 } 76 77 public void setContext(ComponentContext context) { 78 this.context = context; 79 } 80 81 public void setLogger(Logger logger) { 82 this.logger = logger; 83 } 84 85 public void shutDown(String serviceUnitName, 86 PetalsServiceUnitManager epHandler) throws DeploymentException { 87 QName service = this.mapServiceUnitEndpoint.remove(serviceUnitName); 88 this.mapEndpointXslt.remove(service); 89 } 90 91 public void start(String serviceUnitName, PetalsServiceUnitManager epHandler) 92 throws DeploymentException { 93 logger.log(Level.FINE, "start serviceUnitName " + serviceUnitName); 94 String serviceUnitRootPath = serviceUnitInstallationRootPath 95 .get(serviceUnitName); 96 File [] files = new File (serviceUnitRootPath).listFiles(); 97 Document serviceDesc = null; 98 QName service = null; 99 String xsltEndpoint = null; 100 File jbiXml = new File (serviceUnitRootPath + File.separator 101 + "META-INF" + File.separator + "jbi.xml"); 102 103 for (File file : files) { 104 if (file.getName().endsWith(".wsdl")) { 105 serviceDesc = WSDLHelper.createDocumentFromWSDL(file); 106 } 107 } 108 if (serviceDesc != null) { 109 try { 110 activateEndpointsFromJBIDescription(epHandler, serviceDesc, 111 serviceUnitName, serviceUnitRootPath); 112 113 xsltEndpoint = loadEndpointFromFile(jbiXml); 114 service = getServiceNameFromJbiXml(jbiXml); 115 116 } catch (Exception ex) { 117 logger.log(Level.SEVERE, FAILED_ACTIVATE_ENDPOINT + ex); 118 throw new DeploymentException(FAILED_ACTIVATE_ENDPOINT, ex); 119 } 120 } else { 121 throw new DeploymentException(INCOMPLETE_SERVICE_UNIT_PACKAGE); 122 } 123 if (service != null && xsltEndpoint != null) { 124 mapServiceUnitEndpoint.put(serviceUnitName, service); 125 mapEndpointXslt.put(service, QName.valueOf(xsltEndpoint)); 126 } 127 } 128 129 public void stop(String serviceUnitName, PetalsServiceUnitManager epHandler) 130 throws DeploymentException { 131 134 QName endpoint = this.mapServiceUnitEndpoint.remove(serviceUnitName); 135 this.mapEndpointXslt.remove(endpoint); 136 try { 137 serviceUnitInstallationRootPath.remove(serviceUnitName); 138 deactivateEndpointsFromJBIDescription(serviceUnitName, epHandler); 139 } catch (Exception e) { 140 throw new DeploymentException(FAILED_DEACTIVATE_ENDPOINT, e); 141 } 142 } 143 144 public String undeploy(String serviceUnitName, String serviceUnitRootPath) 145 throws DeploymentException { 146 return ManagementMessageUtil.getComponentTaskResult(context 147 .getComponentName(), "undeploy", 148 ManagementMessageUtil.TASK_RESULT_SUCCESS); 149 } 150 151 private String loadEndpointFromFile(File configFile) { 152 String value = null; 153 Document jbiDoc = WSDLHelper.createDocumentFromWSDL(configFile); 154 Node providesNode = XMLHelper.findChild(jbiDoc, "consumes", true); 155 value = XMLHelper.getAttributeValue(providesNode, "service-name"); 156 return value; 157 } 158 159 @Override 160 public String deploy(String serviceUnitName, String serviceUnitType, 161 String serviceUnitRootPath) throws DeploymentException { 162 if (SERVICE_UNIT_TYPE.equals(serviceUnitType)) { 163 logger.fine(" DEPLOY serviceUnitName " + serviceUnitName 164 + " serviceUnitRootPath " + serviceUnitRootPath); 165 return ManagementMessageUtil.getComponentTaskResult(context 166 .getComponentName(), "deploy", 167 ManagementMessageUtil.TASK_RESULT_SUCCESS); 168 } else { 169 return null; 170 } 171 } 172 173 } 174 | Popular Tags |