KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > deployment > lib > EjbDeploymentDescManager


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: EjbDeploymentDescManager.java,v 1.38 2005/04/28 16:52:59 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26
27 package org.objectweb.jonas_ejb.deployment.lib;
28
29 import java.io.File JavaDoc;
30 import java.io.FileInputStream JavaDoc;
31 import java.io.FileNotFoundException JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.io.InputStream JavaDoc;
34 import java.io.InputStreamReader JavaDoc;
35 import java.io.Reader JavaDoc;
36 import java.net.MalformedURLException JavaDoc;
37 import java.net.URL JavaDoc;
38 import java.net.URLClassLoader JavaDoc;
39 import java.util.Enumeration JavaDoc;
40 import java.util.Hashtable JavaDoc;
41 import java.util.List JavaDoc;
42 import java.util.StringTokenizer JavaDoc;
43 import java.util.Vector JavaDoc;
44 import java.util.zip.ZipEntry JavaDoc;
45 import java.util.zip.ZipFile JavaDoc;
46
47 import org.objectweb.jonas_ejb.deployment.api.BeanDesc;
48 import org.objectweb.jonas_ejb.deployment.api.DeploymentDesc;
49 import org.objectweb.jonas_ejb.deployment.api.DeploymentDescEjb1_1;
50 import org.objectweb.jonas_ejb.deployment.api.DeploymentDescEjb2;
51 import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
52 import org.objectweb.jonas_ejb.deployment.api.MessageDrivenDesc;
53 import org.objectweb.jonas_ejb.deployment.api.SessionDesc;
54 import org.objectweb.jonas_ejb.deployment.rules.EjbJarRuleSet;
55 import org.objectweb.jonas_ejb.deployment.rules.JonasEjbJarRuleSet;
56 import org.objectweb.jonas_ejb.deployment.xml.EjbJar;
57 import org.objectweb.jonas_ejb.deployment.xml.JonasEjbJar;
58 import org.objectweb.jonas_ejb.lib.BeanNaming;
59
60 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
61 import org.objectweb.jonas_lib.deployment.api.EjbLocalRefDesc;
62 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc;
63 import org.objectweb.jonas_lib.deployment.api.JndiEnvRefsGroup;
64 import org.objectweb.jonas_lib.deployment.api.MessageDestinationRefDesc;
65 import org.objectweb.jonas_lib.deployment.digester.JDigester;
66 import org.objectweb.jonas_lib.deployment.lib.AbsDeploymentDescManager;
67 import org.objectweb.jonas_lib.deployment.xml.JonasMessageDestination;
68
69 import org.objectweb.jonas_ws.deployment.api.PortComponentDesc;
70 import org.objectweb.jonas_ws.deployment.api.PortComponentRefDesc;
71 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
72 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException;
73 import org.objectweb.jonas_ws.deployment.lib.WSDeploymentDescManager;
74
75 import org.objectweb.jonas.common.Log;
76
77 import org.objectweb.util.monolog.api.BasicLevel;
78 import org.objectweb.util.monolog.api.Logger;
79
80 /**
81  * This class provide a way for managing the EjbDeploymentDesc.
82  * Note that there is an intance of the EjbDeploymentDescManager on each JOnAS
83  * server.
84  * @author Ludovic Bert
85  * @author Florent Benoit
86  * @author Nicolas Van Caneghem <nicolas.vancaneghem@openpricer.com>
87  * Allow the deployment of an exploded ear
88  * Contributors:<br>
89  * JOnAS 4.0 Adriana Danes: keep deployement descriptors is a Stringified format
90  * for management support.
91  */

