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 | 0 | super("ejb"); |
31 | 0 | } |
32 | |
|
33 | |
protected EjbContainerContext(String name) |
34 | |
{ |
35 | 0 | super(name); |
36 | 0 | } |
37 | |
|
38 | |
public Object getComponent(Object key) throws ObjectNotFoundException |
39 | |
{ |
40 | 0 | Object homeObject = null; |
41 | 0 | if (key == null) |
42 | |
{ |
43 | 0 | throw new ObjectNotFoundException("null"); |
44 | |
} |
45 | |
try |
46 | |
{ |
47 | 0 | homeObject = context.lookup(key.toString()); |
48 | |
} |
49 | 0 | catch (NamingException e) |
50 | |
{ |
51 | 0 | throw new ObjectNotFoundException(key.toString(), e); |
52 | 0 | } |
53 | |
|
54 | 0 | if (homeObject == null) |
55 | |
{ |
56 | 0 | throw new ObjectNotFoundException(key.toString()); |
57 | |
} |
58 | 0 | else if (homeObject instanceof EJBHome) |
59 | |
{ |
60 | |
|
61 | 0 | Method method = ClassUtils.getMethod(homeObject.getClass(), "create", null); |
62 | 0 | if (method == null) |
63 | |
{ |
64 | 0 | throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException( |
65 | |
EjbMessages.ejbObjectMissingCreate(key).toString())); |
66 | |
} |
67 | |
try |
68 | |
{ |
69 | 0 | return method.invoke(homeObject, ClassUtils.NO_ARGS); |
70 | |
} |
71 | 0 | catch (Exception e) |
72 | |
{ |
73 | 0 | throw new ObjectNotFoundException(key.toString(), e); |
74 | |
} |
75 | |
} |
76 | |
else |
77 | |
{ |
78 | 0 | throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException( |
79 | |
EjbMessages.ejbKeyRefNotValid(key).toString())); |
80 | |
} |
81 | |
} |
82 | |
} |