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