KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_lib > deployment > api > JndiEnvRefsGroupDesc


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 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  * Initial developer(s): Philippe Coq
22  * --------------------------------------------------------------------------
23  * $Id: JndiEnvRefsGroupDesc.java,v 1.13 2004/12/08 13:36:20 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_lib.deployment.api;
28
29 // import java
30
import java.util.HashMap JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.Set JavaDoc;
35 import java.util.Vector JavaDoc;
36
37 import org.objectweb.jonas_lib.deployment.xml.EjbLocalRef;
38 import org.objectweb.jonas_lib.deployment.xml.EjbRef;
39 import org.objectweb.jonas_lib.deployment.xml.EnvEntry;
40 import org.objectweb.jonas_lib.deployment.xml.JndiEnvRefsGroupXml;
41 import org.objectweb.jonas_lib.deployment.xml.JonasEjbRef;
42 import org.objectweb.jonas_lib.deployment.xml.JonasJndiEnvRefsGroupXml;
43 import org.objectweb.jonas_lib.deployment.xml.JonasMessageDestinationRef;
44 import org.objectweb.jonas_lib.deployment.xml.JonasResource;
45 import org.objectweb.jonas_lib.deployment.xml.JonasResourceEnv;
46 import org.objectweb.jonas_lib.deployment.xml.JonasServiceRef;
47 import org.objectweb.jonas_lib.deployment.xml.MessageDestinationRef;
48 import org.objectweb.jonas_lib.deployment.xml.ResourceEnvRef;
49 import org.objectweb.jonas_lib.deployment.xml.ResourceRef;
50 import org.objectweb.jonas_lib.deployment.xml.ServiceRef;
51
52 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
53 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException;
54
55 import org.objectweb.jonas.common.Log;
56
57 import org.objectweb.util.monolog.api.BasicLevel;
58 import org.objectweb.util.monolog.api.Logger;
59
60 /**
61  * This class is used to keep the usage of containedJNDI environment
62  * regerence elements consistent across J2EE deployment descriptors
63  * Elements are "env-entry", "ejb-ref", "ejb-local-ref", "resource-ref",
64  * "resource-env-ref, "service-ref", "message-destination-ref"
65  * This class extends DescriptionGroupDesc and give access to elements
66  * "description", "display-name", "icon"
67  * used by entity, session, message-driven-bean, web-app, clientApp
68  *
69  * @author Philippe Coq
70  *
71  */

