|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| package net.sf.crispy.impl; |
|
6 |
| |
|
7 |
| import java.beans.BeanInfo; |
|
8 |
| import java.beans.Introspector; |
|
9 |
| import java.beans.MethodDescriptor; |
|
10 |
| import java.lang.reflect.Method; |
|
11 |
| |
|
12 |
| import javax.naming.InitialContext; |
|
13 |
| import javax.naming.NamingException; |
|
14 |
| import javax.rmi.PortableRemoteObject; |
|
15 |
| |
|
16 |
| import net.sf.crispy.InvocationException; |
|
17 |
| import net.sf.crispy.Property; |
|
18 |
| import net.sf.crispy.proxy.StaticProxy; |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| public class StaticEjbProxy extends StaticProxy { |
|
27 |
| |
|
28 |
| private InitialContext initialContext = null; |
|
29 |
| |
|
30 |
18
| public StaticEjbProxy () {}
|
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
19
| public String getDefaultUrlAndPort() {
|
|
38 |
19
| return null;
|
|
39 |
| } |
|
40 |
| |
|
41 |
19
| public Object newInstance (Class pvClass) {
|
|
42 |
19
| return createProxy(pvClass);
|
|
43 |
| } |
|
44 |
| |
|
45 |
19
| private Object createProxy (Class pvProxyClass) {
|
|
46 |
| |
|
47 |
19
| try {
|
|
48 |
19
| initialContext = new InitialContext(getProperties());
|
|
49 |
| } catch (NamingException e) { |
|
50 |
0
| throw new InvocationException("Exception by the InitialContext", e);
|
|
51 |
| } |
|
52 |
| |
|
53 |
19
| String lvJndi = getProperties().getProperty(pvProxyClass.getName());
|
|
54 |
19
| if (lvJndi == null) {
|
|
55 |
1
| throw new InvocationException("For the Class: " + pvProxyClass.getName() + " is no JNDI-Entry.");
|
|
56 |
| } |
|
57 |
18
| Object lvHome = null;
|
|
58 |
| |
|
59 |
18
| try {
|
|
60 |
18
| lvHome = initialContext.lookup(lvJndi);
|
|
61 |
| } catch (NamingException e) { |
|
62 |
1
| throw new InvocationException("Exception by JNDI-lookup: " + lvJndi, e);
|
|
63 |
| } |
|
64 |
| |
|
65 |
17
| if (lvHome == null) {
|
|
66 |
0
| throw new InvocationException("For the JNDI-Entry " + lvJndi + " exist no HomeInterface.");
|
|
67 |
| } |
|
68 |
17
| String lvEjbHomeStr = getProperties().getProperty(pvProxyClass.getName() + Property.EJB_HOME_INTERFACE);
|
|
69 |
17
| try {
|
|
70 |
17
| Class lvEjbHomeClass = Class.forName(lvEjbHomeStr);
|
|
71 |
15
| lvHome = PortableRemoteObject.narrow(lvHome, lvEjbHomeClass);
|
|
72 |
| } catch (Exception e) { |
|
73 |
2
| throw new InvocationException("Exception by loading HomeInterface: " + lvEjbHomeStr
|
|
74 |
| + " (please check your properties and set the Home-Interface:" + |
|
75 |
| "ServiceName + Property.EJB_HOME_INTERFACE - Home-Interface)", e); |
|
76 |
| } |
|
77 |
15
| if (lvHome == null) {
|
|
78 |
0
| throw new InvocationException("With PortableRemoteObject.narrow can not create the HomeInterface: "
|
|
79 |
| + lvJndi + " " + pvProxyClass.getName()); |
|
80 |
| } |
|
81 |
| |
|
82 |
15
| try {
|
|
83 |
15
| BeanInfo beanInfo = Introspector.getBeanInfo(lvHome.getClass());
|
|
84 |
15
| MethodDescriptor lvMethodDescriptor[] = beanInfo.getMethodDescriptors();
|
|
85 |
180
| for (int i = 0; i < lvMethodDescriptor.length; i++) {
|
|
86 |
180
| Method lvMethod = lvMethodDescriptor[i].getMethod();
|
|
87 |
180
| if (lvMethod.getName().equals("create")) {
|
|
88 |
15
| setProxyObject(lvMethod.invoke(lvHome, null));
|
|
89 |
15
| setProxyClass(getProxyObject().getClass());
|
|
90 |
15
| return getProxyObject();
|
|
91 |
| } |
|
92 |
| } |
|
93 |
| } catch (Exception e) { |
|
94 |
0
| throw new InvocationException("Exception by Introspector, by search of create()-Method from: "
|
|
95 |
| + lvHome.getClass().getName(), e); |
|
96 |
| } |
|
97 |
| |
|
98 |
0
| return getProxyObject();
|
|
99 |
| |
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
| } |