KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > EjbUtil


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb;
23
24 import java.net.URL JavaDoc;
25 import java.net.MalformedURLException JavaDoc;
26
27 import java.util.Iterator JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29
30 import javax.management.MBeanServer JavaDoc;
31
32 import org.jboss.deployers.spi.deployer.DeploymentUnit;
33 import org.jboss.deployers.spi.structure.DeploymentContext;
34 import org.jboss.deployment.DeploymentInfo;
35 import org.jboss.deployment.MainDeployerMBean;
36 import org.jboss.logging.Logger;
37 import org.jboss.metadata.ApplicationMetaData;
38 import org.jboss.metadata.BeanMetaData;
39 import org.jboss.metadata.MessageDestinationMetaData;
40 import org.jboss.metadata.WebMetaData;
41 import org.jboss.util.Strings;
42
43 /** Utility methods for resolving ejb-ref and ejb-local-ref within the
44  * scope of a deployment.
45  *
46  * @author <a HREF="mailto:criege@riege.com">Christian Riege</a>
47  * @author Scott.Stark@jboss.org
48  *
49  * @version $Revision: 58339 $
50  */

51 public final class EjbUtil
52 {
53    private static final Logger log = Logger.getLogger(EjbUtil.class);
54
55    /**
56     * Resolves an &lt;ejb-link&gt; target for an &lt;ejb-ref&gt; entry and
57     * returns the name of the target in the JNDI tree.
58     *
59     * @param di DeploymentInfo
60     * @param link Content of the &lt;ejb-link&gt; entry.
61     *
62     * @return The JNDI Entry of the target bean; <code>null</code> if
63     * no appropriate target could be found.
64     */

65    public static String JavaDoc findEjbLink(MBeanServer JavaDoc server, DeploymentInfo di, String JavaDoc link)
66    {
67       return resolveLink(server, di, link, false);
68    }
69    public static String JavaDoc findEjbLink(MBeanServer JavaDoc server, DeploymentUnit unit, String JavaDoc link)
70    {
71       return resolveLink(server, unit, link, false);
72    }
73
74    /**
75     * Resolves an &lt;ejb-link&gt; target for an &lt;ejb-local-ref&gt; entry
76     * and returns the name of the target in the JNDI tree.
77     *
78     * @param di DeploymentInfo
79     * @param link Content of the &lt;ejb-link&gt; entry.
80     *
81     * @return The JNDI Entry of the target bean; <code>null</code> if
82     * no appropriate target could be found.
83     */

84    public static String JavaDoc findLocalEjbLink(MBeanServer JavaDoc server, DeploymentInfo di, String JavaDoc link)
85    {
86       return resolveLink(server, di, link, true);
87    }
88    public static String JavaDoc findLocalEjbLink(MBeanServer JavaDoc server, DeploymentUnit unit, String JavaDoc link)
89    {
90       return resolveLink(server, unit, link, true);
91    }
92
93    /**
94     * Resolves a &lt;message-destination&gt; target for a &lt;message-destination-link&gt;
95     * entry and returns the name of the target in the JNDI tree.
96     *
97     * @param di DeploymentInfo
98     * @param link Content of the &lt;message-driven-link&gt; entry.
99     *
100     * @return The JNDI Entry of the target; <code>null</code> if
101     * no appropriate target could be found.
102     */

103    public static MessageDestinationMetaData findMessageDestination(MBeanServer JavaDoc server, DeploymentInfo di, String JavaDoc link)
104    {
105       return resolveMessageDestination(server, di, link);
106    }
107    public static MessageDestinationMetaData findMessageDestination(MBeanServer JavaDoc server, DeploymentUnit unit, String JavaDoc link)
108    {
109       return resolveMessageDestination(server, unit, link);
110    }
111
112    private static String JavaDoc resolveLink(MBeanServer JavaDoc server, DeploymentInfo di, String JavaDoc link, boolean isLocal)
113    {
114       if (link == null)
115       {
116          return null;
117       }
118
119       if (log.isTraceEnabled())
120       {
121          log.trace("resolveLink( {" + di + "}, {" + link + "}, {" + isLocal + "}");
122       }
123
124       if (di == null)
125       {
126          // We should throw an IllegalArgumentException here probably?
127
return null;
128       }
129
130       if (link.indexOf('#') != -1)
131       {
132          // <ejb-link> is specified in the form path/file.jar#Bean
133
return resolveRelativeLink(server, di, link, isLocal);
134       }
135       else
136       {
137          // <ejb-link> contains a Bean Name, scan the DeploymentInfo tree
138
DeploymentInfo top = di;
139          while (top.parent != null)
140          {
141             top = top.parent;
142          }
143
144          return resolveAbsoluteLink(top, link, isLocal);
145       }
146    }
147    private static String JavaDoc resolveLink(MBeanServer JavaDoc server, DeploymentUnit unit, String JavaDoc link, boolean isLocal)
148    {
149       if (link == null)
150       {
151          return null;
152       }
153
154       if (log.isTraceEnabled())
155       {
156          log.trace("resolveLink( {" + unit + "}, {" + link + "}, {" + isLocal + "}");
157       }
158
159       if (unit == null)
160       {
161          // We should throw an IllegalArgumentException here probably?
162
return null;
163       }
164
165       if (link.indexOf('#') != -1)
166       {
167          // <ejb-link> is specified in the form path/file.jar#Bean
168
return resolveRelativeLink(server, unit, link, isLocal);
169       }
170       else
171       {
172          // <ejb-link> contains a Bean Name, scan the DeploymentInfo tree
173
DeploymentContext top = unit.getDeploymentContext();
174          while (top.getParent() != null)
175          {
176             top = top.getParent();
177          }
178
179          return resolveAbsoluteLink(top, link, isLocal);
180       }
181    }
182
183    private static String JavaDoc resolveRelativeLink(MBeanServer JavaDoc server, DeploymentInfo di, String JavaDoc link, boolean isLocal)
184    {
185
186       String JavaDoc path = link.substring(0, link.indexOf('#'));
187       String JavaDoc ejbName = link.substring(link.indexOf('#') + 1);
188       String JavaDoc us = di.url.toString();
189
190       // Remove the trailing slash for unpacked deployments
191
if (us.charAt(us.length() - 1) == '/')
192          us = us.substring(0, us.length() - 1);
193
194       String JavaDoc ourPath = us.substring(0, us.lastIndexOf('/'));
195
196       if (log.isTraceEnabled())
197       {
198          log.trace("Resolving relative link: " + link);
199          log.trace("Looking for: '" + link + "', we're located at: '" + ourPath + "'");
200       }
201
202       for (StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(path, "/"); st.hasMoreTokens();)
203       {
204          String JavaDoc s = st.nextToken();
205          if (s.equals(".."))
206          {
207             ourPath = ourPath.substring(0, ourPath.lastIndexOf('/'));
208          }
209          else
210          {
211             ourPath += "/" + s;
212          }
213       }
214
215       URL JavaDoc target = null;
216
217       try
218       {
219          target = Strings.toURL(ourPath);
220       }
221       catch (MalformedURLException JavaDoc mue)
222       {
223          log.warn("Can't construct URL for: " + ourPath);
224          return null;
225       }
226
227       DeploymentInfo targetInfo = null;
228       try
229       {
230          targetInfo = (DeploymentInfo) server.invoke(MainDeployerMBean.OBJECT_NAME, "getDeployment", new Object JavaDoc[]
231          {target}, new String JavaDoc[]
232          {URL JavaDoc.class.getName()});
233       }
234       catch (Exception JavaDoc e)
235       {
236          log.warn("Got Exception when looking for DeploymentInfo: " + e);
237          return null;
238       }
239
240       if (targetInfo == null)
241       {
242          log.warn("Can't locate deploymentInfo for target: " + target);
243          return null;
244       }
245
246       if (log.isTraceEnabled())
247       {
248          log.trace("Found appropriate DeploymentInfo: " + targetInfo);
249       }
250
251       String JavaDoc linkTarget = null;
252       if (targetInfo.metaData instanceof ApplicationMetaData)
253       {
254          ApplicationMetaData appMD = (ApplicationMetaData) targetInfo.metaData;
255          BeanMetaData beanMD = appMD.getBeanByEjbName(ejbName);
256
257          if (beanMD != null)
258          {
259             linkTarget = getJndiName(beanMD, isLocal);
260          }
261          else
262          {
263             log.warn("No Bean named '" + ejbName + "' found in '" + path + "'!");
264          }
265       }
266       else
267       {
268          log.warn("DeploymentInfo " + targetInfo + " is not an EJB .jar " + "file!");
269       }
270
271       return linkTarget;
272    }
273
274    private static String JavaDoc resolveAbsoluteLink(DeploymentInfo di, String JavaDoc link, boolean isLocal)
275    {
276       if (log.isTraceEnabled())
277       {
278          log.trace("Resolving absolute link, di: " + di);
279       }
280
281       String JavaDoc ejbName = null;
282
283       // Search current DeploymentInfo
284
if (di.metaData instanceof ApplicationMetaData)
285       {
286          // Look in the ejb module for a match
287
ApplicationMetaData appMD = (ApplicationMetaData) di.metaData;
288          BeanMetaData beanMD = appMD.getBeanByEjbName(link);
289          if (beanMD != null)
290          {
291             ejbName = getJndiName(beanMD, isLocal);
292             if (log.isTraceEnabled())
293             {
294                log.trace("Found Bean: " + beanMD + ", resolves to: " + ejbName);
295             }
296
297             return ejbName;
298          }
299          else if (log.isTraceEnabled())
300          {
301             // Dump the ejb module ejbNames
302
log.trace("No match for ejb-link: " + link+", module names:");
303             Iterator JavaDoc iter = appMD.getEnterpriseBeans();
304             while (iter.hasNext())
305             {
306                beanMD = (BeanMetaData) iter.next();
307                String JavaDoc beanEjbName = getJndiName(beanMD, isLocal);
308                log.trace("... ejbName: " + beanEjbName);
309             }
310          }
311       }
312
313       // Search each subcontext
314
Iterator JavaDoc it = di.subDeployments.iterator();
315       while (it.hasNext() && ejbName == null)
316       {
317          DeploymentInfo child = (DeploymentInfo) it.next();
318          ejbName = resolveAbsoluteLink(child, link, isLocal);
319       }
320
321       return ejbName;
322    }
323
324    private static String JavaDoc getJndiName(BeanMetaData beanMD, boolean isLocal)
325    {
326       String JavaDoc jndiName = null;
327       if (isLocal)
328       {
329          // Validate that there is a local home associated with this bean
330
String JavaDoc localHome = beanMD.getLocalHome();
331          if (localHome != null)
332             jndiName = beanMD.getLocalJndiName();
333          else
334          {
335             log
336                   .warn("LocalHome jndi name requested for: '" + beanMD.getEjbName()
337                         + "' but there is no LocalHome class");
338          }
339       }
340       else
341       {
342          jndiName = beanMD.getJndiName();
343       }
344       return jndiName;
345    }
346
347    private static MessageDestinationMetaData resolveMessageDestination(MBeanServer JavaDoc server, DeploymentInfo di, String JavaDoc link)
348    {
349       if (link == null)
350          return null;
351
352       if (log.isTraceEnabled())
353          log.trace("resolveLink( {" + di + "}, {" + link + "})");
354
355       if (di == null)
356          // We should throw an IllegalArgumentException here probably?
357
return null;
358
359       if (link.indexOf('#') != -1)
360          // link is specified in the form path/file.jar#Bean
361
return resolveRelativeMessageDestination(server, di, link);
362       else
363       {
364          // link contains a Bean Name, scan the DeploymentInfo tree
365
DeploymentInfo top = di;
366          while (top.parent != null)
367             top = top.parent;
368
369          return resolveAbsoluteMessageDestination(top, link);
370       }
371    }
372    private static MessageDestinationMetaData resolveMessageDestination(MBeanServer JavaDoc server, DeploymentUnit unit, String JavaDoc link)
373    {
374       if (link == null)
375          return null;
376
377       if (log.isTraceEnabled())
378          log.trace("resolveLink( {" + unit + "}, {" + link + "})");
379
380       if (unit == null)
381          // We should throw an IllegalArgumentException here probably?
382
return null;
383
384       if (link.indexOf('#') != -1)
385          // link is specified in the form path/file.jar#Bean
386
return resolveRelativeMessageDestination(server, unit, link);
387       else
388       {
389          // link contains a Bean Name, scan the DeploymentInfo tree
390
DeploymentContext top = unit.getDeploymentContext();
391          while (top != null)
392          {
393             top = top.getParent();
394          }
395
396          return resolveAbsoluteMessageDestination(top.getDeploymentUnit(), link);
397       }
398    }
399
400    private static MessageDestinationMetaData resolveRelativeMessageDestination(MBeanServer JavaDoc server, DeploymentInfo di, String JavaDoc link)
401    {
402       String JavaDoc path = link.substring(0, link.indexOf('#'));
403       String JavaDoc destinationName = link.substring(link.indexOf('#') + 1);
404       String JavaDoc us = di.url.toString();
405
406       // Remove the trailing slash for unpacked deployments
407
if (us.charAt(us.length() - 1) == '/')
408          us = us.substring(0, us.length() - 1);
409
410       String JavaDoc ourPath = us.substring(0, us.lastIndexOf('/'));
411
412       if (log.isTraceEnabled())
413       {
414          log.trace("Resolving relative message-destination-link: " + link);
415          log.trace("Looking for: '" + link + "', we're located at: '" + ourPath + "'");
416       }
417
418       for (StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(path, "/"); st.hasMoreTokens();)
419       {
420          String JavaDoc s = st.nextToken();
421          if (s.equals(".."))
422             ourPath = ourPath.substring(0, ourPath.lastIndexOf('/'));
423          else
424             ourPath += "/" + s;
425       }
426
427       URL JavaDoc target = null;
428       try
429       {
430          target = Strings.toURL(ourPath);
431       }
432       catch (MalformedURLException JavaDoc mue)
433       {
434          log.warn("Can't construct URL for: " + ourPath);
435          return null;
436       }
437
438       DeploymentInfo targetInfo = null;
439       try
440       {
441          targetInfo = (DeploymentInfo) server.invoke
442          (
443             MainDeployerMBean.OBJECT_NAME,
444             "getDeployment",
445             new Object JavaDoc[] {target},
446             new String JavaDoc[] {URL JavaDoc.class.getName()}
447          );
448       }
449       catch (Exception JavaDoc e)
450       {
451          log.warn("Got Exception when looking for DeploymentInfo: " + e);
452          return null;
453       }
454
455       if (targetInfo == null)
456       {
457          log.warn("Can't locate deploymentInfo for target: " + target);
458          return null;
459       }
460
461       if (log.isTraceEnabled())
462          log.trace("Found appropriate DeploymentInfo: " + targetInfo);
463
464       if (targetInfo.metaData instanceof ApplicationMetaData)
465       {
466          ApplicationMetaData appMD = (ApplicationMetaData) targetInfo.metaData;
467          return appMD.getMessageDestination(destinationName);
468       }
469       else if (targetInfo.metaData instanceof WebMetaData)
470       {
471          WebMetaData webMD = (WebMetaData) targetInfo.metaData;
472          return webMD.getMessageDestination(destinationName);
473       }
474       else
475       {
476          log.warn("DeploymentInfo " + targetInfo + " is not an EJB .jar " + "file!");
477          return null;
478       }
479    }
480    private static MessageDestinationMetaData resolveRelativeMessageDestination(MBeanServer JavaDoc server, DeploymentUnit unit, String JavaDoc link)
481    {
482       String JavaDoc path = link.substring(0, link.indexOf('#'));
483       String JavaDoc destinationName = link.substring(link.indexOf('#') + 1);
484       String JavaDoc us = unit.getName();
485
486       // Remove the trailing slash for unpacked deployments
487
if (us.charAt(us.length() - 1) == '/')
488          us = us.substring(0, us.length() - 1);
489
490       String JavaDoc ourPath = us.substring(0, us.lastIndexOf('/'));
491
492       if (log.isTraceEnabled())
493       {
494          log.trace("Resolving relative message-destination-link: " + link);
495          log.trace("Looking for: '" + link + "', we're located at: '" + ourPath + "'");
496       }
497
498       for (StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(path, "/"); st.hasMoreTokens();)
499       {
500          String JavaDoc s = st.nextToken();
501          if (s.equals(".."))
502             ourPath = ourPath.substring(0, ourPath.lastIndexOf('/'));
503          else
504             ourPath += "/" + s;
505       }
506
507       URL JavaDoc target = null;
508       try
509       {
510          target = Strings.toURL(ourPath);
511       }
512       catch (MalformedURLException JavaDoc mue)
513       {
514          log.warn("Can't construct URL for: " + ourPath);
515          return null;
516       }
517
518       DeploymentInfo targetInfo = null;
519       try
520       {
521          targetInfo = (DeploymentInfo) server.invoke
522          (
523             MainDeployerMBean.OBJECT_NAME,
524             "getDeployment",
525             new Object JavaDoc[] {target},
526             new String JavaDoc[] {URL JavaDoc.class.getName()}
527          );
528       }
529       catch (Exception JavaDoc e)
530       {
531          log.warn("Got Exception when looking for DeploymentInfo: " + e);
532          return null;
533       }
534
535       if (targetInfo == null)
536       {
537          log.warn("Can't locate deploymentInfo for target: " + target);
538          return null;
539       }
540
541       if (log.isTraceEnabled())
542          log.trace("Found appropriate DeploymentInfo: " + targetInfo);
543
544       if (targetInfo.metaData instanceof ApplicationMetaData)
545       {
546          ApplicationMetaData appMD = (ApplicationMetaData) targetInfo.metaData;
547          return appMD.getMessageDestination(destinationName);
548       }
549       else if (targetInfo.metaData instanceof WebMetaData)
550       {
551          WebMetaData webMD = (WebMetaData) targetInfo.metaData;
552          return webMD.getMessageDestination(destinationName);
553       }
554       else
555       {
556          log.warn("DeploymentInfo " + targetInfo + " is not an EJB .jar " + "file!");
557          return null;
558       }
559    }
560
561    private static MessageDestinationMetaData resolveAbsoluteMessageDestination(DeploymentInfo di, String JavaDoc link)
562    {
563       if (log.isTraceEnabled())
564          log.trace("Resolving absolute link, di: " + di);
565
566       // Search current DeploymentInfo
567
if (di.metaData instanceof ApplicationMetaData)
568       {
569          ApplicationMetaData appMD = (ApplicationMetaData) di.metaData;
570          MessageDestinationMetaData mdMD = appMD.getMessageDestination(link);
571          if (mdMD != null)
572             return mdMD;
573       }
574       else if (di.metaData instanceof WebMetaData)
575       {
576          WebMetaData webMD = (WebMetaData) di.metaData;
577          return webMD.getMessageDestination(link);
578       }
579
580       // Search each subcontext
581
Iterator JavaDoc it = di.subDeployments.iterator();
582       while (it.hasNext())
583       {
584          DeploymentInfo child = (DeploymentInfo) it.next();
585          MessageDestinationMetaData mdMD = resolveAbsoluteMessageDestination(child, link);
586          if (mdMD != null)
587             return mdMD;
588       }
589
590       // Not found
591
return null;
592    }
593    private static MessageDestinationMetaData resolveAbsoluteMessageDestination(DeploymentUnit unit, String JavaDoc link)
594    {
595       if (log.isTraceEnabled())
596          log.trace("Resolving absolute link, unit: " + unit);
597
598       // Search current DeploymentInfo
599
ApplicationMetaData appMD = unit.getAttachment(ApplicationMetaData.class);
600       if (appMD != null)
601       {
602          MessageDestinationMetaData mdMD = appMD.getMessageDestination(link);
603          if (mdMD != null)
604             return mdMD;
605       }
606       WebMetaData webMD = unit.getAttachment(WebMetaData.class);
607       if( webMD != null )
608       {
609          return webMD.getMessageDestination(link);
610       }
611
612       // Search each subcontext
613
Iterator JavaDoc<DeploymentContext> it = unit.getDeploymentContext().getChildren().iterator();
614       while (it.hasNext())
615       {
616          DeploymentContext child = it.next();
617          MessageDestinationMetaData mdMD = resolveAbsoluteMessageDestination(child.getDeploymentUnit(), link);
618          if (mdMD != null)
619             return mdMD;
620       }
621
622       // Not found
623
return null;
624    }
625
626    private static String JavaDoc resolveRelativeLink(MBeanServer JavaDoc server, DeploymentUnit unit, String JavaDoc link, boolean isLocal)
627    {
628
629       String JavaDoc path = link.substring(0, link.indexOf('#'));
630       String JavaDoc ejbName = link.substring(link.indexOf('#') + 1);
631       String JavaDoc us = unit.getName();
632
633       // Remove the trailing slash for unpacked deployments
634
if (us.charAt(us.length() - 1) == '/')
635          us = us.substring(0, us.length() - 1);
636
637       String JavaDoc ourPath = us.substring(0, us.lastIndexOf('/'));
638
639       if (log.isTraceEnabled())
640       {
641          log.trace("Resolving relative link: " + link);
642          log.trace("Looking for: '" + link + "', we're located at: '" + ourPath + "'");
643       }
644
645       for (StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(path, "/"); st.hasMoreTokens();)
646       {
647          String JavaDoc s = st.nextToken();
648          if (s.equals(".."))
649          {
650             ourPath = ourPath.substring(0, ourPath.lastIndexOf('/'));
651          }
652          else
653          {
654             ourPath += "/" + s;
655          }
656       }
657
658       URL JavaDoc target = null;
659
660       try
661       {
662          target = Strings.toURL(ourPath);
663       }
664       catch (MalformedURLException JavaDoc mue)
665       {
666          log.warn("Can't construct URL for: " + ourPath);
667          return null;
668       }
669
670       DeploymentInfo targetInfo = null;
671       try
672       {
673          targetInfo = (DeploymentInfo) server.invoke(MainDeployerMBean.OBJECT_NAME, "getDeployment", new Object JavaDoc[]
674          {target}, new String JavaDoc[]
675          {URL JavaDoc.class.getName()});
676       }
677       catch (Exception JavaDoc e)
678       {
679          log.warn("Got Exception when looking for DeploymentInfo: " + e);
680          return null;
681       }
682
683       if (targetInfo == null)
684       {
685          log.warn("Can't locate deploymentInfo for target: " + target);
686          return null;
687       }
688
689       if (log.isTraceEnabled())
690       {
691          log.trace("Found appropriate DeploymentInfo: " + targetInfo);
692       }
693
694       String JavaDoc linkTarget = null;
695       if (targetInfo.metaData instanceof ApplicationMetaData)
696       {
697          ApplicationMetaData appMD = (ApplicationMetaData) targetInfo.metaData;
698          BeanMetaData beanMD = appMD.getBeanByEjbName(ejbName);
699
700          if (beanMD != null)
701          {
702             linkTarget = getJndiName(beanMD, isLocal);
703          }
704          else
705          {
706             log.warn("No Bean named '" + ejbName + "' found in '" + path + "'!");
707          }
708       }
709       else
710       {
711          log.warn("DeploymentInfo " + targetInfo + " is not an EJB .jar " + "file!");
712       }
713
714       return linkTarget;
715    }
716
717    private static String JavaDoc resolveAbsoluteLink(DeploymentContext ctx, String JavaDoc link, boolean isLocal)
718    {
719       if(ctx == null)
720          throw new IllegalArgumentException JavaDoc("deployment context passed is null");
721       
722       if (log.isTraceEnabled())
723       {
724          log.trace("Resolving absolute link, ctx: " + ctx);
725       }
726
727       String JavaDoc ejbName = null;
728   
729       ApplicationMetaData appMD = ctx.getDeploymentUnit().getAttachment(ApplicationMetaData.class);
730       if (appMD != null)
731       {
732          // Look in the ejb module for a match
733
BeanMetaData beanMD = appMD.getBeanByEjbName(link);
734          if (beanMD != null)
735          {
736             ejbName = getJndiName(beanMD, isLocal);
737             if (log.isTraceEnabled())
738             {
739                log.trace("Found Bean: " + beanMD + ", resolves to: " + ejbName);
740             }
741
742             return ejbName;
743          }
744          else if (log.isTraceEnabled())
745          {
746             // Dump the ejb module ejbNames
747
log.trace("No match for ejb-link: " + link+", module names:");
748             Iterator JavaDoc iter = appMD.getEnterpriseBeans();
749             while (iter.hasNext())
750             {
751                beanMD = (BeanMetaData) iter.next();
752                String JavaDoc beanEjbName = getJndiName(beanMD, isLocal);
753                log.trace("... ejbName: " + beanEjbName);
754             }
755          }
756       }
757
758       // Search each subcontext
759
Iterator JavaDoc it = ctx.getChildren().iterator();
760       while (it.hasNext() && ejbName == null)
761       {
762          DeploymentContext child = (DeploymentContext)it.next();
763          ejbName = resolveAbsoluteLink(child, link, isLocal);
764       }
765
766       return ejbName;
767    }
768
769 }
Popular Tags