wiki:ExampleUsingConverterRegistry

Using Third Party Types in your API

Sometimes it is dicouraged to have any XML-RPC or Delight reference in an interface class. In order to still use this interface with Delight a ParameterConverterRegistry has been introduced. See also ExampleUsingThirdPartyTypes.

*** SOMETIMES DISCOURAGED ***
@ConverterMappings( 
      @Mapping(type=URL.class,converter=URLConverter.class) 
)
public interface Api
{
    URL getHomepageLocation();
    void addSite( URL url );
}

Alternative with ParameterConverterRegistry:

public interface Api
{
    URL getHomepageLocation();
    void addSite( URL url );
}

Now, without having to annotate the interface invoking the methods looks like this:

ParameterConverterRegistry.setParameterConverterForClass( URL.class, URLConverter.class );
Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port );

URL homepageUrl = remote_api.getHomepageLocation();
InputStream is = homepageUrl.openStream();
...

remote_api.addSite( new URL( "http://middle.of.nowhere" ) );

...

NOTE: Client AND Server have to register the converter prior to a remote call.

Last modified 15 years ago Last modified on 07/28/09 18:21:07