Changes between Initial Version and Version 1 of ExampleUsingConverterRegistry


Ignore:
Timestamp:
07/28/09 18:21:07 (15 years ago)
Author:
lauer
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExampleUsingConverterRegistry

    v1 v1  
     1== Using Third Party Types in your API == 
     2 
     3Sometimes it is dicouraged to have any XML-RPC or Delight reference in an interface class. In order to still use this interface 
     4with 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) 
     11public interface Api 
     12{ 
     13    URL getHomepageLocation(); 
     14    void addSite( URL url ); 
     15} 
     16}}} 
     17 
     18Alternative with '''ParameterConverterRegistry:''' 
     19 
     20{{{ 
     21public interface Api 
     22{ 
     23    URL getHomepageLocation(); 
     24    void addSite( URL url ); 
     25} 
     26}}} 
     27 
     28Now, without having to annotate the interface invoking the methods looks like this: 
     29{{{ 
     30ParameterConverterRegistry.setParameterConverterForClass( URL.class, URLConverter.class ); 
     31Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port ); 
     32 
     33URL homepageUrl = remote_api.getHomepageLocation(); 
     34InputStream is = homepageUrl.openStream(); 
     35... 
     36 
     37remote_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.