KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > container > EjbContainerContext


1 /*
2  * $Id: EjbContainerContext.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.impl.container;
12
13 import org.mule.config.i18n.Message;
14 import org.mule.config.i18n.Messages;
15 import org.mule.umo.manager.ObjectNotFoundException;
16 import org.mule.util.ClassUtils;
17
18 import javax.ejb.EJBHome JavaDoc;
19 import javax.naming.NamingException JavaDoc;
20
21 import java.lang.reflect.Method JavaDoc;
22
23 /**
24  * <code>EjbContainerContext</code> is a container implementaiton that allows EJB
25  * Session beans to be referenced as Mule managed UMOs
26  *
27  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
28  * @version $Revision: 3798 $
29  */

30 public class EjbContainerContext extends RmiContainerContext
31 {
32     public EjbContainerContext()
33     {
34         super("ejb");
35     }
36
37     protected EjbContainerContext(String JavaDoc name)
38     {
39         super(name);
40     }
41
42     public Object JavaDoc getComponent(Object JavaDoc key) throws ObjectNotFoundException
43     {
44         Object JavaDoc homeObject = null;
45         if (key == null)
46         {
47             throw new ObjectNotFoundException("null");
48         }
49         try
50         {
51             homeObject = context.lookup(key.toString());
52         }
53         catch (NamingException JavaDoc e)
54         {
55             throw new ObjectNotFoundException(key.toString(), e);
56         }
57
58         if (homeObject == null)
59         {
60             throw new ObjectNotFoundException(key.toString());
61         }
62         else if (homeObject instanceof EJBHome JavaDoc)
63         {
64
65             Method JavaDoc method = ClassUtils.getMethod("create", null, homeObject.getClass());
66             if (method == null)
67             {
68                 throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException JavaDoc(new Message(
69                     Messages.EJB_OBJECT_X_MISSING_CREATE, key).toString()));
70             }
71             try
72             {
73                 return method.invoke(homeObject, ClassUtils.NO_ARGS);
74             }
75             catch (Exception JavaDoc e)
76             {
77                 throw new ObjectNotFoundException(key.toString(), e);
78             }
79         }
80         else
81         {
82             throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException JavaDoc(new Message(
83                 Messages.EJB_KEY_REF_X_NOT_VALID, key).toString()));
84         }
85     }
86 }
87
Popular Tags