CompositeProxyFactory.java
biz/hammurapi/util/CompositeProxyFactory.java
Violations
Inspector |
Message |
Severity |
Location |
Java Inspector 002 |
Empty catch block. |
1 |
90:59
|
Java Inspector 048 |
Copyrights information should be present in each file. |
1 |
|
Java Inspector 089 |
Type is not documented |
2 |
44:9
|
Java Inspector 089 |
Undocumented parameter classLoader |
2 |
73:9
|
Java Inspector 089 |
Undocumented method |
2 |
78:9
|
Java Inspector 089 |
Undocumented method |
2 |
83:41
|
Java Inspector 089 |
Undocumented method |
2 |
101:9
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
95:81
|
Java Inspector 046 |
Empty statements |
3 |
90:91
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23package biz.hammurapi.util;
24
25import java.lang.reflect.InvocationHandler;
26import java.lang.reflect.Method;
27import java.lang.reflect.Proxy;
28
29
30
31
32
33
34
35
36
37
38public class CompositeProxyFactory {
39
40
41
42
43
44 public interface TargetFactory {
45
46
47
48
49
50
51 Class getTargetClass();
52
53
54
55
56 Object getTarget();
57 }
58
59 private ClassLoader classLoader;
60
61
62
63
64 public CompositeProxyFactory() {
65 super();
66 classLoader=getClass().getClassLoader();
67 }
68
69
70
71
72
73 public CompositeProxyFactory(ClassLoader classLoader) {
74 super();
75 this.classLoader=classLoader;
76 }
77
78 public static Object createProxy(ClassLoader classLoader, Class[] interfaces, final TargetFactory[] targetFactories) {
79 return Proxy.newProxyInstance(
80 classLoader,
81 interfaces,
82 new InvocationHandler() {
83 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
84 for (int i=0; i<targetFactories.length; i++) {
85 try {
86 return targetFactories[i]
87 .getTargetClass()
88 .getMethod(method.getName(), method.getParameterTypes())
89 .invoke(targetFactories[i].getTarget(), args);
90 } catch (NoSuchMethodException e) {
91
92 }
93 }
94
95 throw new NoSuchMethodException("Method not found in targets: "+method);
96 }
97 });
98
99 }
100
101 public Object createProxy(Class[] interfaces, TargetFactory[] targetFactories) {
102 return createProxy(classLoader, interfaces, targetFactories);
103 }
104}
105