1 package org.objectweb.celtix.jbi.se; 2 3 4 import java.util.HashMap ; 5 import java.util.Map ; 6 import java.util.logging.Logger ; 7 8 import javax.jbi.JBIException; 9 import javax.jbi.component.ComponentContext; 10 import javax.jbi.component.ServiceUnitManager; 11 import javax.jbi.management.DeploymentException; 12 import javax.jbi.servicedesc.ServiceEndpoint; 13 14 import org.w3c.dom.Document ; 15 16 import org.objectweb.celtix.Bus; 17 18 21 public class CeltixServiceUnitManager implements ServiceUnitManager { 22 23 private static final Logger LOG = Logger.getLogger(CeltixServiceUnitManager.class.getName()); 24 25 private ComponentContext ctx; 26 private final Map <String , CeltixServiceUnit> serviceUnits 27 = new HashMap <String , CeltixServiceUnit>(); 28 private final Map <ServiceEndpoint, CeltixServiceUnit> csuMap 29 = new HashMap <ServiceEndpoint, CeltixServiceUnit>(); 30 31 private final Bus bus; 32 private final ComponentClassLoader componentParentLoader; 33 34 public CeltixServiceUnitManager(Bus b, ComponentContext c, ComponentClassLoader loader) { 35 ctx = c; 36 bus = b; 37 componentParentLoader = loader; 38 } 39 40 42 public final void shutDown(final String suName) throws DeploymentException { 43 LOG.info("SU Manaager shutdown " + suName); 44 } 45 46 public final String deploy(final String suName, final String suRootPath) throws DeploymentException { 47 LOG.info("SU Manaager deploy " + suName + " path: " + suRootPath); 48 49 try { 50 Thread.currentThread().setContextClassLoader(componentParentLoader); 51 CeltixServiceUnit csu = new CeltixServiceUnit(bus, suRootPath, componentParentLoader); 52 csu.prepare(ctx); 53 serviceUnits.put(suName, csu); 54 } catch (Exception ex) { 55 ex.printStackTrace(); 56 throw new DeploymentException(ex); 57 } 58 59 String msg = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" 60 + "<component-task-result>" 61 + " <component-name>" + suName + "</component-name>" 62 + " <component-task-result-details" 63 + " xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">" 64 + " <task-result-details>" 65 + " <task-id>deploy</task-id>" 66 + " <task-result>SUCCESS</task-result>" 67 + " </task-result-details>" 68 + " </component-task-result-details>" 69 + "</component-task-result>"; 70 71 return msg; 72 } 73 74 public final String undeploy(final String suName, final String suRootPath) throws DeploymentException { 75 LOG.info("SU Manaager undeploy " + suName + " path: " + suRootPath); 76 77 csuMap.remove(suName); 78 79 String msg = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" 80 + "<component-task-result>" 81 + " <component-name>" + suName + "</component-name>" 82 + " <component-task-result-details" 83 + " xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">" 84 + " <task-result-details>" 85 + " <task-id>undeploy</task-id>" 86 + " <task-result>SUCCESS</task-result>" 87 + " </task-result-details>" 88 + " </component-task-result-details>" 89 + "</component-task-result>"; 90 91 return msg; 92 } 93 94 public final void init(final String suName, final String suRootPath) throws DeploymentException { 95 LOG.info("SU Manaager init " + suName + " path: " + suRootPath); 96 } 97 98 public final void start(final String suName) throws DeploymentException { 99 LOG.info("SU Manaager start " + suName); 100 101 try { 102 CeltixServiceUnit csu = serviceUnits.get(suName); 103 assert csu != null; 104 105 if (csu.isServiceProvider()) { 106 ServiceEndpoint ref = ctx.activateEndpoint(csu.getServiceName(), csu.getEndpointName()); 107 LOG.fine("activated endpoint: " + ref.getEndpointName() 108 + " service: " + ref.getServiceName()); 109 csuMap.put(ref, csu); 110 } 111 } catch (JBIException ex) { 112 ex.printStackTrace(); 113 } 114 } 115 116 public final CeltixServiceUnit getServiceUnitForEndpoint(ServiceEndpoint ep) { 117 return csuMap.get(ep); 118 } 119 120 public final void stop(final String suName) throws DeploymentException { 121 LOG.info("SU Manaager stop " + suName); 122 } 123 124 Document getServiceDescription(final ServiceEndpoint serviceEndpoint) { 125 Document ret = null; 126 127 if (csuMap.keySet().contains(serviceEndpoint)) { 128 CeltixServiceUnit csu = csuMap.get(serviceEndpoint); 129 ret = csu.getWsdlAsDocument(); 130 } 131 return ret; 132 } 133 } 134 | Popular Tags |