KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > jbi > se > CeltixServiceUnitManager


1 package org.objectweb.celtix.jbi.se;
2
3
4 import java.util.HashMap JavaDoc;
5 import java.util.Map JavaDoc;
6 import java.util.logging.Logger JavaDoc;
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 JavaDoc;
15
16 import org.objectweb.celtix.Bus;
17
18 /** Manage deployment of service units to the Celtix service engine
19  *
20  */

21 public class CeltixServiceUnitManager implements ServiceUnitManager {
22     
23     private static final Logger JavaDoc LOG = Logger.getLogger(CeltixServiceUnitManager.class.getName());
24     
25     private ComponentContext ctx;
26     private final Map JavaDoc<String JavaDoc, CeltixServiceUnit> serviceUnits
27         = new HashMap JavaDoc<String JavaDoc, CeltixServiceUnit>();
28     private final Map JavaDoc<ServiceEndpoint, CeltixServiceUnit> csuMap
29         = new HashMap JavaDoc<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     // Implementation of javax.jbi.component.ServiceUnitManager
41

42     public final void shutDown(final String JavaDoc suName) throws DeploymentException {
43         LOG.info("SU Manaager shutdown " + suName);
44     }
45     
46     public final String JavaDoc deploy(final String JavaDoc suName, final String JavaDoc 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 JavaDoc ex) {
55             ex.printStackTrace();
56             throw new DeploymentException(ex);
57         }
58         
59         String JavaDoc 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 JavaDoc undeploy(final String JavaDoc suName, final String JavaDoc suRootPath) throws DeploymentException {
75         LOG.info("SU Manaager undeploy " + suName + " path: " + suRootPath);
76         
77         csuMap.remove(suName);
78         
79         String JavaDoc 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 JavaDoc suName, final String JavaDoc suRootPath) throws DeploymentException {
95         LOG.info("SU Manaager init " + suName + " path: " + suRootPath);
96     }
97     
98     public final void start(final String JavaDoc 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 JavaDoc suName) throws DeploymentException {
121         LOG.info("SU Manaager stop " + suName);
122     }
123     
124     Document JavaDoc getServiceDescription(final ServiceEndpoint serviceEndpoint) {
125         Document JavaDoc 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