72
73 public abstract class JndiEnvRefsGroupDesc extends DescriptionGroupDesc implements JndiEnvRefsGroup {
74
75     /**
76      * List of resource env ref Descriptors.
77      */

78     private Vector JavaDoc resourceEnvRefs = new Vector JavaDoc();
79
80     /**
81      * List of resource ref Descriptors..
82      */

83     private Vector JavaDoc resourceRefs = new Vector JavaDoc();
84
85     /**
86      * List of env-entry Descriptors.
87      */

88     private Vector JavaDoc envEntries = new Vector JavaDoc();
89
90     /**
91      * List of service-ref Descriptors.
92      */

93     private Vector JavaDoc serviceRefs = new Vector JavaDoc();
94
95     /**
96      * List of EJB ref Descriptors..
97      */

98     private Vector JavaDoc ejbRefs = new Vector JavaDoc();
99
100     /**
101      * List of local EJB ref Descriptors..
102      */

103     private Vector JavaDoc ejbLocalRefs = new Vector JavaDoc();
104
105     /**
106      * List of message destination ref Descriptors..
107      */

108     private Vector JavaDoc messageDestinationRefs = new Vector JavaDoc();
109
110     /**
111      * logger
112      */

113     private static Logger logger = Log.getLogger(Log.JONAS_WS_PREFIX);
114
115     /**
116      * Construct an instance of a JndiEnvRefsGroupDesc. <BR>
117      *
118      * @param classLoader the classloader for the deployed module.
119      * @param app the data structure of the J2EE application
120      * @param jonasApp the data structure of the jonas specific deployment
121      * descriptor
122      * @param fileName the file name of the module (useful only for service-ref)
123      * @throws DeploymentDescException if the deployment descriptors are
124      * corrupted.
125      */

126     protected JndiEnvRefsGroupDesc(ClassLoader JavaDoc classLoader,
127                                    JndiEnvRefsGroupXml app,
128                                    JonasJndiEnvRefsGroupXml jonasApp,
129                                    String JavaDoc fileName)
130       throws DeploymentDescException {
131
132         // test classloader
133
if (classLoader == null) {
134             throw new DeploymentDescException("Classloader is null");
135         }
136         // display name
137
displayName = null;
138         if (app.getDisplayName() != null) {
139             displayName = app.getDisplayName();
140         }
141
142         // resource-env-ref
143
processResourceEnvRef(classLoader, app, jonasApp);
144
145         // resource-ref
146
processResourceRef(classLoader, app, jonasApp);
147
148         // env-entry
149
processEnvEntry(app);
150
151         // ejb-ref
152
processEjbRef(app, jonasApp);
153
154         // ejb-local-ref
155
processEjbLocalRef(app);
156
157         // service-ref
158
processServiceRef(classLoader, app, jonasApp, fileName);
159
160         // message-destination-ref
161
processMessageDestinationRef(app, jonasApp);
162
163
164     }
165
166     /**
167      * @param app the data structure of the J2EE application
168      * @throws DeploymentDescException if the deployment descriptors are
169      * corrupted.
170      */

171     private void processEnvEntry(JndiEnvRefsGroupXml app) throws DeploymentDescException {
172         // env-entry
173
for (Iterator JavaDoc i = app.getEnvEntryList().iterator(); i.hasNext();) {
174             EnvEntryDesc envEntryDesc = new EnvEntryDesc((EnvEntry) i.next());
175             envEntries.addElement(envEntryDesc);
176         }
177     }
178
179     /**
180      * @param app the data structure of the J2EE application
181      * @param jonasApp the data structure of the jonas specific deployment
182      * descriptor
183      * @throws DeploymentDescException if the deployment descriptors are
184      * corrupted.
185      */

186     private void processMessageDestinationRef(JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp) throws DeploymentDescException {
187         List JavaDoc messageDestinationRefList = app.getMessageDestinationRefList();
188         List JavaDoc jonasMessageDestinationRefList = jonasApp.getJonasMessageDestinationRefList();
189
190
191         HashMap JavaDoc messageDestinationRef = new HashMap JavaDoc();
192         for (Iterator JavaDoc i = jonasMessageDestinationRefList.iterator(); i.hasNext();) {
193             JonasMessageDestinationRef jonasMessageDestinationRef = (JonasMessageDestinationRef) i.next();
194             String JavaDoc mdrName = jonasMessageDestinationRef.getMessageDestinationRefName();
195             boolean findMDRef = false;
196             for (Iterator JavaDoc j = messageDestinationRefList.iterator(); j.hasNext() && !findMDRef;) {
197                 MessageDestinationRef mdRef = (MessageDestinationRef) j.next();
198                 if (mdrName.equals(mdRef.getMessageDestinationRefName())) {
199                     findMDRef = true;
200                 }
201             }
202             if (!findMDRef) {
203                 throw new DeploymentDescException("message-destination-ref missing for jonas-message-destination-ref " + mdrName);
204             }
205             messageDestinationRef.put(mdrName, jonasMessageDestinationRef);
206         }
207         for (Iterator JavaDoc i = messageDestinationRefList.iterator(); i.hasNext();) {
208             MessageDestinationRef mdRef = (MessageDestinationRef) i.next();
209             String JavaDoc mdrName = mdRef.getMessageDestinationRefName();
210             JonasMessageDestinationRef jonasMessageDestinationRef = (JonasMessageDestinationRef) messageDestinationRef.get(mdrName);
211             if (jonasMessageDestinationRef == null) {
212                 // The message-destination-link must be specified when there is no jonas-message-destination-ref
213
if ((mdRef.getMessageDestinationLink() == null)) {
214                     // Ignore the message-destination-link syntax "product.jar#ProductMD"
215
throw new DeploymentDescException("message-destination-link missing for message-destination-ref-name " + mdrName);
216                 } }
217             messageDestinationRefs.addElement(new MessageDestinationRefDesc(mdRef, jonasMessageDestinationRef));
218         }
219     }
220
221     /**
222      * @param classLoader the classloader for the deployed module.
223      * @param app the data structure of the J2EE application
224      * @param jonasApp the data structure of the jonas specific deployment
225      * descriptor
226      * @param fileName the file name of the module (useful only for service-ref)
227      * @throws WSDeploymentDescException if the deployment descriptors are
228      * corrupted.
229      */

230     private void processServiceRef(ClassLoader JavaDoc classLoader, JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp, String JavaDoc fileName) throws WSDeploymentDescException {
231         Map JavaDoc links = linksSR2JSR(app, jonasApp);
232         List JavaDoc serviceRefList = app.getServiceRefList();
233         for (Iterator JavaDoc i = serviceRefList.iterator(); i.hasNext();) {
234             ServiceRef serviceRef = ((ServiceRef) i.next());
235             JonasServiceRef jsr = (JonasServiceRef) links.get(serviceRef.getServiceRefName());
236             serviceRefs.addElement(new ServiceRefDesc(classLoader, serviceRef, jsr, fileName));
237         }
238     }
239
240     /**
241      * @param app the data structure of the J2EE application
242      * @throws DeploymentDescException if the deployment descriptors are
243      * corrupted.
244      */

245     private void processEjbLocalRef(JndiEnvRefsGroupXml app) throws DeploymentDescException {
246         List JavaDoc ejbLocalRefList = app.getEjbLocalRefList();
247         for (Iterator JavaDoc i = ejbLocalRefList.iterator(); i.hasNext();) {
248             EjbLocalRef ejbLocalRef = (EjbLocalRef) i.next();
249             if ((ejbLocalRef.getEjbLink() == null)) {
250                 throw new DeploymentDescException("ejb-link missing for ejb-ref-name " + ejbLocalRef.getEjbRefName());
251             }
252             ejbLocalRefs.addElement(new EjbLocalRefDesc(ejbLocalRef));
253         }
254     }
255
256     /**
257      * @param app the data structure of the J2EE application
258      * @param jonasApp the data structure of the jonas specific deployment
259      * descriptor
260      * @throws DeploymentDescException if the deployment descriptors are
261      * corrupted.
262      */

263     private void processEjbRef(JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp) throws DeploymentDescException {
264         List JavaDoc ejbRefList = app.getEjbRefList();
265         List JavaDoc jonasEjbRefList = jonasApp.getJonasEjbRefList();
266
267         HashMap JavaDoc ejbRef = new HashMap JavaDoc();
268         for (Iterator JavaDoc i = jonasEjbRefList.iterator(); i.hasNext();) {
269             JonasEjbRef jonasEjbRef = (JonasEjbRef) i.next();
270             String JavaDoc brName = jonasEjbRef.getEjbRefName();
271             boolean findBRef = false;
272             for (Iterator JavaDoc j = ejbRefList.iterator(); j.hasNext() && !findBRef;) {
273                 EjbRef eRef = (EjbRef) j.next();
274                 if (brName.equals(eRef.getEjbRefName())) {
275                     findBRef = true;
276                 }
277             }
278             if (!findBRef) {
279                 throw new DeploymentDescException("ejb-ref missing for jonas-ejb-ref " + brName);
280             }
281             ejbRef.put(brName, jonasEjbRef);
282         }
283         for (Iterator JavaDoc i = ejbRefList.iterator(); i.hasNext();) {
284             EjbRef eRef = (EjbRef) i.next();
285             String JavaDoc brName = eRef.getEjbRefName();
286             JonasEjbRef jonasEjbRef = (JonasEjbRef) ejbRef.get(brName);
287             if (jonasEjbRef == null) {
288                 // The ejb-link must be specified when there is no jonas-ejb-ref
289
if ((eRef.getEjbLink() == null)) {
290                     // Ignore the ejb-link syntax "product.jar#ProductEJB"
291
throw new DeploymentDescException("ejb-link missing for ejb-ref-name " + brName);
292                 }
293             }
294             ejbRefs.addElement(new EjbRefDesc(eRef, jonasEjbRef));
295         }
296     }
297
298     /**
299      * @param classLoader the classloader for the deployed module.
300      * @param app the data structure of the J2EE application
301      * @param jonasApp the data structure of the jonas specific deployment
302      * descriptor
303      * @throws DeploymentDescException if the deployment descriptors are
304      * corrupted.
305      */

306     private void processResourceRef(ClassLoader JavaDoc classLoader, JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp) throws DeploymentDescException {
307         List JavaDoc resourceRefList = app.getResourceRefList();
308         List JavaDoc jonasResourceList = jonasApp.getJonasResourceList();
309         HashMap JavaDoc resource = new HashMap JavaDoc();
310         for (Iterator JavaDoc i = jonasResourceList.iterator(); i.hasNext();) {
311             JonasResource jonasResource = ((JonasResource) i.next());
312             String JavaDoc rName = jonasResource.getResRefName();
313             boolean findResRef = false;
314             for (Iterator JavaDoc j = resourceRefList.iterator(); j.hasNext() && !findResRef;) {
315                 if (rName.equals(((ResourceRef) j.next()).getResRefName())) {
316                     findResRef = true;
317                 }
318             }
319             if (!findResRef) {
320                 throw new DeploymentDescException("resource-ref missing for jonas-resource " + rName);
321             }
322             resource.put(rName, jonasResource);
323         }
324
325         for (Iterator JavaDoc i = resourceRefList.iterator(); i.hasNext();) {
326             ResourceRef resourceRef = ((ResourceRef) i.next());
327             String JavaDoc rName = resourceRef.getResRefName();
328             if (!resource.containsKey(rName)) {
329                 throw new DeploymentDescException("jonas-resource missing for res-ref-name " + rName);
330             }
331             resourceRefs.addElement(new ResourceRefDesc(classLoader, resourceRef, (JonasResource) resource.get(rName)));
332         }
333     }
334
335     /**
336      * @param classLoader the classloader for the deployed module.
337      * @param app the data structure of the J2EE application
338      * @param jonasApp the data structure of the jonas specific deployment
339      * descriptor
340      * @throws DeploymentDescException if the deployment descriptors are
341      * corrupted.
342      */

343     private void processResourceEnvRef(ClassLoader JavaDoc classLoader, JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp) throws DeploymentDescException {
344         List JavaDoc resourceEnvRefList = app.getResourceEnvRefList();
345         List JavaDoc jonasResourceEnvList = jonasApp.getJonasResourceEnvList();
346         HashMap JavaDoc resourceEnv = new HashMap JavaDoc();
347         for (Iterator JavaDoc i = jonasResourceEnvList.iterator(); i.hasNext();) {
348             JonasResourceEnv jonasResourceEnv = (JonasResourceEnv) i.next();
349             String JavaDoc rName = jonasResourceEnv.getResourceEnvRefName();
350             boolean findResRef = false;
351             for (Iterator JavaDoc j = resourceEnvRefList.iterator(); j.hasNext() && !findResRef;) {
352                 ResourceEnvRef resourceEnvRef = (ResourceEnvRef) j.next();
353                 if (rName.equals(resourceEnvRef.getResourceEnvRefName())) {
354                     findResRef = true;
355                 }
356             }
357             if (!findResRef) {
358                 throw new DeploymentDescException("resource-env-ref missing for jonas-resource-env " + rName);
359             }
360             resourceEnv.put(rName, jonasResourceEnv);
361         }
362         for (Iterator JavaDoc i = resourceEnvRefList.iterator(); i.hasNext();) {
363             ResourceEnvRef resourceEnvRef = (ResourceEnvRef) i.next();
364             String JavaDoc rName = resourceEnvRef.getResourceEnvRefName();
365             if (!resourceEnv.containsKey(rName)) {
366                 throw new DeploymentDescException("jonas-resource-env missing for resource-env-ref-name " + rName);
367             }
368             resourceEnvRefs.addElement(new ResourceEnvRefDesc(classLoader, resourceEnvRef,
369                     (JonasResourceEnv) resourceEnv.get(rName)));
370         }
371     }
372
373     /**
374      * @param app JndiEnvRefsGroupXml instance
375      * @param jonasApp linked JonasJndiEnvRefsGroupXml instance
376      * @return Returns a map associating the ServiceRef.name with the JonasServiceRef
377      */

378     private Map JavaDoc linksSR2JSR(JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp) {
379         Map JavaDoc res = new HashMap JavaDoc();
380         // for each sr
381
for (Iterator JavaDoc i = app.getServiceRefList().iterator(); i.hasNext();) {
382             ServiceRef sr = (ServiceRef) i.next();
383             res.put(sr.getServiceRefName(), null);
384         }
385         // jonas-<desc>.xml
386
if (jonasApp != null) {
387
388             // get all ServiceRef.name
389
Set JavaDoc keys = res.keySet();
390
391             // for each jonas service ref
392
for (Iterator JavaDoc i = jonasApp.getJonasServiceRefList().iterator(); i.hasNext();) {
393                 JonasServiceRef jsr = (JonasServiceRef) i.next();
394                 String JavaDoc srName = jsr.getServiceRefName();
395
396                 if (keys.contains(srName)) {
397                     // jonas-service-ref linked to service-ref
398
res.put(srName, jsr);
399                 } else {
400                     String JavaDoc err = "jonas-service-ref '" + srName + "' is not linked to any service-ref. It will be ignored."; //getI18n().getMessage("WSDeploymentDesc.wsdlDeclareUnknownPort", wsdlf.getName());
401
logger.log(BasicLevel.WARN, err);
402                 }
403             }
404         }
405         return res;
406     }
407
408     /**
409      * Get resource environment references.
410      *
411      * @return array of resource environment reference descriptors
412      */

413     public ResourceEnvRefDesc[] getResourceEnvRefDesc() {
414         ResourceEnvRefDesc[] ret = new ResourceEnvRefDesc[resourceEnvRefs.size()];
415         resourceEnvRefs.copyInto(ret);
416         return ret;
417     }
418
419     /**
420      * Get resource manager connection factory references.
421      *
422      * @return array of resource reference descriptors
423      */

424     public ResourceRefDesc[] getResourceRefDesc() {
425         ResourceRefDesc[] ret = new ResourceRefDesc[resourceRefs.size()];
426         resourceRefs.copyInto(ret);
427         return ret;
428     }
429
430     /**
431      * Get environment entries.
432      *
433      * @return array of Env entries descriptors
434      */

435     public EnvEntryDesc[] getEnvEntryDesc() {
436         EnvEntryDesc[] ret = new EnvEntryDesc[envEntries.size()];
437         envEntries.copyInto(ret);
438         return ret;
439     }
440
441     /**
442      * Get EJB references.
443      *
444      * @return array of EJB reference descriptors
445      */

446     public EjbRefDesc[] getEjbRefDesc() {
447         EjbRefDesc[] ret = new EjbRefDesc[ejbRefs.size()];
448         ejbRefs.copyInto(ret);
449         return ret;
450     }
451
452     /**
453      * Get ejb local references.
454      *
455      * @return array of ejb local reference descriptors
456      */

457     public EjbLocalRefDesc[] getEjbLocalRefDesc() {
458         EjbLocalRefDesc[] ret = new EjbLocalRefDesc[ejbLocalRefs.size()];
459         ejbLocalRefs.copyInto(ret);
460         return ret;
461     }
462
463     /**
464      * Get service references.
465      *
466      * @return array of service references descriptors
467      */

468     public ServiceRefDesc[] getServiceRefDesc() {
469         ServiceRefDesc[] ret = new ServiceRefDesc[serviceRefs.size()];
470         serviceRefs.copyInto(ret);
471         return ret;
472     }
473
474     /**
475      * Get message-destination references.
476      * @return array of message-destination references descriptors
477      */

478     public MessageDestinationRefDesc[] getMessageDestinationRefDesc() {
479         MessageDestinationRefDesc[] ret = new MessageDestinationRefDesc[messageDestinationRefs.size()];
480         messageDestinationRefs.copyInto(ret);
481         return ret;
482     }
483 }
484
Popular Tags