92 public class EjbDeploymentDescManager extends AbsDeploymentDescManager {
93
94     /**
95      * ejb-jar.xml filename
96      */

97     public static final String JavaDoc EJB_JAR_FILE_NAME = "META-INF/ejb-jar.xml";
98
99     /**
100      * jonas-ejb-jar.xml filename
101      */

102     public static final String JavaDoc JONAS_EJB_JAR_FILE_NAME = "META-INF/jonas-ejb-jar.xml";
103
104     /**
105      * Flag for parser validation
106      */

107     private static boolean parsingWithValidation = true;
108
109     /**
110      * The unique instance of the EjbDeploymentDescManager.
111      */

112     private static EjbDeploymentDescManager unique;
113
114
115     /**
116      * Digester used to parse ejb-jar.xml
117      */

118     private static JDigester ejbjarDigester = null;
119
120     /**
121      * Digester use to parse jonas-ejb-ja.xml
122      */

123     private static JDigester jonasEjbjarDigester = null;
124
125     /**
126      * Rules to parse the application-client.xml
127      */

128     private static EjbJarRuleSet ejbjarRuleSet = new EjbJarRuleSet();
129
130     /**
131      * Rules to parse the jonas-client.xml
132      */

133     private static JonasEjbJarRuleSet jonasEjbjarRuleSet = new JonasEjbJarRuleSet();
134
135
136     /**
137      * Reference on the WSDeploymentDescManager.
138      */

139     private WSDeploymentDescManager wsDDManager = null;
140
141     /**
142      * Associates an URL of an ejb-jar to its ejb deployment descriptor.
143      * It's the cache.
144      */

145     private Hashtable JavaDoc urlJarBindings;
146
147     /**
148      * Associates an URL to an ear classloader. (ear only)
149      */

150     private Hashtable JavaDoc urlEarCLBindings;
151
152     /**
153      * Associates an URL to an ejb classloader. (ear only)
154      */

155     private Hashtable JavaDoc urlEjbCLBindings;
156
157     /**
158      * Associates an URL to an alternate DDesc file.
159      */

160     private Hashtable JavaDoc urlAltDDBindings = null;
161
162     /**
163      * Associates an ear classloader to a list of URLs. It is used to know if
164      * the ejb-link or message-destination-link is authorised. An ejb-link or
165      * mesage-destination is authorized only in the same ear.
166      */

167     private Hashtable JavaDoc earCLEjbLinkJar;
168
169     /**
170      * Logger for the deployment desc manager.
171      */

172     private static Logger logger = Log.getLogger("org.objectweb.jonas_ejb.dd");
173
174     /**
175      * cache used for WsGen (multiple calls)
176      */

177     private static Hashtable JavaDoc staticCache = new Hashtable JavaDoc();
178
179     /**
180      * Xml content of the standard deployement descriptor file
181      */

182     private static String JavaDoc xmlContent = "";
183
184     /**
185      * Xml content of the JOnAS deployement descriptor file
186      */

187     private static String JavaDoc jonasXmlContent = "";
188
189     /**
190      * Contructs a unique new EjbDeploymentDescManager.
191      */

192     private EjbDeploymentDescManager() {
193         urlJarBindings = new Hashtable JavaDoc();
194         urlEarCLBindings = new Hashtable JavaDoc();
195         urlEjbCLBindings = new Hashtable JavaDoc();
196         earCLEjbLinkJar = new Hashtable JavaDoc();
197         urlAltDDBindings = new Hashtable JavaDoc();
198     }
199
200     /**
201      * Get an instance of the EjbDeploymentDescManager.
202      * @return the instance of the EjbDeploymentDescManager.
203      */

204     public static EjbDeploymentDescManager getInstance() {
205         if (unique == null) {
206             unique = new EjbDeploymentDescManager();
207         }
208         return unique;
209     }
210
211     /**
212      * Factory method using the ejb-jar file name.
213      * Used by GenIC/GenIDL/WsGen.
214      * @param ejbjar ejbjar file name
215      * @param ejbLoader classloader used to load bean classes.
216      * @return instance of the corresponding DeploymentDesc
217      * @exception DeploymentDescException when DeploymentDesc cannot be created with
218      * given ejb-jar file.
219      */

220     public static DeploymentDesc getDeploymentDesc(String JavaDoc ejbjar, ClassLoader JavaDoc ejbLoader)
221         throws DeploymentDescException {
222         if (!staticCache.containsKey(ejbjar)) {
223             return getDeploymentDescriptor(ejbjar, ejbLoader, (String JavaDoc) null);
224         } else {
225             return (DeploymentDesc) staticCache.get(ejbjar);
226         }
227     }
228
229     /**
230      * Get the specified ejb deployment descriptor and put it in the cache
231      * if it is not in.
232      * Called by createContainer & WebDeploymentDescManager
233      * @param url the url where to load xml deployment descriptors.
234      * @param ejbLoader classloader used to load bean classes.
235      * @param earLoader the parent classloader (the ear classloader). Null if
236      * there in the case of an ejb-jar application.
237      * @return DeploymentDesc the ejb deployment descriptor. (This method is
238      * used for the ear applications).
239      * @throws DeploymentDescException when DeploymentDesc cannot be created
240      * with the given files.
241      */

242     public synchronized DeploymentDesc getDeploymentDesc(URL JavaDoc url,
243                                                          ClassLoader JavaDoc ejbLoader,
244                                                          ClassLoader JavaDoc earLoader)
245         throws DeploymentDescException {
246         // load an instance of the WebService Manager
247
if (wsDDManager == null) {
248             wsDDManager = WSDeploymentDescManager.getInstance();
249         }
250
251         // Check in the ejb-link is allowed : the ejb-link must be done
252
// on an ejb-jar defined in the ear application.
253
if (earLoader != null) {
254             checkEjbLinkAvailable(earLoader, url);
255         }
256
257         DeploymentDesc dd = (DeploymentDesc) urlJarBindings.get(url.getFile());
258         if (dd == null) {
259             // dd not in cache => load the deployment descriptor.
260
dd = loadDeploymentDesc(url, ejbLoader, earLoader);
261         }
262         return dd;
263     }
264
265     /**
266      * Get the deployment descriptor of the ejb-link of the specified url.
267      * @param currentUrl the URL of the component (web or bean)
268      * that do an ejb-link.
269      * @param urlToLoad the URL of the bean to get the deployment descriptor.
270      * @return the deployment descriptor of the specified bean.
271      * @throws DeploymentDescException when DeploymentDesc cannot be created
272      * with the given files.
273      */

274     private DeploymentDesc getDeploymentDesc(URL JavaDoc currentUrl, URL JavaDoc urlToLoad)
275         throws DeploymentDescException {
276         DeploymentDesc ejbLinkDD = (DeploymentDesc) urlJarBindings.get(urlToLoad.getFile());
277         if (ejbLinkDD == null) {
278             // ejbLinkDD not in cache => load the deployment descriptor.
279
String JavaDoc url = currentUrl.getFile();
280             URLClassLoader JavaDoc earLoader = (URLClassLoader JavaDoc) urlEarCLBindings.get(url);
281             if (new File JavaDoc(url).isFile()) {
282                 if (!url.toLowerCase().endsWith(".jar")) {
283                     String JavaDoc err = "File '" + url + "' is not a jar file";
284                     throw new DeploymentDescException(err);
285                 }
286             }
287
288             if (earLoader != null) {
289                 // In the case of an ear application.
290

291                 // Check in the ejb-link is allowed : the ejb-link must be done
292
// on an ejb-jar defined in the ear application.
293
checkEjbLinkAvailable(earLoader, urlToLoad);
294
295                 // get the loader for classes (ejb classloader).
296
URLClassLoader JavaDoc loaderForCls = (URLClassLoader JavaDoc) urlEjbCLBindings.get(url);
297
298                 // Build a default classloader
299
if (loaderForCls == null) {
300                     loaderForCls = new URLClassLoader JavaDoc(new URL JavaDoc[] {urlToLoad});
301                 }
302
303                 // get the ear classloader.
304
URLClassLoader JavaDoc loader = (URLClassLoader JavaDoc) urlEarCLBindings.get(url);
305                 ejbLinkDD = loadDeploymentDesc(urlToLoad, loaderForCls, loader);
306             } else {
307                 // In the case of a non ear application.
308
if (!currentUrl.getFile().equals(urlToLoad)) {
309                     String JavaDoc err = "In '" + url + "' ejb-link is not allowed outside the ejb-jar if you are not in an ear application.";
310                     throw new DeploymentDescException(err);
311                 }
312                 // else nothing to do.
313
}
314         }
315         return ejbLinkDD;
316     }
317
318     /**
319      * Load the specified ejb deployment descriptor and
320      * put it in cache.
321      * @param url where to load xml deployment descriptors.
322      * @param ejbLoader classloader used to load bean classes.
323      * @param earLoader the parent classloader (the ear classloader). Null when
324      * not in the case of an ear application.
325      * @return DeploymentDesc the ejb deployment descriptor.
326      * @throws DeploymentDescException when DeploymentDesc cannot be created
327      * with the given files.
328      */

329     private DeploymentDesc loadDeploymentDesc(URL JavaDoc url, ClassLoader JavaDoc ejbLoader, ClassLoader JavaDoc earLoader)
330         throws DeploymentDescException {
331         // Check if the ejb-jar exists.
332
String JavaDoc filename = url.getFile();
333         File JavaDoc f = new File JavaDoc(filename);
334         if (!f.exists()) {
335             throw new DeploymentDescException(filename + " not found");
336         }
337
338         // Get the instance of the DeploymentDesc.
339
DeploymentDesc dd = null;
340         if (f.isDirectory()) {
341             dd = getDeploymentDescriptor(filename + EJB_JAR_FILE_NAME,
342                                          BeanNaming.getJonasXmlName(filename + EJB_JAR_FILE_NAME),
343                                          ejbLoader,
344                                          f.getAbsolutePath());
345
346         } else if (filename.toLowerCase().endsWith(".xml")) {
347             // This is an XML file name: Treat it for upward compatibility
348
// f is the ejb-jar.xml file, jonas specific is colocated to this file.
349
File JavaDoc parent = f.getParentFile();
350             dd = getDeploymentDescriptor(filename,
351                                          BeanNaming.getJonasXmlName(filename),
352                                          ejbLoader,
353                                          parent.getAbsolutePath());
354         } else {
355             // This is an ejb-jar
356
// Check if there is an altenate DD for this URL (ear only)
357
String JavaDoc altname = null;
358             URL JavaDoc altDDUrl = (URL JavaDoc) urlAltDDBindings.get(url.getFile());
359             if (altDDUrl != null) {
360                 altname = altDDUrl.getFile();
361             }
362             dd = getDeploymentDescriptor(filename, ejbLoader, altname);
363         }
364
365         // Put it in the cache in case of ear.
366
if (earLoader != null) {
367             urlEjbCLBindings.put(filename, ejbLoader);
368             urlEarCLBindings.put(filename, earLoader);
369         }
370
371         BeanDesc[] bd = dd.getBeanDesc();
372         for (int j = 0; j < bd.length; j++) {
373
374             // Resolve the ejb-link for ejb-ref
375
EjbRefDesc[] ejbRef = bd[j].getEjbRefDesc();
376             for (int i = 0; i < ejbRef.length; i++) {
377                 String JavaDoc jndiName = ejbRef[i].getJndiName();
378                 String JavaDoc ejbLink = ejbRef[i].getEjbLink();
379                 String JavaDoc ejbRefType = ejbRef[i].getEjbRefType();
380                 if (ejbLink != null && jndiName == null) {
381                     String JavaDoc ejbName = getJndiName(url, ejbLink, earLoader, ejbRefType, dd, true);
382                     ejbRef[i].setJndiName(ejbName);
383                 }
384             }
385
386             // Resolve the ejb-link for ejb-local-ref
387
EjbLocalRefDesc[] ejbLocalRef = bd[j].getEjbLocalRefDesc();
388             for (int i = 0; i < ejbLocalRef.length; i++) {
389                 String JavaDoc ejblink = ejbLocalRef[i].getEjbLink();
390                 if (ejblink == null) {
391                     String JavaDoc err = "Ejb-link must be specified for ejb-local-ref " + ejbLocalRef[i].getEjbRefName();
392                     throw new DeploymentDescException(err);
393                 }
394                 String JavaDoc ejbRefType = ejbLocalRef[i].getEjbRefType();
395                 String JavaDoc ejbName = getJndiName(url, ejblink, earLoader, ejbRefType, dd, false);
396                 ejbLocalRef[i].setJndiLocalName(ejbName);
397             }
398
399             // Resolve the port-component-link for service-ref
400
ServiceRefDesc[] serviceRef = bd[j].getServiceRefDesc();
401
402             for (int i = 0; i < serviceRef.length; i++) {
403                 List JavaDoc pcRefs = serviceRef[i].getPortComponentRefs();
404
405                 for (int k = 0; k < pcRefs.size(); k++) {
406                     // for each service portComponents : resolve links
407
PortComponentRefDesc pcr = (PortComponentRefDesc) pcRefs.get(k);
408                     String JavaDoc pclink = pcr.getPortComponentLink();
409                     if (pclink != null) {
410                         // a pc link is defined, we resolve it
411
PortComponentDesc pcDesc = getPCDesc(url, pclink, ejbLoader, earLoader);
412                         pcr.setPortComponentDesc(pcDesc);
413                     }
414                 }
415             }
416
417             // Resolve the message-destination-link for message-destination-ref
418
MessageDestinationRefDesc[] mdRef = bd[j].getMessageDestinationRefDesc();
419             for (int i = 0; i < mdRef.length; i++) {
420                 String JavaDoc jndiName = mdRef[i].getJndiName();
421                 String JavaDoc mdLink = mdRef[i].getMessageDestinationLink();
422                 String JavaDoc mdType = mdRef[i].getMessageDestinationType();
423                 String JavaDoc mdUsage = mdRef[i].getMessageDestinationUsage();
424                 if (logger.isLoggable(BasicLevel.DEBUG)) {
425                     logger.log(BasicLevel.DEBUG, "" + jndiName + " " + mdLink + " " + mdType + " " + mdUsage);
426                 }
427                 if (mdLink != null && jndiName == null) {
428                     String JavaDoc mdName = getMDJndiName(url, mdLink, mdType, mdUsage, dd);
429                     mdRef[i].setJndiName(mdName);
430                 }
431             }
432
433         }
434
435         // ... and put it in cache if ear case.
436
if (earLoader != null) {
437             // case of ear application.
438
urlJarBindings.put(filename, dd);
439         }
440
441         return dd;
442     }
443
444
445     /**
446      * Return the port component desc from the pcLink string.
447      * pcLink format : filename.[jar or war]#portComponentName in the same Ear File
448      * portComponentName
449      *
450      * @param ejbjarURL the url of the ejbjar being parsed. This is needed
451      * because pcLink is relative. With the url and the pcLink, we can
452      * know where the file is located.
453      * @param pcLink the pcLink tag of an port-component-ref.
454      * @param earLoader the classloader of the ear.
455      * @param moduleLoader the classloader of the current module
456      *
457      * @return the pcLink portComponent.
458      *
459      * @throws WSDeploymentDescException when it failed
460      */

461     private PortComponentDesc getPCDesc(URL JavaDoc ejbjarURL,
462                                         String JavaDoc pcLink,
463                                         ClassLoader JavaDoc moduleLoader,
464                                         ClassLoader JavaDoc earLoader)
465         throws WSDeploymentDescException {
466
467         // now ask WS Manager for port-component-desc
468
return wsDDManager.getPortComponentDesc(ejbjarURL, pcLink, moduleLoader, earLoader);
469     }
470
471
472     /**
473      * Return the JNDI name from the ejbLink string.
474      * ejbLink format : filename.jar#beanName in the same Ear File
475      * beanName in the same ejb-jar file.
476      * @param currentFile the url of the jar being parsed. This is needed because
477      * ejbLink is relative. With the url and the ejbLink, we can know where
478      * the file is locate.
479      * @param ejbLink the ejbLink tag of an ejb-ref
480      * @param earCl optionnal classloader
481      * @param ejbType the type of the referenced ejb in the ejb-ref tag.
482      * @param deploymentDesc the deployment descriptor of the parsed deploymentDesc.
483      * @param isEjbRef true if the jndi name to resolve is an ejb-ref
484      * @return the JNDI name if found, null otherwise
485      * @throws DeploymentDescException when it failed
486      */

487     public String JavaDoc getJndiName(URL JavaDoc currentFile, String JavaDoc ejbLink, ClassLoader JavaDoc earCl, String JavaDoc ejbType,
488                                DeploymentDesc deploymentDesc, boolean isEjbRef)
489         throws DeploymentDescException {
490         // Extract from the ejb link
491
// - the name of the file
492
// - the name of the bean
493
String JavaDoc ejbJarLink = null;
494         String JavaDoc beanNameLink = null;
495
496         //Same jar ?
497
if (ejbLink.indexOf(LINK_SEPARATOR) == -1) {
498             BeanDesc bd = null;
499             //Link to a bean inside the same ejb-jar file.
500
if (earCl == null && deploymentDesc == null) {
501                     throw new DeploymentDescException("Deployment desc for file ejb-jar '" + currentFile.getFile() + "' not found");
502             }
503             // Read in its own deployment descriptor if not null
504
if (deploymentDesc != null) {
505                 bd = deploymentDesc.getBeanDesc(ejbLink);
506             }
507             String JavaDoc url = currentFile.getFile();
508             URLClassLoader JavaDoc earClassLoader = null;
509             // get the loader for classes (ejb classloader).
510
URLClassLoader JavaDoc ejbLoader = (URLClassLoader JavaDoc) urlEjbCLBindings.get(url);
511             if (earCl != null) {
512                 earClassLoader = (URLClassLoader JavaDoc) earCl;
513                 //Add it
514
urlEarCLBindings.put(url, earCl);
515             } else {
516                 earClassLoader = (URLClassLoader JavaDoc) urlEarCLBindings.get(url);
517             }
518
519             //ejb standalone case
520
if ((earClassLoader == null) && (bd == null)) {
521                 String JavaDoc err = "Ejb-link " + ejbLink + " not found inside the file " + currentFile.getFile() + ". The bean doesn't exists.";
522                 throw new DeploymentDescException(err);
523             }
524
525             // ear case, search in all ejbjars
526
if (bd == null) {
527                 if (logger.isLoggable(BasicLevel.DEBUG)) {
528                     logger.log(BasicLevel.DEBUG, "The bean '" + ejbLink + "' was not found in the current ejbjar, searching on all the ejbjars.");
529                 }
530                 Vector JavaDoc v = (Vector JavaDoc) earCLEjbLinkJar.get(earClassLoader);
531                 DeploymentDesc lookupDD = null;
532                 String JavaDoc fileName = null;
533                 URL JavaDoc urlRead = null;
534                 String JavaDoc urlReadString = null;
535                 boolean found = false;
536                 BeanDesc bdtmp = null;
537                 for (Enumeration JavaDoc e = v.elements(); e.hasMoreElements();) {
538                     urlReadString = (String JavaDoc) e.nextElement();
539                     File JavaDoc f = new File JavaDoc(urlReadString);
540                     try {
541                         urlRead = f.toURL();
542                     } catch (Exception JavaDoc ue) {
543                         throw new DeploymentDescException("Cannot make an url with the argument'" + urlReadString + "'.");
544                     }
545                     // Classloader is null ? try to get it
546
if (ejbLoader == null) {
547                         ejbLoader = (URLClassLoader JavaDoc) urlEjbCLBindings.get(urlReadString);
548                     }
549                     // if it is still null, fails
550
if (ejbLoader == null) {
551                         throw new DeploymentDescException("Error while resolving ejb-link. The ejb classloader is not found for url '" + urlReadString + "'.");
552                     }
553
554                     // Add it
555
urlEjbCLBindings.put(urlReadString, ejbLoader);
556
557                     fileName = urlRead.getFile();
558                     //do not analyse current file
559
if (!fileName.equals(url)) {
560                         //Need to load deployment desc without any resolving link
561
// Get the instance of the DeploymentDesc.
562
if (f.isDirectory()) {
563                             lookupDD = getDeploymentDescriptor(fileName + EJB_JAR_FILE_NAME,
564                                                                BeanNaming.getJonasXmlName(fileName + EJB_JAR_FILE_NAME),
565                                                                ejbLoader,
566                                                                f.getAbsolutePath());
567                         } else if (fileName.toLowerCase().endsWith(".xml")) {
568                             // This is an XML file name: Treat it for upward compatibility
569
// f is the ejb-jar.xml file, first paretn is the META-INF directory, and second parent is the root directory of the module
570
File JavaDoc parent = f.getParentFile().getParentFile();
571                             lookupDD = getDeploymentDescriptor(fileName,
572                                                                BeanNaming.getJonasXmlName(fileName),
573                                                                ejbLoader,
574                                                                parent.getAbsolutePath());
575                         } else {
576                             // This is an ejb-jar
577
// Check if there is an altenate DD for this URL (ear only)
578
String JavaDoc altname = null;
579                             URL JavaDoc altDDUrl = (URL JavaDoc) urlAltDDBindings.get(url);
580                             if (altDDUrl != null) {
581                                 altname = altDDUrl.getFile();
582                             }
583                             lookupDD = getDeploymentDescriptor(fileName,
584                                                                ejbLoader,
585                                                                altname);
586                         }
587
588                         if (lookupDD != null) {
589                             bdtmp = lookupDD.getBeanDesc(ejbLink);
590                             if (bdtmp != null) {
591                                 if (logger.isLoggable(BasicLevel.DEBUG)) {
592                                     logger.log(BasicLevel.DEBUG, "Found a BeanDesc in the Deployment Desc." + urlRead);
593                                 }
594                                 //ejblink was found ?
595
if (found) {
596                                     String JavaDoc err = "There are more than one bean with the name '" + ejbLink + "' which were found in all the ejbjars of this EAR.";
597                                     throw new DeploymentDescException(err);
598                                 } else {
599                                     found = true;
600                                     bd = bdtmp;
601                                 }
602                             } else {
603                                 if (logger.isLoggable(BasicLevel.DEBUG)) {
604                                     logger.log(BasicLevel.DEBUG, "No BeanDesc found in the Deployment Desc." + urlRead);
605                                 }
606                             }
607                         }
608                     }
609                 }
610                 if (!found) {
611                     String JavaDoc err = "No ejblink was found for '" + ejbLink + "' in all the ejbjars of this EAR.";
612                     throw new DeploymentDescException(err);
613                 }
614             }
615
616             if (logger.isLoggable(BasicLevel.DEBUG)) {
617                 logger.log(BasicLevel.DEBUG, "BeanDesc found = " + bd.getEjbName());
618             }
619             //Check if the type of the ejb-ref is correct.
620
checkType(currentFile, ejbType, bd);
621
622             if (bd == null) {
623                 String JavaDoc err = "Ejb-link " + ejbLink + " not found inside the file " + currentFile.getFile() + ". The bean doesn't exists.";
624                 throw new DeploymentDescException(err);
625             }
626
627             String JavaDoc jndiname;
628             if (isEjbRef) {
629                 jndiname = bd.getJndiName();
630             } else {
631                 jndiname = bd.getJndiLocalName();
632             }
633             return jndiname;
634         }
635
636         if (earCl != null) {
637             String JavaDoc url = currentFile.getFile();
638             //Add it
639
urlEarCLBindings.put(url, earCl);
640         }
641
642         //Ejb-link not in the same ejb-jar file.
643
StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(ejbLink, LINK_SEPARATOR);
644
645         // We must have only two elements after this step, one for the fileName
646
// before the # and the name of the bean after the # char
647
if (st.countTokens() != 2 || ejbLink.startsWith(LINK_SEPARATOR)
648             || ejbLink.endsWith(LINK_SEPARATOR)) {
649
650             String JavaDoc err = "Ejb link " + ejbLink + " has a bad format. Correct format : filename.jar#beanName.";
651             throw new DeploymentDescException(err);
652         }
653
654         //Get the token
655
ejbJarLink = st.nextToken();
656         beanNameLink = st.nextToken();
657
658         //Check if ejbJarLink is a jar or not
659
if (!ejbJarLink.endsWith(".jar")) {
660             String JavaDoc err = "Ejbjar filename " + ejbJarLink + " from the ejb-link " + ejbLink + " has a bad format. Correct format : filename.jar";
661             throw new DeploymentDescException(err);
662         }
663
664
665         // Now construct the URL from the absolute path from the url ejbJar and
666
// the relative path from ejbJarLink
667
URL JavaDoc ejbJarLinkUrl = null;
668         try {
669             ejbJarLinkUrl = new File JavaDoc(new File JavaDoc(currentFile.getFile()).getParent() + File.separator + ejbJarLink).getCanonicalFile().toURL();
670         } catch (MalformedURLException JavaDoc mue) {
671             String JavaDoc err = "Error when creating an url for the ejb jar filename. Error :" + mue.getMessage();
672             throw new DeploymentDescException(err);
673         } catch (IOException JavaDoc ioe) {
674             String JavaDoc err = "Error when creating/accessing a file. Error :" + ioe.getMessage();
675             throw new DeploymentDescException(err);
676         }
677
678         // We've got the url
679
BeanDesc bd = null;
680         // The ejb-link with .jar#beanName could reference the current jar file
681
if (currentFile.getPath().equalsIgnoreCase(ejbJarLinkUrl.getPath())) {
682             if (logger.isLoggable(BasicLevel.DEBUG)) {
683                 logger.log(BasicLevel.DEBUG, "ejblink jar#bean reference our current file");
684             }
685
686             // Read in its own deployment descriptor if not null
687
if (deploymentDesc != null) {
688                 bd = deploymentDesc.getBeanDesc(beanNameLink);
689             } else {
690                 if (logger.isLoggable(BasicLevel.DEBUG)) {
691                     logger.log(BasicLevel.DEBUG, "DD = null, cannot return bean in the current DD");
692                 }
693             }
694
695         } else {
696             //Another file :
697

698             // Now, We can ask the Deployment Descriptor of this url
699
DeploymentDesc dd = getDeploymentDesc(currentFile, ejbJarLinkUrl);
700
701             // JndiName resolve.
702
bd = dd.getBeanDesc(beanNameLink);
703         }
704
705         if (bd == null) {
706             String JavaDoc err = "Ejb-link " + ejbLink + " not found inside the file " + currentFile.getFile() + ". The bean doesn't exists";
707             throw new DeploymentDescException(err);
708         }
709
710         //Check if the type of the ejb-ref is correct.
711
checkType(currentFile, ejbType, bd);
712
713         String JavaDoc jndiname;
714         if (isEjbRef) {
715             jndiname = bd.getJndiName();
716         } else {
717             jndiname = bd.getJndiLocalName();
718         }
719         return jndiname;
720     }
721
722     /**
723      * Return the JNDI name from the messageDestinationLink string.
724      * messageDestinationLink format : filename.jar#beanName in the same Ear File
725      * beanName in the same ejb-jar file.
726      * @param ejbJar the url of the jar being parsed. This is needed because
727      * mdLink is relative. With the url and the mdLink, we can know where
728      * the file is locate.
729      * @param mdLink the mdLink tag of a message-destination-ref
730      * @param mdType the type of the referenced mdb in the message-destination-ref tag.
731      * @param mdUsage the usage of the referenced mdb in the message-destination-ref tag.
732      * @param deploymentDesc the deployment descriptor of the parsed deploymentDesc.
733      * @return the JNDI name if found, null otherwise
734      * @throws DeploymentDescException when it failed
735      */

736     private String JavaDoc getMDJndiName(URL JavaDoc ejbJar, String JavaDoc mdLink, String JavaDoc mdType, String JavaDoc mdUsage,
737                                  DeploymentDesc deploymentDesc)
738         throws DeploymentDescException {
739
740         if (logger.isLoggable(BasicLevel.DEBUG)) {
741             logger.log(BasicLevel.DEBUG, "" + ejbJar + " " + mdLink + " " + mdType + " " + mdUsage);
742         }
743         // Extract from the mdb link
744
// - the name of the file
745
// - the name of the destination
746
String JavaDoc ejbJarLink = null;
747         String JavaDoc destNameLink = null;
748         DeploymentDesc dd = deploymentDesc;
749
750         //Different jar ?
751
if (mdLink.indexOf(LINK_SEPARATOR) != -1) {
752             //Message-destination-link not in the same ejb-jar file.
753
StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(mdLink, LINK_SEPARATOR);
754
755             // We must have only two elements after this step, one for the fileName
756
// before the # and the name of the message-destination after the # char
757
if (st.countTokens() != 2 || mdLink.startsWith(LINK_SEPARATOR)
758                 || mdLink.endsWith(LINK_SEPARATOR)) {
759
760                 String JavaDoc err = "Message-destination-link " + mdLink + " has a bad format. Correct format : filename.jar#messageDestinationName.";
761                 throw new DeploymentDescException(err);
762             }
763
764             //Get the token
765
ejbJarLink = st.nextToken();
766             destNameLink = st.nextToken();
767
768             //Check if ejbJarLink is a jar or not
769
if (!ejbJarLink.endsWith(".jar")) {
770                 String JavaDoc err = "Ejbjar filename " + ejbJarLink + " from the message-destination-link " + mdLink + " has a bad format. Correct format : filename.jar";
771                 throw new DeploymentDescException(err);
772             }
773
774
775             // Now construct the URL from the absolute path from the url ejbJar and
776
// the relative path from ejbJarLink
777
URL JavaDoc ejbJarLinkUrl = null;
778             try {
779                 ejbJarLinkUrl = new File JavaDoc(new File JavaDoc(ejbJar.getFile()).getParent() + File.separator + ejbJarLink).getCanonicalFile().toURL();
780             } catch (MalformedURLException JavaDoc mue) {
781                 String JavaDoc err = "Error when creating an url for the ejb jar filename. Error :" + mue.getMessage();
782                 throw new DeploymentDescException(err);
783             } catch (IOException JavaDoc ioe) {
784                 String JavaDoc err = "Error when creating/accessing a file. Error :" + ioe.getMessage();
785                 throw new DeploymentDescException(err);
786             }
787
788             // Check if the jar exist.
789
if (!new File JavaDoc(ejbJarLinkUrl.getFile()).exists()) {
790                 String JavaDoc err = "Cannot get the deployment descriptor for '" + ejbJarLinkUrl.getFile() + "'. The file doesn't exist.";
791                 throw new DeploymentDescException(err);
792             }
793
794             // We've got the url
795
// Now, We can ask the Deployment Descriptor of this url
796
dd = getDeploymentDesc(ejbJar, ejbJarLinkUrl);
797         }
798
799         //Link to a destination inside the same ejb-jar file.
800
if (dd == null) {
801             throw new DeploymentDescException("Deployment desc for file ejb-jar '" + ejbJar.getFile() + "' not found");
802         }
803
804         boolean foundMd = dd.getMessageDestination(mdLink);
805         if (!foundMd) {
806             String JavaDoc err = "No message-destination was found for '" + mdLink + "' in the ejbjar specified.";
807             throw new DeploymentDescException(err);
808         }
809
810         JonasMessageDestination md = dd.getJonasMessageDestination(mdLink);
811
812         if (md == null) {
813             String JavaDoc err = "No jonas-message-destination was found for '" + mdLink + "' in the ejbjar specified.";
814             throw new DeploymentDescException(err);
815         }
816
817         if (logger.isLoggable(BasicLevel.DEBUG)) {
818             logger.log(BasicLevel.DEBUG, "Message-destination found = " + md.getJndiName());
819         }
820
821         //Check if the type & usage of the message-destination-ref is correct.
822
//checkTypeUsage(ejbJar, mdType, mdUsage, mdd);
823

824         return md.getJndiName();
825
826     }
827
828     /**
829      * Check if the link is available in the case of an ear application.
830      * @param earClassLoader the ear classloader of the ear application.
831      * @param url the url to check.
832      * @throws DeploymentDescException if the ejb-link isn't available.
833      */

834     private void checkEjbLinkAvailable(ClassLoader JavaDoc earClassLoader,
835                                        URL JavaDoc url)
836         throws DeploymentDescException {
837
838         Vector JavaDoc v = (Vector JavaDoc) earCLEjbLinkJar.get(earClassLoader);
839
840         if (v != null) {
841             if (!v.contains(url.getFile())) {
842                 String JavaDoc err = "The ejb-link or message-destination-link of '" + url.getFile() + "' must be done on an ejb-jar defined in the ear application (application.xml <module><ejb>###</ejb></module>)";
843                 throw new DeploymentDescException(err);
844             }
845         } else {
846             String JavaDoc err = "setAvailableEjbLinkJar was badly called.";
847             throw new DeploymentDescException(err);
848         }
849     }
850
851     /**
852      * Set for the given ear identified by its earClassLoader the list of the
853      * ejb-jar that can be in the ejb-link and the optional Desployment Desc.
854      * @param earClassLoader the classloader of the ear application.
855      * @param urls the list of the URLs of the ear application that can be in
856      * the ejb-link.
857      * @param altDDs the list of the URLs of the alternate DDs to use if specified.
858      */

859     public void setAvailableEjbJarsAndAltDDs(ClassLoader JavaDoc earClassLoader,
860                                              URL JavaDoc[] urls,
861                                              URL JavaDoc[] altDDs) {
862         Vector JavaDoc v = new Vector JavaDoc();
863         for (int i = 0; i < urls.length; i++) {
864             v.addElement(urls[i].getFile());
865             if (altDDs[i] != null) {
866                 urlAltDDBindings.put(urls[i].getFile(), altDDs[i]);
867             }
868         }
869         earCLEjbLinkJar.put(earClassLoader, v);
870     }
871
872     /**
873      * Make a cleanup of the cache of deployment descriptor. This method must
874      * be invoked after the ear deployment by the EAR service.
875      * @param earClassLoader the URLClassLoader of the ear application to
876      * remove from the cache.
877      */

878     public void removeCache(ClassLoader JavaDoc earClassLoader) {
879         Vector JavaDoc v = (Vector JavaDoc) earCLEjbLinkJar.remove(earClassLoader);
880         if (v != null) {
881             for (int i = 0; i < v.size(); i++) {
882                 String JavaDoc url = (String JavaDoc) v.elementAt(i);
883                 urlJarBindings.remove(url);
884                 urlEarCLBindings.remove(url);
885                 urlEjbCLBindings.remove(url);
886                 urlAltDDBindings.remove(url);
887             }
888         }
889
890         if (earCLEjbLinkJar.size() != 0
891             || urlJarBindings.size() != 0
892             || urlEarCLBindings.size() != 0
893             || urlAltDDBindings.size() != 0
894             || urlEjbCLBindings.size() != 0) {
895
896             String JavaDoc buffer = earCLEjbLinkJar.size() + " ";
897             buffer += urlJarBindings.size() + " ";
898             buffer += urlEarCLBindings.size() + " ";
899             buffer += urlEjbCLBindings.size() + " ";
900             buffer += urlAltDDBindings.size();
901
902             if (logger.isLoggable(BasicLevel.DEBUG)) {
903                 logger.log(BasicLevel.DEBUG, buffer + " there are some elements in cache");
904             }
905         }
906     }
907
908     /**
909      * Get the size of the cache (number of entries in the cache).
910      * Used only for debugging.
911      * @return the size of the cache (number of entries in the cache).
912      */

913     public int getCacheSize() {
914         return earCLEjbLinkJar.size() + urlJarBindings.size()
915             + urlEarCLBindings.size() + urlEjbCLBindings.size()
916             + urlAltDDBindings.size();
917     }
918
919     /**
920      * Return a string representation of the cache. (Used only for debugging).
921      * @return a string representation of the cache.
922      */

923     public String JavaDoc toString() {
924         return earCLEjbLinkJar.size() + " " + urlJarBindings.size() + " "
925             + urlEarCLBindings.size() + " " + urlEjbCLBindings.size() + " "
926             + urlAltDDBindings.size();
927     }
928
929     /**
930      * Factory method using deployment descriptor and Jonas deployment descriptor
931      * file names.
932      * used by GEnIC or GenIDL
933      * @param ejbJarXmlFileName name of the standard DD
934      * @param jonasEjbJarXmlFileName name of the specific DD
935      * @param jarFileName name of the jar file
936      * @return instance of the corresponding DeploymentDesc
937      * @exception DeploymentDescException when DeploymentDesc cannot be created with
938      * given files.
939      */

940     public static DeploymentDesc getDeploymentDesc(String JavaDoc ejbJarXmlFileName,
941                                                    String JavaDoc jonasEjbJarXmlFileName,
942                                                    String JavaDoc jarFileName)
943         throws DeploymentDescException {
944         // instantiate deployment descriptor
945
ClassLoader JavaDoc cl = DeploymentDesc.class.getClassLoader();
946         if (cl == null) {
947             cl = Thread.currentThread().getContextClassLoader();
948         }
949         return getDeploymentDescriptor(ejbJarXmlFileName, jonasEjbJarXmlFileName, cl, jarFileName);
950     }
951
952     /**
953      * Factory method using deployment descriptor and Jonas deployment descriptor
954      * file names. (input is 2 .xml descriptors)
955      * @param ejbJarXmlFileName Name of the xml for the EJBJAR
956      * @param jonasEjbJarXmlFileName Name of the xml for JOnAS ejbjar
957      * @param cl classloader to use
958      * @param moduleDirName name of file
959      * @return instance of the corresponding DeploymentDesc
960      * @exception DeploymentDescException when DeploymentDesc cannot be created with
961      * given files.
962      */

963     private static DeploymentDesc getDeploymentDescriptor(String JavaDoc ejbJarXmlFileName,
964                                                           String JavaDoc jonasEjbJarXmlFileName,
965                                                           ClassLoader JavaDoc cl,
966                                                           String JavaDoc moduleDirName)
967         throws DeploymentDescException {
968
969         InputStream JavaDoc is;
970
971         // load deployment descriptor data
972
try {
973             is = new FileInputStream JavaDoc(ejbJarXmlFileName);
974             // store file content in a String
975
xmlContent = xmlContent(is);
976             // reposition to the begining of the stream
977
is = new FileInputStream JavaDoc(ejbJarXmlFileName);
978         } catch (FileNotFoundException JavaDoc e) {
979             throw new DeploymentDescException(ejbJarXmlFileName + " file not found");
980         } catch (IOException JavaDoc ioe) {
981             throw new DeploymentDescException("Cannot read the content of the xml file " + ejbJarXmlFileName);
982         }
983         EjbJar ejbJar = loadEjbJar(new InputStreamReader JavaDoc(is), ejbJarXmlFileName);
984         String JavaDoc dtdversion = ejbJar.getVersion();
985         try {
986             is.close();
987         } catch (IOException JavaDoc e) {
988             logger.log(BasicLevel.WARN, "Can't close '" + ejbJarXmlFileName + "'");
989         }
990
991         // load jonas deployment descriptor data
992
try {
993             is = new FileInputStream JavaDoc(jonasEjbJarXmlFileName);
994             // store file content in a String
995
jonasXmlContent = xmlContent(is);
996             // reposition to the begining of the stream
997
is = new FileInputStream JavaDoc(jonasEjbJarXmlFileName);
998         } catch (FileNotFoundException JavaDoc e) {
999             throw new DeploymentDescException(jonasEjbJarXmlFileName + " file not found");
1000        } catch (IOException JavaDoc ioe) {
1001            throw new DeploymentDescException("Cannot read the content of the xml file " + ejbJarXmlFileName);
1002        }
1003
1004        JonasEjbJar jonasEjbJar = loadJonasEjbJar(new InputStreamReader JavaDoc(is),
1005                                                  jonasEjbJarXmlFileName);
1006        try {
1007            is.close();
1008        } catch (IOException JavaDoc e) {
1009            logger.log(BasicLevel.WARN, "Can't close '" + jonasEjbJarXmlFileName + "'");
1010        }
1011
1012        // instantiate deployment descriptor
1013
DeploymentDesc descEjb = null;
1014        if (dtdversion.equals("1.1")) {
1015            descEjb = new DeploymentDescEjb1_1(cl, ejbJar, jonasEjbJar, logger, moduleDirName);
1016        } else {
1017            descEjb = new DeploymentDescEjb2(cl, ejbJar, jonasEjbJar, logger, moduleDirName);
1018        }
1019        descEjb.setXmlContent(xmlContent);
1020        descEjb.setJOnASXmlContent(jonasXmlContent);
1021        return descEjb;
1022    }
1023
1024
1025    /**
1026     * Factory method using the ejb-jar file name. (input is a .jar file)
1027     * Called either from GenIC or from createContainer.
1028     * @param ejbJarFileName name of the ejbjar
1029     * @param cl classloader to use
1030     * @param altWebXmlFilename null if not ear
1031     * @return instance of the corresponding DeploymentDesc
1032     * @exception DeploymentDescException when DeploymentDesc cannot be created with
1033     * given ejb-jar file.
1034     */

1035    private static DeploymentDesc getDeploymentDescriptor(String JavaDoc ejbJarFileName,
1036                                                          ClassLoader JavaDoc cl,
1037                                                          String JavaDoc altWebXmlFilename)
1038        throws DeploymentDescException {
1039
1040        ZipFile JavaDoc zf = null;
1041        InputStream JavaDoc isDd = null;
1042        InputStream JavaDoc isJdd = null;
1043        EjbJar ejbJar;
1044        JonasEjbJar jonasEjbJar;
1045
1046        // Check if the Alt deploymentDesc file exists. (optional value)
1047
if ((altWebXmlFilename != null) && (!new File JavaDoc(altWebXmlFilename).exists())) {
1048            String JavaDoc err = "The file for the altdd tag for the EAR case '" + altWebXmlFilename + "' was not found.";
1049            throw new DeploymentDescException(err);
1050        }
1051
1052        // Get the XML DD files of the ejb-jar as InputStream
1053
try {
1054            zf = new ZipFile JavaDoc(ejbJarFileName);
1055
1056            if (altWebXmlFilename == null) {
1057                // No alt-dd case ( standard)
1058
ZipEntry JavaDoc ejbEntry = zf.getEntry(EJB_JAR_FILE_NAME);
1059                if (ejbEntry == null) {
1060                    throw new DeploymentDescException("The entry '" + EJB_JAR_FILE_NAME
1061                            + "' was not found in the file '" + ejbJarFileName + "'.");
1062                }
1063                isDd = zf.getInputStream(ejbEntry);
1064                xmlContent = xmlContent(isDd);
1065                isDd = zf.getInputStream(zf.getEntry(EJB_JAR_FILE_NAME));
1066            } else {
1067                // AltDD (Ear and optional)
1068
isDd = new FileInputStream JavaDoc(altWebXmlFilename);
1069                xmlContent = xmlContent(isDd);
1070                isDd = new FileInputStream JavaDoc(altWebXmlFilename);
1071            }
1072            ZipEntry JavaDoc jEjbEntry = zf.getEntry(JONAS_EJB_JAR_FILE_NAME);
1073            if (jEjbEntry != null) {
1074                isJdd = zf.getInputStream(jEjbEntry);
1075                jonasXmlContent = xmlContent(isJdd);
1076                isJdd = zf.getInputStream(zf.getEntry(JONAS_EJB_JAR_FILE_NAME));
1077            } else {
1078                logger.log(BasicLevel.WARN, "No entry '" + JONAS_EJB_JAR_FILE_NAME + "' was found in the file '" + ejbJarFileName + "'.");
1079            }
1080        } catch (Exception JavaDoc e) {
1081            if (zf != null) {
1082                try {
1083                    zf.close();
1084                } catch (IOException JavaDoc i) {
1085                    logger.log(BasicLevel.WARN, "Can't close '" + ejbJarFileName + "'");
1086                }
1087            }
1088            logger.log(BasicLevel.ERROR, "Cannot read the XML deployment descriptors for " + ejbJarFileName + ":", e);
1089            throw new DeploymentDescException("Cannot read the XML deployment descriptors for " + ejbJarFileName + ":" + e);
1090        }
1091
1092        // load standard deployment descriptor data
1093
ejbJar = loadEjbJar(new InputStreamReader JavaDoc(isDd), EJB_JAR_FILE_NAME);
1094        String JavaDoc dtdversion = ejbJar.getVersion();
1095        try {
1096            isDd.close();
1097        } catch (IOException JavaDoc e) {
1098            logger.log(BasicLevel.WARN, "Can't close META-INF/ejb-jar.xml in '" + ejbJarFileName + "'");
1099        }
1100
1101        // load jonas deployment descriptor data
1102
if (isJdd != null) {
1103            jonasEjbJar = loadJonasEjbJar(new InputStreamReader JavaDoc(isJdd),
1104                                      JONAS_EJB_JAR_FILE_NAME);
1105            try {
1106                isJdd.close();
1107            } catch (IOException JavaDoc e) {
1108                logger.log(BasicLevel.WARN, "Can't close META-INF/jonas-ejb-jar.xml in '" + ejbJarFileName + "'");
1109            }
1110
1111        } else {
1112            jonasEjbJar = new JonasEjbJar();
1113        }
1114
1115        // Close the ZipFile
1116
if (zf != null) {
1117            try {
1118                zf.close();
1119            } catch (IOException JavaDoc e) {
1120                logger.log(BasicLevel.WARN, "Can't close '" + ejbJarFileName + "'");
1121            }
1122        }
1123
1124        // instantiate deployment descriptor
1125
DeploymentDesc descEjb = null;
1126        if (dtdversion.equals("1.1")) {
1127            descEjb = new DeploymentDescEjb1_1(cl, ejbJar, jonasEjbJar, logger, ejbJarFileName);
1128        } else {
1129            descEjb = new DeploymentDescEjb2(cl, ejbJar, jonasEjbJar, logger, ejbJarFileName);
1130        }
1131        descEjb.setXmlContent(xmlContent);
1132        descEjb.setJOnASXmlContent(jonasXmlContent);
1133        return descEjb;
1134    }
1135
1136
1137   /**
1138     * Load the ejb_jar.xml file.
1139     * @param reader the reader of the XML file.
1140     * @param name the name of the file (ejb-jar.xml).
1141     * @return a structure containing the result of the ejb-jar.xml parsing.
1142     * @throws DeploymentDescException if the deployment descriptor
1143     * is corrupted.
1144     */

1145    public static EjbJar loadEjbJar(Reader JavaDoc reader, String JavaDoc name)
1146        throws DeploymentDescException {
1147        EjbJar ejbjar = new EjbJar();
1148
1149        // Create if null
1150
if (ejbjarDigester == null) {
1151            // Create and initialize the digester
1152
ejbjarDigester = new JDigester(ejbjarRuleSet,
1153                                           parsingWithValidation,
1154                                           true,
1155                                           new EjbjarDTDs(),
1156                                           new EjbjarSchemas());
1157        }
1158        try {
1159            ejbjarDigester.parse(reader, name, ejbjar);
1160        } catch (DeploymentDescException e) {
1161            throw e;
1162        } finally {
1163            ejbjarDigester.push(null);
1164        }
1165        return ejbjar;
1166    }
1167
1168    /**
1169     * Load the EjbJar file
1170     * @param reader reader containing the stream
1171     * @param name name of the file
1172     * @return JOnAS DD object
1173     * @throws DeploymentDescException if loading fails
1174     */

1175    public static JonasEjbJar loadJonasEjbJar(Reader JavaDoc reader,
1176                                               String JavaDoc name)
1177        throws DeploymentDescException {
1178         JonasEjbJar jonasEjbjar = new JonasEjbJar();
1179        // Create if null
1180
if (jonasEjbjarDigester == null) {
1181            // Create and initialize the digester
1182
jonasEjbjarDigester = new JDigester(jonasEjbjarRuleSet,
1183                                           parsingWithValidation,
1184                                           true,
1185                                           new JonasEjbjarDTDs(),
1186                                           new JonasEjbjarSchemas());
1187        }
1188        try {
1189            jonasEjbjarDigester.parse(reader , name, jonasEjbjar);
1190        } catch (DeploymentDescException e) {
1191            throw e;
1192        } finally {
1193            jonasEjbjarDigester.push(null);
1194        }
1195        return jonasEjbjar;
1196    }
1197
1198    /**
1199     * Controls whether the parser is reporting all validity errors.
1200     * @return if true, all external entities will be read.
1201     */

1202    public static boolean getParsingWithValidation() {
1203        return parsingWithValidation;
1204    }
1205
1206    /**
1207     * Controls whether the parser is reporting all validity errors.
1208     * @param validation if true, all external entities will be read.
1209     */

1210    public static void setParsingWithValidation(boolean validation) {
1211        EjbDeploymentDescManager.parsingWithValidation = validation;
1212    }
1213
1214    /**
1215     * Return the content of the web.xml file
1216     * @return the content of the web.xml file
1217     */

1218    public static String JavaDoc getXmlContent() {
1219        return xmlContent;
1220    }
1221
1222    /**
1223     * Return the content of the jonas-web.xml file
1224     * @return the content of the jonas-web.xml file
1225     */

1226    public static String JavaDoc getJOnASXmlContent() {
1227        return jonasXmlContent;
1228    }
1229
1230
1231    /**
1232     * Check if the type of the ejb-ref is correct.
1233     * @param ejbJar the URL of the ejb-jar being parsed.
1234     * @param ejbType the type of the ejb-ref (ejb-ref-type).
1235     * @param bd the descriptor of the referenced bean.
1236     * @throws DeploymentDescException if the type is incorrect.
1237     */

1238    protected void checkType(URL JavaDoc ejbJar, String JavaDoc ejbType, JndiEnvRefsGroup bd) throws DeploymentDescException {
1239
1240        if (bd instanceof SessionDesc) {
1241            if (!ejbType.equalsIgnoreCase("Session")) {
1242                String JavaDoc err = "Deployment desc '" + ejbJar.getFile()
1243                        + "' has an incompatible ejb-ref-type: Required Session but found " + ejbType;
1244                throw new DeploymentDescException(err);
1245            }
1246        } else if (bd instanceof EntityDesc) {
1247            if (!ejbType.equalsIgnoreCase("Entity")) {
1248                String JavaDoc err = "Deployment desc '" + ejbJar.getFile()
1249                        + "' has an incompatible ejb-ref-type: Required Entity but found " + ejbType;
1250                throw new DeploymentDescException(err);
1251            }
1252        } else {
1253            String JavaDoc err = "Deployment desc '" + ejbJar.getFile() + "' has a bad ejb-ref-type.";
1254            throw new DeploymentDescException(err);
1255        }
1256    }
1257
1258    /**
1259     * Check if the type & usage of the message-destination-ref is correct.
1260     * @param url the URL of the file being parsed.
1261     * @param mdType the type of the message-destination-ref
1262     * (message-destination-type).
1263     * @param mdUsage the usage of the message-destination-ref
1264     * (message-destination-usage).
1265     * @param bd the descriptor of the referenced bean.
1266     * @throws DeploymentDescException if the type is incorrect.
1267     */

1268    protected void checkTypeUsage(URL JavaDoc url, String JavaDoc mdType, String JavaDoc mdUsage, BeanDesc bd) throws DeploymentDescException {
1269
1270        if (bd instanceof MessageDrivenDesc) {
1271            MessageDrivenDesc mdd = (MessageDrivenDesc) bd;
1272            if (mdd.getDestinationType().equals("javax.jms.Topic")) {
1273                if (!mdType.equalsIgnoreCase("javax.jms.Topic")) {
1274                    String JavaDoc err = "Deployment desc '" + url.getFile()
1275                            + "' has an incompatible message-destination-type: Required javax.jms.Topic but found "
1276                            + mdType;
1277                    throw new DeploymentDescException(err);
1278                }
1279            } else if (mdd.getDestinationType().equals("javax.jms.Queue")) {
1280                if (!mdType.equalsIgnoreCase("javax.jms.Queue")) {
1281                    String JavaDoc err = "Deployment desc '" + url.getFile()
1282                            + "' has an incompatible message-destination-type: Required javax.jms.Queue but found "
1283                            + mdType;
1284                    throw new DeploymentDescException(err);
1285                }
1286            }
1287        } else {
1288            String JavaDoc err = "Deployment desc '" + url.getFile() + "' has a bad message-destination-ref-type.";
1289            throw new DeploymentDescException(err);
1290        }
1291    }
1292
1293    /**
1294     * Add a mapping between url and classloader
1295     * @param ejbClassloader EjbClassloader on which associate URLs
1296     * @param urls array of urls associated to the classloader
1297     */

1298    public void addClassLoaderUrlMapping(ClassLoader JavaDoc ejbClassloader, URL JavaDoc[] urls) {
1299        for (int u = 0; u < urls.length; u++) {
1300            urlEjbCLBindings.put(urls[u].getPath(), ejbClassloader);
1301        }
1302    }
1303}
1304
Popular Tags