This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / fs_selfservice / java / biz / freeside / SelfService.java
1 package biz.freeside;
2
3 // see http://ws.apache.org/xmlrpc/client.html for these classes
4 import org.apache.xmlrpc.XmlRpcException;
5 import org.apache.xmlrpc.client.XmlRpcClient;
6 import org.apache.xmlrpc.client.XmlRpcClientConfig;
7 import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
8
9 import java.util.HashMap;
10 import java.util.List;
11 import java.net.URL;
12
13 public class SelfService extends XmlRpcClient {
14
15   public SelfService( String url ) throws Exception {
16     super();
17     XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
18     config.setServerURL(new URL( url ));
19     this.setConfig(config);
20   }
21
22   private String canonicalMethod ( String method ) {
23     String canonical = new String(method);
24     if (!canonical.startsWith( "FS.SelfService.XMLRPC." )) {
25       canonical = "FS.SelfService.XMLRPC." + canonical;
26     }
27     return canonical;
28   }
29
30   private HashMap testResponse ( Object toTest ) throws XmlRpcException {
31     if (! ( toTest instanceof HashMap )) {
32       throw new XmlRpcException("expected HashMap but got" + toTest.getClass());
33     }
34     return (HashMap) toTest;
35   }
36
37   public HashMap execute( String method, List params ) throws XmlRpcException {
38     return testResponse(super.execute( canonicalMethod(method), params ));
39   }
40
41   public HashMap execute( String method, Object[] params ) throws XmlRpcException {
42     return testResponse(super.execute( canonicalMethod(method), params ));
43   }
44
45   public HashMap execute( XmlRpcClientConfig config, String method, List params ) throws XmlRpcException {
46     return testResponse(super.execute( config, canonicalMethod(method), params ));
47   }
48
49   public HashMap execute( XmlRpcClientConfig config, String method, Object[] params ) throws XmlRpcException {
50     return testResponse(super.execute( config, canonicalMethod(method), params ));
51   }
52 }