|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| package net.sf.crispy.proxy; |
|
6 |
| |
|
7 |
| import java.lang.reflect.Method; |
|
8 |
| import java.util.Hashtable; |
|
9 |
| import java.util.Map; |
|
10 |
| import java.util.Properties; |
|
11 |
| |
|
12 |
| import net.sf.crispy.InvocationException; |
|
13 |
| import net.sf.crispy.InvocationStrategy; |
|
14 |
| import net.sf.crispy.Property; |
|
15 |
| |
|
16 |
| import org.apache.commons.logging.Log; |
|
17 |
| import org.apache.commons.logging.LogFactory; |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| public abstract class Proxy { |
|
26 |
| |
|
27 |
| protected static final Log log = LogFactory.getLog (Proxy.class); |
|
28 |
| |
|
29 |
| |
|
30 |
| private Class proxyClass = null; |
|
31 |
| private Object proxyObject = null; |
|
32 |
| private Properties properties = new Properties(); |
|
33 |
| |
|
34 |
| |
|
35 |
848
| public void setProxyClass(Class pvClazz) { proxyClass = pvClazz; }
|
|
36 |
937
| public Class getProxyClass() { return proxyClass; }
|
|
37 |
| |
|
38 |
720
| public void setProxyObject(Object pvProxyObject) { proxyObject = pvProxyObject; }
|
|
39 |
1078
| public Object getProxyObject() { return proxyObject; }
|
|
40 |
| |
|
41 |
564
| public void setProperties(Properties pvProperties) { properties = pvProperties; }
|
|
42 |
727
| public Properties getProperties() { return properties; }
|
|
43 |
| |
|
44 |
| public abstract Object newInstance (Class pvClass); |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
558
| public static Object createInvocationStrategy (final InvocationStrategy pvDefaultInvocationStrategy,
|
|
50 |
| final Properties pvProperties, final String pvDefaultUrlAndPort, |
|
51 |
| final Class pvProxyClass, final Method pvMethod) throws Exception { |
|
52 |
| |
|
53 |
| |
|
54 |
558
| InvocationStrategy lvInvocationStrategy = pvDefaultInvocationStrategy;
|
|
55 |
| |
|
56 |
558
| String lvClassStrInvocationStrategy = pvProperties.getProperty(Property.INVOCATION_STRATEGY);
|
|
57 |
558
| if (lvClassStrInvocationStrategy != null) {
|
|
58 |
10
| Class lvStrategyClass = Class.forName(lvClassStrInvocationStrategy);
|
|
59 |
10
| try {
|
|
60 |
10
| lvInvocationStrategy = (InvocationStrategy) lvStrategyClass.newInstance();
|
|
61 |
| } catch (Exception e) { |
|
62 |
1
| throw new InvocationException("Can't create instance for InvocationStrategy-Class: "
|
|
63 |
| + lvStrategyClass + " (" + e + ")!"); |
|
64 |
| } |
|
65 |
| } |
|
66 |
| |
|
67 |
| |
|
68 |
557
| if (lvInvocationStrategy != null) {
|
|
69 |
450
| Map lvInvStrategyProps = new Hashtable(4);
|
|
70 |
450
| lvInvStrategyProps.put(InvocationStrategy.CLASS_NAME, pvProxyClass.getName());
|
|
71 |
450
| if (pvMethod != null) {
|
|
72 |
307
| lvInvStrategyProps.put(InvocationStrategy.METHOD_NAME, pvMethod.getName());
|
|
73 |
| } |
|
74 |
450
| String lvConstNameSpace = pvProperties.getProperty(Property.INVOCATION_STRATEGY_NAMESPACE);
|
|
75 |
450
| if (lvConstNameSpace != null) {
|
|
76 |
2
| lvInvStrategyProps.put(InvocationStrategy.CONST_NAMESPACE, lvConstNameSpace);
|
|
77 |
| } |
|
78 |
450
| String lvUrl = pvProperties.getProperty(Property.REMOTE_URL_AND_PORT);
|
|
79 |
450
| if (lvUrl == null) {
|
|
80 |
302
| lvUrl = pvDefaultUrlAndPort;
|
|
81 |
| } |
|
82 |
450
| lvInvStrategyProps.put(InvocationStrategy.URL, lvUrl);
|
|
83 |
450
| return lvInvocationStrategy.convert(lvInvStrategyProps);
|
|
84 |
| } |
|
85 |
| |
|
86 |
| if (log.isDebugEnabled()) { |
|
87 |
| log.debug("No InvocationStrategy: " + pvProxyClass + " / " + pvMethod + ")"); |
|
88 |
| } |
|
89 |
107
| return null;
|
|
90 |
| } |
|
91 |
| |
|
92 |
| |
|
93 |
| } |