1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package ch.elca.el4j.services.remoting;
19
20 import java.rmi.Remote;
21 import java.rmi.RemoteException;
22
23 import ch.elca.el4j.util.interfaceenrichment.EnrichmentDecorator;
24 import ch.elca.el4j.util.interfaceenrichment.MethodDescriptor;
25
26
27
28
29
30
31
32
33
34 public class RmiEnrichmentDecorator implements EnrichmentDecorator {
35
36
37
38 private static final Class REMOTE_CLASS = Remote.class;
39
40
41
42
43 private static final Class REMOTE_EXCEPTION_CLASS = RemoteException.class;
44
45
46
47
48
49 public String changedInterfaceName(String originalInterfaceName) {
50 return originalInterfaceName + "Rmi";
51 }
52
53
54
55
56 public Class[] changedExtendedInterface(Class[] extendedInterfaces) {
57 Class[] extendedInterfacesNew;
58 if (extendedInterfaces == null || extendedInterfaces.length == 0) {
59 extendedInterfacesNew = new Class[1];
60 extendedInterfacesNew[0] = REMOTE_CLASS;
61 } else {
62 extendedInterfacesNew = new Class[extendedInterfaces.length + 1];
63 for (int i = 0; i < extendedInterfaces.length; i++) {
64 if (REMOTE_CLASS.isAssignableFrom(extendedInterfaces[i])) {
65
66
67
68 return extendedInterfaces;
69 }
70 extendedInterfacesNew[i] = extendedInterfaces[i];
71 }
72 extendedInterfacesNew[extendedInterfacesNew.length - 1]
73 = REMOTE_CLASS;
74 }
75 return extendedInterfacesNew;
76 }
77
78
79
80
81 public MethodDescriptor changedMethodSignature(MethodDescriptor method) {
82 Class[] thrownExceptions = method.getThrownExceptions();
83
84 Class[] thrownExceptionsNew;
85 if (thrownExceptions == null || thrownExceptions.length == 0) {
86 thrownExceptionsNew = new Class[1];
87 thrownExceptionsNew[0] = REMOTE_EXCEPTION_CLASS;
88 } else {
89 thrownExceptionsNew = new Class[thrownExceptions.length + 1];
90 for (int i = 0; i < thrownExceptions.length; i++) {
91 if (thrownExceptions[i].isAssignableFrom(
92 REMOTE_EXCEPTION_CLASS)) {
93
94
95
96 return method;
97 }
98 thrownExceptionsNew[i] = thrownExceptions[i];
99 }
100 thrownExceptionsNew[thrownExceptionsNew.length - 1]
101 = REMOTE_EXCEPTION_CLASS;
102 }
103
104 method.setThrownExceptions(thrownExceptionsNew);
105 return method;
106 }
107 }