|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| package net.sf.crispy.impl.xmlrpc; |
|
6 |
| |
|
7 |
| import java.lang.reflect.Method; |
|
8 |
| import java.util.Vector; |
|
9 |
| |
|
10 |
| import net.sf.crispy.ExceptionWrapper; |
|
11 |
| import net.sf.crispy.InterceptorHandler; |
|
12 |
| import net.sf.crispy.server.ServiceEndpoint; |
|
13 |
| import net.sf.crispy.server.ServiceEndpointImpl; |
|
14 |
| import net.sf.crispy.util.Converter; |
|
15 |
| import net.sf.crispy.util.Invoker; |
|
16 |
| |
|
17 |
| import org.apache.commons.logging.Log; |
|
18 |
| import org.apache.commons.logging.LogFactory; |
|
19 |
| import org.apache.xmlrpc.XmlRpcHandler; |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| public class XmlRpcConvertHandler implements XmlRpcHandler { |
|
29 |
| |
|
30 |
| protected static final Log log = LogFactory.getLog (XmlRpcConvertHandler.class); |
|
31 |
| |
|
32 |
| private Object object = null; |
|
33 |
| private String nullValue = null; |
|
34 |
| private ServiceEndpoint serviceEndpoint = null; |
|
35 |
| |
|
36 |
| |
|
37 |
39
| public final void setNullValue (String pvNullValue) {
|
|
38 |
39
| nullValue = pvNullValue;
|
|
39 |
| } |
|
40 |
81
| public final String getNullValue() {
|
|
41 |
81
| return nullValue;
|
|
42 |
| } |
|
43 |
| |
|
44 |
| |
|
45 |
35
| public XmlRpcConvertHandler(Object pvObject, String pvNullValue) {
|
|
46 |
35
| object = pvObject;
|
|
47 |
35
| setNullValue(pvNullValue);
|
|
48 |
35
| serviceEndpoint = new ServiceEndpointImpl();
|
|
49 |
| } |
|
50 |
| |
|
51 |
4
| public XmlRpcConvertHandler(Object pvObject, String pvNullValue, ServiceEndpoint pvServiceEndpoint) {
|
|
52 |
4
| object = pvObject;
|
|
53 |
4
| setNullValue(pvNullValue);
|
|
54 |
4
| serviceEndpoint = pvServiceEndpoint;
|
|
55 |
| } |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
81
| public Object execute(String pvMethod, Vector pvParams) throws Exception {
|
|
62 |
81
| String lvMethodName = pvMethod.substring(pvMethod.lastIndexOf('.') + 1);
|
|
63 |
81
| Converter lvConverter = new Converter(getNullValue());
|
|
64 |
81
| lvConverter.setWithSimpleKeyMapper(true);
|
|
65 |
81
| Method lvMethod = Invoker.findMethod(object.getClass(), lvMethodName, pvParams);
|
|
66 |
80
| Object[] lvArgs = Invoker.vector2Array(pvParams, lvMethod, lvConverter);
|
|
67 |
| |
|
68 |
80
| InterceptorHandler lvHandler = serviceEndpoint.createNewInterceptorHandlerInstance();
|
|
69 |
80
| Object ret = serviceEndpoint.doInvoke(object, lvMethod, lvArgs, lvHandler);
|
|
70 |
80
| ret = ExceptionWrapper.isThrowableThanHandleThrowable(ret);
|
|
71 |
80
| ret = lvConverter.makeSimple(ret);
|
|
72 |
80
| return ret;
|
|
73 |
| } |
|
74 |
| |
|
75 |
| } |