|
1 |
| package net.sf.crispy.proxy; |
|
2 |
| |
|
3 |
| import java.util.Properties; |
|
4 |
| |
|
5 |
| import net.sf.crispy.InvocationStrategy; |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| public class StaticProxyDecorator extends StaticProxy { |
|
13 |
| |
|
14 |
| private StaticProxy staticProxy = null; |
|
15 |
| |
|
16 |
181
| public StaticProxyDecorator(StaticProxy pvStaticProxy) {
|
|
17 |
181
| setStaticProxy(pvStaticProxy);
|
|
18 |
| } |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
191
| public Object newInstance(Class pvClass) {
|
|
26 |
191
| Properties lvProperties = new Properties(getProperties());
|
|
27 |
191
| lvProperties.put(PROPERTY_CURRENT_INTERFACE_CLASS, pvClass.getName());
|
|
28 |
191
| InvocationStrategy lvDefaultInvocationStrategy = getDefaultInvocationStrategy(lvProperties);
|
|
29 |
190
| getStaticProxy().setInvocationStrategy(lvDefaultInvocationStrategy);
|
|
30 |
190
| try {
|
|
31 |
190
| Object lvInvocationStrategy = Proxy.createInvocationStrategy(lvDefaultInvocationStrategy ,
|
|
32 |
| getProperties(), getStaticProxy().getDefaultUrlAndPort(), |
|
33 |
| pvClass, null); |
|
34 |
190
| getStaticProxy().setInvocationStrategy(lvInvocationStrategy);
|
|
35 |
| } catch (Exception e) { |
|
36 |
| if (log.isWarnEnabled()) { |
|
37 |
| log.warn("Error by create InvocationStrategy for Class: " + pvClass, e); |
|
38 |
| } |
|
39 |
| } |
|
40 |
| |
|
41 |
190
| Object lvReturn = getStaticProxy().newInstance(pvClass);
|
|
42 |
183
| return lvReturn;
|
|
43 |
| } |
|
44 |
| |
|
45 |
181
| public final void setStaticProxy(StaticProxy pvStaticProxy) { staticProxy = pvStaticProxy; }
|
|
46 |
957
| public StaticProxy getStaticProxy() { return staticProxy; }
|
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
381
| public Properties getProperties() { return staticProxy.getProperties(); }
|
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
180
| public void setProperties(Properties pvProperties) { staticProxy.setProperties(pvProperties); }
|
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
1
| public Class getProxyClass() { return staticProxy.getProxyClass(); }
|
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
1
| public Object getProxyObject() { return staticProxy.getProxyObject(); }
|
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
1
| public String getDefaultUrlAndPort() {
|
|
77 |
1
| return getStaticProxy().getDefaultUrlAndPort();
|
|
78 |
| } |
|
79 |
| |
|
80 |
191
| public InvocationStrategy getDefaultInvocationStrategy(Properties pvProperties) {
|
|
81 |
191
| return getStaticProxy().getDefaultInvocationStrategy(pvProperties);
|
|
82 |
| } |
|
83 |
| |
|
84 |
| } |