KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > component > common > serviceunitmanager > handler > ExternalServiceManager


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: InstallationService.java 154 2006-03-27 15:30:10Z wjoseph $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.component.common.serviceunitmanager.handler;
23
24 import java.io.File JavaDoc;
25 import java.util.logging.Level JavaDoc;
26 import java.util.logging.Logger JavaDoc;
27
28 import javax.jbi.component.ComponentContext;
29 import javax.jbi.management.DeploymentException;
30
31 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager;
32 import org.objectweb.petals.component.common.util.ManagementMessageUtil;
33 import org.objectweb.petals.component.common.util.WSDLHelper;
34
35 import org.w3c.dom.Document JavaDoc;
36
37 /**
38  * Handle service units for external services
39  *
40  * @version $Rev: 250 $ $Date: 2006-04-21 14:20:57 +0200 (ven, 21 avr 2006) $
41  * @since Petals 1.0
42  * @author wjoseph - eBMWebsourcing
43  */

44
45 public class ExternalServiceManager extends PetalsServiceUnitHandler {
46
47     /**
48      * Default contructor, this must be implemented
49      */

50     public ExternalServiceManager() {
51         super();
52         SERVICE_UNIT_TYPE = "external_service";
53     }
54
55     /**
56      * Creates a new service unit manager
57      *
58      * @param context
59      * Component context of the callind component
60      * @param logger
61      * Logger of the calling component
62      */

63     public ExternalServiceManager(ComponentContext context, Logger JavaDoc logger) {
64         super(context, logger);
65         SERVICE_UNIT_TYPE = "external_service";
66     }
67
68     /* (non-Javadoc)
69      * @see org.objectweb.petals.component.common.serviceunitmanager.handler.PetalsServiceUnitHandler#deploy(java.lang.String, java.lang.String, java.lang.String)
70      */

71     public String JavaDoc deploy(String JavaDoc serviceUnitName, String JavaDoc serviceUnitType
72             , String JavaDoc serviceUnitRootPath) {
73         String JavaDoc result = null;
74         if (SERVICE_UNIT_TYPE.equals(serviceUnitType)) {
75             logger.log(Level.FINE, "deploy serviceUnitName "
76                     + serviceUnitName + "serviceUnitRootPath" + serviceUnitRootPath);
77             result = ManagementMessageUtil.getComponentTaskResult(context
78                     .getComponentName(), "deploy",
79                     ManagementMessageUtil.TASK_RESULT_SUCCESS);
80         }
81         return result;
82     }
83
84     public void init(String JavaDoc serviceUnitName, String JavaDoc serviceUnitRootPath)
85         throws DeploymentException {
86
87         logger.log(Level.FINE, "init serviceUnitName " + serviceUnitName
88                 + " serviceUnitRootPath " + serviceUnitRootPath);
89         
90         if(serviceUnitInstallationRootPath.put(serviceUnitName, serviceUnitRootPath) != null){
91             logger.log(Level.SEVERE,ERROR_DUPLICATE_SERVICE_UNIT);
92             throw new DeploymentException(ERROR_DUPLICATE_SERVICE_UNIT);
93         }
94     }
95
96     protected Document JavaDoc getServiceUnitWSDL(String JavaDoc suRootPath) {
97         Document JavaDoc result = null;
98         File JavaDoc[] files = new File JavaDoc(suRootPath).listFiles();
99         for (File JavaDoc file : files) {
100             if (file.getName().endsWith(".wsdl")) {
101                 result = WSDLHelper.createDocumentFromWSDL(file);
102                 break;
103             }
104         }
105         return result;
106     }
107     
108     public void shutDown(String JavaDoc serviceUnitName,
109             PetalsServiceUnitManager epHandler) throws DeploymentException {
110         logger.log(Level.FINE, "shutdown serviceUnitName " + serviceUnitName);
111     }
112
113     public void start(String JavaDoc serviceUnitName, PetalsServiceUnitManager epHandler)
114         throws DeploymentException {
115         logger.log(Level.FINE, "start serviceUnitName " + serviceUnitName);
116         String JavaDoc suRootPath = serviceUnitInstallationRootPath.get(serviceUnitName);
117         Document JavaDoc serviceDesc = getServiceUnitWSDL(suRootPath);
118         if (serviceDesc != null) {
119             try {
120                 activateEndpointsFromJBIDescription(epHandler, serviceDesc,
121                         serviceUnitName,suRootPath);
122             } catch (Exception JavaDoc ex) {
123                 logger.log(Level.SEVERE, FAILED_ACTIVATE_ENDPOINT + ex);
124                 throw new DeploymentException(FAILED_ACTIVATE_ENDPOINT, ex);
125             }
126         } else {
127             throw new DeploymentException(INCOMPLETE_SERVICE_UNIT_PACKAGE);
128         }
129     }
130
131     public void stop(String JavaDoc serviceUnitName, PetalsServiceUnitManager epHandler)
132         throws DeploymentException {
133         try {
134             serviceUnitInstallationRootPath.remove(serviceUnitName);
135             deactivateEndpointsFromJBIDescription(serviceUnitName, epHandler);
136         } catch (Exception JavaDoc e) {
137             throw new DeploymentException(FAILED_DEACTIVATE_ENDPOINT,e);
138         }
139         logger.log(Level.FINE, "stop serviceUnitName " + serviceUnitName);
140     }
141
142     public String JavaDoc undeploy(String JavaDoc serviceUnitName, String JavaDoc serviceUnitRootPath)
143         throws DeploymentException {
144         return ManagementMessageUtil.getComponentTaskResult(context
145                 .getComponentName(), "undeploy",
146                 ManagementMessageUtil.TASK_RESULT_SUCCESS);
147     }
148
149 }
150
Popular Tags