KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > engine > forward > PropertiesServiceUnitManager


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: Csv.java 1216 2006-11-14 18:27:09Z dutoo $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.engine.forward;
23
24 import java.io.File JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Properties JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29
30 import javax.jbi.component.ComponentContext;
31 import javax.jbi.management.DeploymentException;
32 import javax.xml.namespace.QName JavaDoc;
33
34 import org.objectweb.petals.component.common.basic.AbstractServiceUnitManager;
35 import org.objectweb.petals.component.common.util.ManagementMessageUtil;
36 import org.objectweb.petals.component.common.util.WSDLHelper;
37 import org.w3c.dom.Document JavaDoc;
38 import org.w3c.dom.Node JavaDoc;
39
40
41 /**
42  * Represents a PropertiesServiceUnitManager.
43  * This SU Manager gathers service-level "extension properties"
44  * (as defined in component-common 1.0.1) and makes them available
45  * as Properties to the component's message processor(s).
46  *
47  * NB. services are identified by their full exact qualified name, meaning
48  * a missing slash will make it fail.
49  *
50  * @version $Rev: 250 $Date: {date}
51  * @since Petals 1.0
52  * @author Marc Dutoo - Open Wide
53  *
54  */

55 public class PropertiesServiceUnitManager extends AbstractServiceUnitManager {
56
57     private Map JavaDoc<QName JavaDoc, Properties JavaDoc> serviceToPropertiesMap;
58
59     /**
60      * Creates a new PropertiesServiceUnitManager that will put all extensions
61      * in the given service QName to properties map.
62      * NB. services are identified by their full exact qualified name, meaning
63      * a missing slash will make it fail.
64      * @param context
65      * @param logger
66      * @param serviceToPropertiesMap
67      * @throws DeploymentException
68      */

69     public PropertiesServiceUnitManager(ComponentContext context, Logger JavaDoc logger,
70         Map JavaDoc<QName JavaDoc,Properties JavaDoc> serviceToPropertiesMap) throws DeploymentException {
71         super(context, logger);
72         this.serviceToPropertiesMap = serviceToPropertiesMap;
73     }
74
75     /**
76      * (non-Javadoc)
77      *
78      * @see javax.jbi.component.ServiceUnitManager#start(java.lang.String)
79      *
80      * Endpoints are activated here
81      */

82     public void start(String JavaDoc serviceUnitName) throws DeploymentException {
83         logger.log(Level.FINE, "start serviceUnitName " + serviceUnitName);
84         String JavaDoc suRootPath = serviceUnitInstallationRootPath
85                 .get(serviceUnitName);
86         Document JavaDoc serviceDesc = getServiceUnitWSDL(suRootPath);
87         if (serviceDesc != null) {
88             try {
89                 activateEndpointsFromJBIDescription(serviceDesc,
90                         serviceUnitName, suRootPath);
91
92                 // starting extensions
93
File JavaDoc jbiXmlFile = new File JavaDoc(suRootPath + File.separator
94                         + "META-INF" + File.separator + "jbi.xml");
95                 Node JavaDoc servicesNode = getNode(jbiXmlFile, "services");
96                 Map JavaDoc<String JavaDoc, String JavaDoc> extensions = getExtensions(servicesNode);
97                 start(serviceUnitName, suRootPath, serviceDesc, extensions);
98             } catch (Exception JavaDoc ex) {
99                 logger.log(Level.SEVERE, FAILED_ACTIVATE_ENDPOINT + ex);
100                 throw new DeploymentException(FAILED_ACTIVATE_ENDPOINT, ex);
101             }
102         } else {
103             throw new DeploymentException(INCOMPLETE_SERVICE_UNIT_PACKAGE);
104         }
105     }
106
107     /**
108      * Here is the core implementation of the Properties SU Manager.
109      * This method puts all extension properties that have been found
110      * during the deploy phase in a service-wide Properties instance.
111      * These properties may be accessed by the component that was the
112      * creator of this Properties SU Manager.
113      * @param serviceUnitName
114      * @param serviceUnitRootPath
115      * @param serviceDesc
116      * @param extensionMap
117      * @throws Exception
118      */

119     protected void start(String JavaDoc serviceUnitName, String JavaDoc serviceUnitRootPath,
120         Document JavaDoc serviceDesc, Map JavaDoc<String JavaDoc, String JavaDoc> extensionMap) throws Exception JavaDoc {
121         // Now making extensions available as service properties
122
Properties JavaDoc serviceProps = new Properties JavaDoc();
123         serviceProps.putAll(extensionMap);
124         QName JavaDoc service = WSDLHelper.getServiceNameFromWSDLDocument(serviceDesc)[0];
125         serviceToPropertiesMap.put(service, serviceProps);
126     }
127     
128
129     /**
130      * (non-Javadoc)
131      *
132      * @see javax.jbi.component.ServiceUnitManager#stop(java.lang.String)
133      *
134      * Endpoints are deactivated here
135      */

136     public void stop(String JavaDoc serviceUnitName) throws DeploymentException {
137         try {
138             serviceUnitInstallationRootPath.remove(serviceUnitName);
139             deactivateEndpointsFromJBIDescription(serviceUnitName);
140         } catch (Exception JavaDoc e) {
141             throw new DeploymentException(FAILED_DEACTIVATE_ENDPOINT, e);
142         }
143         logger.log(Level.FINE, "stop serviceUnitName " + serviceUnitName);
144     }
145
146     /**
147      * (non-Javadoc)
148      *
149      * @see javax.jbi.component.ServiceUnitManager#undeploy(java.lang.String,
150      * java.lang.String)
151      */

152     public String JavaDoc undeploy(String JavaDoc serviceUnitName, String JavaDoc serviceUnitRootPath)
153         throws DeploymentException {
154         return ManagementMessageUtil.getComponentTaskResult(context
155                 .getComponentName(), "undeploy",
156                 ManagementMessageUtil.TASK_RESULT_SUCCESS);
157     }
158
159     /**
160      * Deploy a service unit. Actually simply gets extension
161      * properties (as defined in component-common 1.0.1) and
162      * let subclasses use them by calling deploy(service, extension).
163      * NB. This is an override of the orginal one that adds
164      * the service being configured to the context of the call.
165      *
166      * @param serviceUnitName
167      * name of the service unit to deploy
168      * @param serviceUnitRootPath
169      * root path of the service unit to deploy
170      * @return a valid management message
171      * @throws DeploymentException
172      * If an error occurs during deployment
173      */

174     public String JavaDoc deploy(String JavaDoc serviceUnitName, String JavaDoc serviceUnitRootPath)
175         throws DeploymentException {
176         String JavaDoc result = null;
177         if (serviceUnitMap.get(serviceUnitName) == null) {
178             // deploying extensions
179
File JavaDoc jbiXmlFile = new File JavaDoc(serviceUnitRootPath + File.separator
180                     + "META-INF" + File.separator + "jbi.xml");
181             Node JavaDoc servicesNode = getNode(jbiXmlFile, "services");
182             Map JavaDoc<String JavaDoc, String JavaDoc> extensions = getExtensions(servicesNode);
183             deploy(serviceUnitName, serviceUnitRootPath, extensions);
184             
185             logger.log(Level.FINE, "deploy serviceUnitName "
186                     + serviceUnitName + "serviceUnitRootPath"
187                     + serviceUnitRootPath);
188             result = ManagementMessageUtil.getComponentTaskResult(context
189                     .getComponentName(), "deploy",
190                     ManagementMessageUtil.TASK_RESULT_SUCCESS);
191         } else {
192             throw new DeploymentException(ERROR_DUPLICATE_SERVICE_UNIT);
193         }
194         return result;
195     }
196
197     protected void deploy(String JavaDoc serviceUnitName, String JavaDoc serviceUnitRootPath,
198         Map JavaDoc<String JavaDoc, String JavaDoc> arg0) {
199         // NB. not used here
200
}
201
202     @Override JavaDoc
203     protected void deploy(Map JavaDoc<String JavaDoc, String JavaDoc> arg0) {
204         // TODO remove from the API of AbstractServiceUnitManager
205
}
206
207 }
208
Popular Tags