1
2
3
4
5
6
7
8
9
10
11 package org.mule.impl.container;
12
13 import org.mule.providers.ejb.i18n.EjbMessages;
14 import org.mule.umo.manager.ObjectNotFoundException;
15 import org.mule.util.ClassUtils;
16
17 import java.lang.reflect.Method;
18
19 import javax.ejb.EJBHome;
20 import javax.naming.NamingException;
21
22
23
24
25
26 public class EjbContainerContext extends RmiContainerContext
27 {
28 public EjbContainerContext()
29 {
30 super("ejb");
31 }
32
33 protected EjbContainerContext(String name)
34 {
35 super(name);
36 }
37
38 public Object getComponent(Object key) throws ObjectNotFoundException
39 {
40 Object homeObject = null;
41 if (key == null)
42 {
43 throw new ObjectNotFoundException("null");
44 }
45 try
46 {
47 homeObject = context.lookup(key.toString());
48 }
49 catch (NamingException e)
50 {
51 throw new ObjectNotFoundException(key.toString(), e);
52 }
53
54 if (homeObject == null)
55 {
56 throw new ObjectNotFoundException(key.toString());
57 }
58 else if (homeObject instanceof EJBHome)
59 {
60
61 Method method = ClassUtils.getMethod(homeObject.getClass(), "create", null);
62 if (method == null)
63 {
64 throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException(
65 EjbMessages.ejbObjectMissingCreate(key).toString()));
66 }
67 try
68 {
69 return method.invoke(homeObject, ClassUtils.NO_ARGS);
70 }
71 catch (Exception e)
72 {
73 throw new ObjectNotFoundException(key.toString(), e);
74 }
75 }
76 else
77 {
78 throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException(
79 EjbMessages.ejbKeyRefNotValid(key).toString()));
80 }
81 }
82 }