1 22 package org.objectweb.petals.engine.edifact; 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.ebmwebsourcing.b2bgw.edifact.dictionary.Dictionary; 32 import org.objectweb.petals.component.common.serviceunitmanager.handler.PetalsServiceUnitHandler; 33 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager; 34 import org.objectweb.petals.component.common.util.ManagementMessageUtil; 35 36 43 public class EdifactMappingHandler extends PetalsServiceUnitHandler { 44 45 public EdifactMappingHandler(ComponentContext context, Logger logger) { 46 this.context = context; 47 this.logger = logger; 48 SERVICE_UNIT_TYPE = "EdiMappingServiceUnit"; 49 } 50 51 private EdifactMappingHandler() { 52 SERVICE_UNIT_TYPE = "EdiMappingServiceUnit"; 53 } 54 55 public void init(String serviceUnitName, String serviceUnitRootPath) 56 throws DeploymentException { 57 logger.fine("init serviceUnitName " + serviceUnitName); 58 this.serviceUnitInstallationRootPath.put(serviceUnitName, 59 serviceUnitRootPath); 60 } 61 62 public void setContext(ComponentContext context) { 63 this.context = context; 64 } 65 66 public void setLogger(Logger logger) { 67 this.logger = logger; 68 } 69 70 public void shutDown(String serviceUnitName, 71 PetalsServiceUnitManager epHandler) throws DeploymentException { 72 } 73 74 public void start(String serviceUnitName, PetalsServiceUnitManager epHandler) 75 throws DeploymentException { 76 String serviceUnitRootPath = serviceUnitInstallationRootPath 77 .get(serviceUnitName); 78 79 File [] files = new File (serviceUnitRootPath).listFiles(); 80 81 for (File file : files) { 82 if (file.getName().endsWith(".xml")) { 83 try { 84 Dictionary.getInstance().reloadMapping( 85 file.getAbsolutePath()); 86 } catch (Exception e) { 87 String msg = "Error loading mapping in Edifact Dictionary"; 88 logger.log(Level.SEVERE, msg); 89 throw new DeploymentException(msg, e); 90 } 91 92 } 93 } 94 } 95 96 public void stop(String serviceUnitName, PetalsServiceUnitManager epHandler) 97 throws DeploymentException { 98 101 try { 102 serviceUnitInstallationRootPath.remove(serviceUnitName); 103 deactivateEndpointsFromJBIDescription(serviceUnitName, epHandler); 104 } catch (Exception e) { 105 throw new DeploymentException(FAILED_DEACTIVATE_ENDPOINT, e); 106 } 107 } 108 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 @Override 117 public String deploy(String serviceUnitName, String serviceUnitType, 118 String serviceUnitRootPath) throws DeploymentException { 119 if (SERVICE_UNIT_TYPE.equals(serviceUnitType)) { 120 logger.fine(" DEPLOY serviceUnitName " + serviceUnitName 121 + " serviceUnitRootPath " + serviceUnitRootPath); 122 return ManagementMessageUtil.getComponentTaskResult(context 123 .getComponentName(), "deploy", 124 ManagementMessageUtil.TASK_RESULT_SUCCESS); 125 } else { 126 return null; 127 } 128 } 129 130 } 131 | Popular Tags |