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 * Make of the server the invocation from services.
24 *
25 * @author Linke
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 public final void setNullValue (String pvNullValue) {
38 nullValue = pvNullValue;
39 }
40 public final String getNullValue() {
41 return nullValue;
42 }
43
44
45 public XmlRpcConvertHandler(Object pvObject, String pvNullValue) {
46 object = pvObject;
47 setNullValue(pvNullValue);
48 serviceEndpoint = new ServiceEndpointImpl();
49 }
50
51 public XmlRpcConvertHandler(Object pvObject, String pvNullValue, ServiceEndpoint pvServiceEndpoint) {
52 object = pvObject;
53 setNullValue(pvNullValue);
54 serviceEndpoint = pvServiceEndpoint;
55 }
56
57
58 /**
59 * @see org.apache.xmlrpc.XmlRpcHandler#execute(java.lang.String, java.util.Vector)
60 */
61 public Object execute(String pvMethod, Vector pvParams) throws Exception {
62 String lvMethodName = pvMethod.substring(pvMethod.lastIndexOf('.') + 1);
63 Converter lvConverter = new Converter(getNullValue());
64 lvConverter.setWithSimpleKeyMapper(true);
65 Method lvMethod = Invoker.findMethod(object.getClass(), lvMethodName, pvParams);
66 Object[] lvArgs = Invoker.vector2Array(pvParams, lvMethod, lvConverter);
67
68 InterceptorHandler lvHandler = serviceEndpoint.createNewInterceptorHandlerInstance();
69 Object ret = serviceEndpoint.doInvoke(object, lvMethod, lvArgs, lvHandler);
70 ret = ExceptionWrapper.isThrowableThanHandleThrowable(ret);
71 ret = lvConverter.makeSimple(ret);
72 return ret;
73 }
74
75 }