| 1 | == Using own concete types == |
| 2 | |
| 3 | === Server side === |
| 4 | |
| 5 | |
| 6 | |
| 7 | {{{ |
| 8 | public interface Api |
| 9 | { |
| 10 | Param returnParam(); |
| 11 | |
| 12 | void passAsParameter( Param p ); |
| 13 | } |
| 14 | |
| 15 | public class Impl implements Api |
| 16 | { |
| 17 | public Param returnParam() { return new ParamImpl( ... ); } |
| 18 | |
| 19 | void passAsParameter( Param p ) {} |
| 20 | } |
| 21 | |
| 22 | }}} |
| 23 | |
| 24 | To use type Param, we have to make it XML-RPC compliant. We use java annotations and |
| 25 | user-defined conversion operations to do this. |
| 26 | |
| 27 | - the @!XmlRpc annotation declares that type Param uses XML-RPC type ARRAY as transport representation |
| 28 | |
| 29 | - The interface {{{Convertable}} declares what specific java type is used for transfer via XML-RPC |
| 30 | |
| 31 | - toXmlRpc converts an instance of type Param into its XML-RPC representation |
| 32 | |
| 33 | - the constructor creates an instance of type Param back from it's XML-RPC representation |
| 34 | |
| 35 | {{{ |
| 36 | @XmlRpc( type=Type.ARRAY ) |
| 37 | public class Param |
| 38 | implements Convertable<Collection<String>> |
| 39 | { |
| 40 | public Param( Collection<String> xmlRpcRepresentation ) { ... } |
| 41 | |
| 42 | public Collection<String> toXmlRpc() { return ... } |
| 43 | } |
| 44 | }}} |
| 45 | |
| 46 | Now our type ist XML-RPC compliant! |
| 47 | |
| 48 | === Client Side === |
| 49 | |
| 50 | Our client can be used without any extra statements: |
| 51 | {{{ |
| 52 | Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port ); |
| 53 | |
| 54 | Param p = remote_api.returnParam(); |
| 55 | |
| 56 | Param asParam = ...; |
| 57 | remote_api.passAsParameter( asParam ); |
| 58 | |
| 59 | ... |
| 60 | }}} |