|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| package net.sf.crispy.impl; |
|
5 |
| |
|
6 |
| import java.rmi.Naming; |
|
7 |
| import java.util.Properties; |
|
8 |
| |
|
9 |
| import net.sf.crispy.InvocationException; |
|
10 |
| import net.sf.crispy.InvocationStrategy; |
|
11 |
| import net.sf.crispy.proxy.StaticProxy; |
|
12 |
| import net.sf.crispy.strategy.NameInvocationStrategy; |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| public class StaticRmiProxy extends StaticProxy { |
|
21 |
| |
|
22 |
| public final static String DEFAULT_URL_AND_PORT = "rmi://localhost:1098"; |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
77
| public String getDefaultUrlAndPort() {
|
|
30 |
77
| return DEFAULT_URL_AND_PORT;
|
|
31 |
| } |
|
32 |
| |
|
33 |
39
| public InvocationStrategy getDefaultInvocationStrategy(Properties pvProperties) {
|
|
34 |
39
| String lvInterfaceClassName = (String) pvProperties.get(PROPERTY_CURRENT_INTERFACE_CLASS);
|
|
35 |
39
| String lvLookupName = getProperties().getProperty(lvInterfaceClassName);
|
|
36 |
39
| if (lvLookupName == null) {
|
|
37 |
1
| throw new InvocationException("For the Class: " + lvInterfaceClassName + " is no RMI-Entry exist " +
|
|
38 |
| "(LookUp-Name: " + lvLookupName + ")."); |
|
39 |
| } |
|
40 |
38
| return new NameInvocationStrategy(lvLookupName);
|
|
41 |
| } |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
38
| public Object newInstance(Class pvProxyClass) {
|
|
48 |
38
| String lvLookupStr = getUrlAndPort() + "/" + getInvocationStrategy();
|
|
49 |
| if (log.isDebugEnabled()) { log.debug("StaticRmiProxy LookUp-String: " + lvLookupStr); } |
|
50 |
38
| try {
|
|
51 |
38
| Object lvProxyObject = Naming.lookup(lvLookupStr);
|
|
52 |
36
| setProxyObject(lvProxyObject);
|
|
53 |
36
| setProxyClass(lvProxyObject.getClass());
|
|
54 |
| } catch (Exception e) { |
|
55 |
2
| throw new InvocationException("Error in newInstance in StaticRmiProxy: " + e, e);
|
|
56 |
| } |
|
57 |
36
| return getProxyObject();
|
|
58 |
| } |
|
59 |
| |
|
60 |
| |
|
61 |
| } |