1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package com.mjh.switchrmi;
28
29 import java.lang.reflect.Method;
30
31 import java.util.HashMap;
32
33 import javax.naming.*;
34
35 import org.apache.log4j.Logger;
36
37 public class RmiClientInvocationHandler
38 extends RmiInvocationHandlerBase
39 {
40 private static final Logger log =
41 Logger.getLogger(RmiClientInvocationHandler.class.getName());
42 private String targetUrl;
43 private String protocolName;
44 private RmiContext context;
45 private RmiHandler handler;
46 private Context jndiContext;
47
48 public RmiClientInvocationHandler(String url, Class[] intrfaces)
49 {
50 super(intrfaces);
51 targetUrl = url;
52 }
53
54 public RmiClientInvocationHandler(String url, Class[] intrfaces,
55 String protocolName, Context ctx)
56 {
57 this(url, intrfaces);
58 this.protocolName = protocolName;
59 jndiContext = ctx;
60 }
61
62 private void init() throws Exception
63 {
64 context = new RmiContextImpl(false, targetUrl, jndiContext,
65 protocolName);
66 handler = new RmiHandler();
67 }
68
69 public Object rmiInvoke(Object target, Method method, Object[] args)
70 throws Throwable
71 {
72 if (context == null)
73 {
74 init();
75 }
76
77 return handler.clientInvoke(method, args, context);
78 }
79
80 public String toString()
81 {
82 return "RmiClientInvocationHandler(url=" + targetUrl + ")";
83 }
84 }