Changes between Version 3 and Version 4 of ExampleUsingThirdPartyTypes


Ignore:
Timestamp:
10/09/06 14:59:57 (18 years ago)
Author:
lauer
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExampleUsingThirdPartyTypes

    v3 v4  
    7272See also: [http://delight.opendfki.de/wiki/ExampleUsingOwnConceteTypes#UsingowntypesinCollectionsandMaps How to use own types contained in Collections an Maps]. 
    7373 
     74== Using !XmlRpcBeans in you API == 
     75 
     76What are !XmlRpcBeans?? 
     77 
     78Sometimes parameter conversion is a straight-forward task which can be handed over to the XML-RPC runtime system. 
     79When a java class fulfills certain conditions (roughly, being a java bean with compatible types) it can be turned into a !XmlRpcBean 
     80by annotating it with the @!XmlRpcBean annotation. It then can be used in every XML-RPC call without restriction.[[BR]] 
     81 
     82A !XmlRpcBean must have 
     83 
     84  - a public constructor taking no arguments 
     85 
     86  - like a java bean: for each property which is supposed to be transported over XML-RPC there has to exist a public getter and setter method 
     87 
     88  - each property type has to be a XML-RPC compliant type, that is it has to have one of the follwoing properties: 
     89    - it is a standard XML-RPC type 
     90    - it is annotated with a @!XmlRpc annotation and defines proper conversion methods 
     91    - a conversion mapping for that type is put at the !XmlRpcBean (which then acts as an API itself) 
     92    - it is an !XmlRpcBean (that is, !XmlRpcBeans can be nested) 
     93    - it is a Collection or Map containing a type which is XML-RPC compliant and is annotated with the @Contains annotation 
     94 
     95 
     96Technically, an !XmlRpcBean is converted into a XML-RPC STRUCT. The field names of the tranfered map are the property names derived from the bean class. 
     97 
     98 
     99Lets look at an example !XmlRpcBean (note that this bean also defines a converter mapping for type ''URL''): 
     100{{{ 
     101@XmlRpcBean 
     102@ConverterMappings( @Mapping(type=URL.class,converter=URLConverter.class) ) 
     103public class CoffeeBean 
     104{ 
     105    public URL getOrigin() 
     106    { 
     107        return mOrigin; 
     108    } 
     109    public void setOrigin( URL origin ) 
     110    { 
     111        mOrigin = origin; 
     112    } 
     113    public String getType() 
     114    { 
     115        return mType; 
     116    } 
     117    public void setType( String type ) 
     118    { 
     119        mType = type; 
     120    } 
     121     
     122    public String toString() 
     123    { 
     124        return( "CoffeeBean(" + getType() + ") comming from '" + getOrigin() + "'" ); 
     125    } 
     126    private String mType; 
     127    private URL mOrigin; 
     128} 
     129}}} 
     130 
     131== Client side == 
     132 
     133Again, the client has no restrictions using the bean class: 
     134{{{ 
     135public interface Api 
     136{ 
     137    @Contains(CoffeeBean.class) 
     138    Collection<CoffeeBean> getAllBeans(); 
     139} 
     140 
     141---- 
     142 
     143Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port ); 
     144 
     145Collection<CoffeeBean> beans = remote_api.getAllBeans(); 
     146 
     147for( CoffeeBeans b: beans ) 
     148{ 
     149    System.out.println( "Bean of type " + b.getType() + " comes from " + b.getOrigin() ); 
     150} 
     151... 
     152}}} 
     153 
     154See also [http://delight.opendfki.de/wiki/ExampleUsingOwnConceteTypes#UsingowntypesinCollectionsandMaps How to use own types in Collections an Maps]. 
     155 
     156Examples in source code: [http://delight.opendfki.de/repos/trunk/XmlRpcDelight/src/examples/de/dfki/util/xmlrpc/examples/external_types/]