KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > deployment > api > WSDeploymentDesc


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: WSDeploymentDesc.java,v 1.13 2004/09/10 11:49:05 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ws.deployment.api;
27
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.Vector JavaDoc;
34
35 import org.objectweb.jonas_lib.I18n;
36 import org.objectweb.jonas_lib.deployment.api.AbsDeploymentDesc;
37
38 import org.objectweb.jonas_ws.deployment.xml.JonasWebserviceDescription;
39 import org.objectweb.jonas_ws.deployment.xml.JonasWebservices;
40 import org.objectweb.jonas_ws.deployment.xml.WebserviceDescription;
41 import org.objectweb.jonas_ws.deployment.xml.Webservices;
42
43 import org.objectweb.util.monolog.api.BasicLevel;
44 import org.objectweb.util.monolog.api.Logger;
45
46 /**
47  * This Classes is a data structure that encapsulate informations contained in
48  * <code>webservices.xml</code> deployment descriptor. It provides methods to
49  * manipulate these informations.
50  * @author Guillaume Sauthier
51  * @author Xavier Delplanque
52  * @author Helene Joanin
53  */

54 public class WSDeploymentDesc extends AbsDeploymentDesc {
55
56     /** The list of ServiceDesc described in webservices.xml */
57     private Vector JavaDoc services = new Vector JavaDoc();
58
59     /** The Webservices display name */
60     private String JavaDoc displayName;
61
62     /** The WebApp dispatching SOAP request to the PortComponents */
63     private String JavaDoc warFile = null;
64
65     /** The Webservices logger */
66     private Logger logger;
67
68     /**
69      * Internationalization
70      */

71     private static I18n i18n = I18n.getInstance(WSDeploymentDesc.class);
72
73     /**
74      * ContextRoot for this group of WebServices
75      */

76     private String JavaDoc contextRoot = null;
77
78     /**
79      * Constructor : creates a WSDeploymentDesc object
80      * @param jarCL module (war or ejbjar) class loader.
81      * @param log the logger to use.
82      * @param ws Zeus object containing webservices informations
83      * @param jws Zeus object containing jonas-webservices informations
84      * @throws WSDeploymentDescException if in the Webservices file : - each
85      * service haven't got an unique name. - each port component haven't
86      * got an unique name. - each handler haven't got an unique name. -
87      * wsdl ports aren't inclued in portComponents.
88      */

89     public WSDeploymentDesc(ClassLoader JavaDoc jarCL, Logger log, Webservices ws, JonasWebservices jws)
90             throws WSDeploymentDescException {
91         this.logger = log;
92
93         // set displayName
94
displayName = ws.getDisplayName();
95
96         // Store the WebApp filename
97
if (jws != null) {
98             if (jws.getWar() != null) {
99                 warFile = jws.getWar();
100             }
101             // set contextRoot
102
String JavaDoc ctx = jws.getContextRoot();
103             if (ctx != null && !"".equals(ctx)) {
104                 contextRoot = ctx;
105             }
106
107         }
108
109         // set services
110
List JavaDoc wdl = ws.getWebserviceDescriptionList();
111         Map JavaDoc links = associateWDAndJWD(ws, jws);
112
113         for (int i = 0; i < wdl.size(); i++) {
114             WebserviceDescription wd = (WebserviceDescription) wdl.get(i);
115             JonasWebserviceDescription jwd = (JonasWebserviceDescription) links.get(wd.getWebserviceDescriptionName());
116             services.add(new ServiceDesc(jarCL, wd, jwd));
117         }
118
119         // validation
120
// services names are unique
121
// fill the list of service names
122
Vector JavaDoc serviceNames = new Vector JavaDoc();
123
124         for (int i = 0; i < services.size(); i++) {
125             String JavaDoc sn = ((ServiceDesc) services.get(i)).getName();
126
127             if (serviceNames.contains(sn)) {
128                 // if the service name is already contained, it isn't unique
129
String JavaDoc err = getI18n().getMessage("WSDeploymentDesc.serviceNameNotUnique", sn); //$NON-NLS-1$
130
logger.log(BasicLevel.ERROR, err);
131                 throw new WSDeploymentDescException(err);
132             }
133
134             serviceNames.add(sn);
135         }
136
137         // port components names are unique
138
// fill the list of port component names
139
Vector JavaDoc pcNames = new Vector JavaDoc();
140
141         for (int i = 0; i < services.size(); i++) {
142             ServiceDesc s = (ServiceDesc) services.get(i);
143             List JavaDoc pcl = s.getPortComponents();
144
145             for (int j = 0; j < pcl.size(); j++) {
146                 PortComponentDesc pcd = (PortComponentDesc) pcl.get(j);
147                 String JavaDoc pcn = pcd.getName();
148
149                 if (pcNames.contains(pcn)) {
150                     // if the port component name is already contained, it isn't
151
// unique
152
String JavaDoc err = getI18n().getMessage("WSDeploymentDesc.portCompNameNotUnique", pcn); //$NON-NLS-1$
153
logger.log(BasicLevel.ERROR, err);
154                     throw new WSDeploymentDescException(err);
155                 }
156
157                 pcNames.add(pcn);
158             }
159         }
160
161         // verify that all wsdl ports are included inside portComponents
162
// build the list of port component QNames
163
Vector JavaDoc pcQNames = new Vector JavaDoc();
164
165         for (int i = 0; i < services.size(); i++) {
166             List JavaDoc pcl = ((ServiceDesc) services.get(i)).getPortComponents();
167
168             for (int j = 0; j < pcl.size(); j++) {
169                 PortComponentDesc pc = (PortComponentDesc) pcl.get(j);
170                 pcQNames.add(pc.getQName());
171             }
172         }
173
174         // verify for each WSDLs that port are inside pcQNames
175
for (int i = 0; i < services.size(); i++) {
176             WSDLFile wsdlf = ((ServiceDesc) services.get(i)).getWSDL();
177
178             if (!wsdlf.hasPortsIncludedIn(pcQNames)) {
179                 String JavaDoc err = getI18n().getMessage("WSDeploymentDesc.wsdlDeclareUnknownPort", wsdlf.getName()); //$NON-NLS-1$
180
logger.log(BasicLevel.ERROR, err);
181                 throw new WSDeploymentDescException(err);
182             }
183         }
184     }
185
186     /**
187      * Associate WebserviceDescription.name to JonasWebserviceDescription
188      * @param jws JonasWebservices instance
189      * @param ws Webservices instance
190      * @return Returns the JonasWebserviceDescription with the given name or null if not found.
191      */

192     private Map JavaDoc associateWDAndJWD(Webservices ws, JonasWebservices jws) {
193         Map JavaDoc res = new HashMap JavaDoc();
194         // for each wsd
195
for (Iterator JavaDoc i = ws.getWebserviceDescriptionList().iterator(); i.hasNext();) {
196             WebserviceDescription wsd = (WebserviceDescription) i.next();
197             res.put(wsd.getWebserviceDescriptionName(), null);
198         }
199         // jonas-webservices.xml
200
if (jws != null) {
201
202             // get all wsd.name
203
Set JavaDoc keys = res.keySet();
204
205             // for each jwsd
206
for (Iterator JavaDoc i = jws.getJonasWebserviceDescriptionList().iterator(); i.hasNext();) {
207                 JonasWebserviceDescription jwsd = (JonasWebserviceDescription) i.next();
208                 String JavaDoc wsdName = jwsd.getWebserviceDescriptionName();
209
210                 if (keys.contains(wsdName)) {
211                     // jonas-webservice-description linked to webservice-description
212
res.put(wsdName, jwsd);
213                 } else {
214                     String JavaDoc err = "jonas-webservice-description '" + wsdName + "' is not linked to any webservice-description. It will be ignored."; //getI18n().getMessage("WSDeploymentDesc.wsdlDeclareUnknownPort", wsdlf.getName());
215
logger.log(BasicLevel.WARN, err);
216                 }
217             }
218         }
219         return res;
220     }
221
222     /**
223      * Return the list of ServiceDesc.
224      * @return the list of ServiceDesc.
225      */

226     public List JavaDoc getServiceDescs() {
227         return services;
228     }
229
230     /**
231      * Return the Webservices displayName.
232      * @return the Webservices displayName.
233      */

234     public String JavaDoc getDisplayName() {
235         return displayName;
236     }
237
238     /**
239      * @return Returns the contextRoot.
240      */

241     public String JavaDoc getContextRoot() {
242         return contextRoot;
243     }
244
245     /**
246      * Return a String representation of the WSDeploymentDesc.
247      * @return a String representation of the WSDeploymentDesc.
248      */

249     public String JavaDoc toString() {
250         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
251
252         sb.append("\nWSDeploymentDesc :"); //$NON-NLS-1$
253
sb.append("\ngetDisplayName()=" + getDisplayName()); //$NON-NLS-1$
254

255         for (Iterator JavaDoc i = getServiceDescs().iterator(); i.hasNext();) {
256             sb.append("\ngetServiceDesc()=" + ((ServiceDesc) i.next()).toString()); //$NON-NLS-1$
257
}
258
259         sb.append("\ngetWarFile()=" + getWarFile()); //$NON-NLS-1$
260

261         return sb.toString();
262     }
263
264     /**
265      * Return the filename of the WebApp dispatching SOAP requests to the
266      * components (can be null if no filename specified in
267      * jonas-webservices.xml).
268      * @return the filename of the WebApp dispatching SOAP requests to the
269      * components.
270      */

271     public String JavaDoc getWarFile() {
272         return warFile;
273     }
274
275     /**
276      * @return Returns the i18n.
277      */

278     protected static I18n getI18n() {
279         return i18n;
280     }
281 }
Popular Tags