| | 1 | == Using Third Party Types in your API == |
| | 2 | |
| | 3 | Sometimes it is dicouraged to have any XML-RPC or Delight reference in an interface class. In order to still use this interface |
| | 4 | with Delight a {{{ParameterConverterRegistry}}} has been introduced. See also [wiki:ExampleUsingThirdPartyTypes]. |
| | 5 | |
| | 6 | {{{ |
| | 7 | *** SOMETIMES DISCOURAGED *** |
| | 8 | @ConverterMappings( |
| | 9 | @Mapping(type=URL.class,converter=URLConverter.class) |
| | 10 | ) |
| | 11 | public interface Api |
| | 12 | { |
| | 13 | URL getHomepageLocation(); |
| | 14 | void addSite( URL url ); |
| | 15 | } |
| | 16 | }}} |
| | 17 | |
| | 18 | Alternative with '''ParameterConverterRegistry:''' |
| | 19 | |
| | 20 | {{{ |
| | 21 | public interface Api |
| | 22 | { |
| | 23 | URL getHomepageLocation(); |
| | 24 | void addSite( URL url ); |
| | 25 | } |
| | 26 | }}} |
| | 27 | |
| | 28 | Now, without having to annotate the interface invoking the methods looks like this: |
| | 29 | {{{ |
| | 30 | ParameterConverterRegistry.setParameterConverterForClass( URL.class, URLConverter.class ); |
| | 31 | Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port ); |
| | 32 | |
| | 33 | URL homepageUrl = remote_api.getHomepageLocation(); |
| | 34 | InputStream is = homepageUrl.openStream(); |
| | 35 | ... |
| | 36 | |
| | 37 | remote_api.addSite( new URL( "http://middle.of.nowhere" ) ); |
| | 38 | |
| | 39 | ... |
| | 40 | }}} |
| | 41 | |
| | 42 | '''NOTE:''' Client '''AND''' Server have to register the converter prior to a remote call. |