001: package org.objectweb.celtix.jbi.se;
002:
003: import java.util.HashMap;
004: import java.util.Map;
005: import java.util.logging.Logger;
006:
007: import javax.jbi.JBIException;
008: import javax.jbi.component.ComponentContext;
009: import javax.jbi.component.ServiceUnitManager;
010: import javax.jbi.management.DeploymentException;
011: import javax.jbi.servicedesc.ServiceEndpoint;
012:
013: import org.w3c.dom.Document;
014:
015: import org.objectweb.celtix.Bus;
016:
017: /** Manage deployment of service units to the Celtix service engine
018: *
019: */
020: public class CeltixServiceUnitManager implements ServiceUnitManager {
021:
022: private static final Logger LOG = Logger
023: .getLogger(CeltixServiceUnitManager.class.getName());
024:
025: private ComponentContext ctx;
026: private final Map<String, CeltixServiceUnit> serviceUnits = new HashMap<String, CeltixServiceUnit>();
027: private final Map<ServiceEndpoint, CeltixServiceUnit> csuMap = new HashMap<ServiceEndpoint, CeltixServiceUnit>();
028:
029: private final Bus bus;
030: private final ComponentClassLoader componentParentLoader;
031:
032: public CeltixServiceUnitManager(Bus b, ComponentContext c,
033: ComponentClassLoader loader) {
034: ctx = c;
035: bus = b;
036: componentParentLoader = loader;
037: }
038:
039: // Implementation of javax.jbi.component.ServiceUnitManager
040:
041: public final void shutDown(final String suName)
042: throws DeploymentException {
043: LOG.info("SU Manaager shutdown " + suName);
044: }
045:
046: public final String deploy(final String suName,
047: final String suRootPath) throws DeploymentException {
048: LOG.info("SU Manaager deploy " + suName + " path: "
049: + suRootPath);
050:
051: try {
052: Thread.currentThread().setContextClassLoader(
053: componentParentLoader);
054: CeltixServiceUnit csu = new CeltixServiceUnit(bus,
055: suRootPath, componentParentLoader);
056: csu.prepare(ctx);
057: serviceUnits.put(suName, csu);
058: } catch (Exception ex) {
059: ex.printStackTrace();
060: throw new DeploymentException(ex);
061: }
062:
063: String msg = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
064: + "<component-task-result>"
065: + " <component-name>"
066: + suName
067: + "</component-name>"
068: + " <component-task-result-details"
069: + " xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">"
070: + " <task-result-details>"
071: + " <task-id>deploy</task-id>"
072: + " <task-result>SUCCESS</task-result>"
073: + " </task-result-details>"
074: + " </component-task-result-details>"
075: + "</component-task-result>";
076:
077: return msg;
078: }
079:
080: public final String undeploy(final String suName,
081: final String suRootPath) throws DeploymentException {
082: LOG.info("SU Manaager undeploy " + suName + " path: "
083: + suRootPath);
084:
085: csuMap.remove(suName);
086:
087: String msg = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
088: + "<component-task-result>"
089: + " <component-name>"
090: + suName
091: + "</component-name>"
092: + " <component-task-result-details"
093: + " xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">"
094: + " <task-result-details>"
095: + " <task-id>undeploy</task-id>"
096: + " <task-result>SUCCESS</task-result>"
097: + " </task-result-details>"
098: + " </component-task-result-details>"
099: + "</component-task-result>";
100:
101: return msg;
102: }
103:
104: public final void init(final String suName, final String suRootPath)
105: throws DeploymentException {
106: LOG.info("SU Manaager init " + suName + " path: " + suRootPath);
107: }
108:
109: public final void start(final String suName)
110: throws DeploymentException {
111: LOG.info("SU Manaager start " + suName);
112:
113: try {
114: CeltixServiceUnit csu = serviceUnits.get(suName);
115: assert csu != null;
116:
117: if (csu.isServiceProvider()) {
118: ServiceEndpoint ref = ctx.activateEndpoint(csu
119: .getServiceName(), csu.getEndpointName());
120: LOG.fine("activated endpoint: " + ref.getEndpointName()
121: + " service: " + ref.getServiceName());
122: csuMap.put(ref, csu);
123: }
124: } catch (JBIException ex) {
125: ex.printStackTrace();
126: }
127: }
128:
129: public final CeltixServiceUnit getServiceUnitForEndpoint(
130: ServiceEndpoint ep) {
131: return csuMap.get(ep);
132: }
133:
134: public final void stop(final String suName)
135: throws DeploymentException {
136: LOG.info("SU Manaager stop " + suName);
137: }
138:
139: Document getServiceDescription(final ServiceEndpoint serviceEndpoint) {
140: Document ret = null;
141:
142: if (csuMap.keySet().contains(serviceEndpoint)) {
143: CeltixServiceUnit csu = csuMap.get(serviceEndpoint);
144: ret = csu.getWsdlAsDocument();
145: }
146: return ret;
147: }
148: }
|