Changes between Version 3 and Version 4 of ExampleUsingOwnInterfaceTypes


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

--

Legend:

Unmodified
Added
Removed
Modified
  • ExampleUsingOwnInterfaceTypes

    v3 v4  
    11== Using Interface Types and Abstract Classes == 
    2  
    3 See also: [http://delight.opendfki.de/wiki/ExampleUsingOwnConceteTypes#UsingowntypesinCollectionsandMaps How to use own types contained in Collections an Maps]. 
    42 
    53The API is defined the same way as in the [wiki:ExampleUsingOwnConceteTypes preceeding use case]. 
     
    5654... 
    5755}}} 
     56 
     57== Using !XmlRpcBeans in you API == 
     58 
     59What are !XmlRpcBeans?? 
     60 
     61Sometimes parameter conversion is a straight-forward task which can be handed over to the XML-RPC runtime system. 
     62When a java class fulfills certain conditions (roughly, being a java bean with compatible types) it can be turned into a !XmlRpcBean 
     63by annotating it with the @!XmlRpcBean annotation. It then can be used in every XML-RPC call without restriction.[[BR]] 
     64 
     65A !XmlRpcBean must have 
     66 
     67  - a public constructor taking no arguments 
     68 
     69  - 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 
     70 
     71  - each property type has to be a XML-RPC compliant type, that is it has to have one of the follwoing properties: 
     72    - it is a standard XML-RPC type 
     73    - it is annotated with a @!XmlRpc annotation and defines proper conversion methods 
     74    - a conversion mapping for that type is put at the !XmlRpcBean (which then acts as an API itself) 
     75    - it is an !XmlRpcBean (that is, !XmlRpcBeans can be nested) 
     76    - it is a Collection or Map containing a type which is XML-RPC compliant and is annotated with the @Contains annotation 
     77 
     78 
     79Technically, 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. 
     80 
     81 
     82Lets look at an example !XmlRpcBean (note that this bean also defines a converter mapping for type ''URL''): 
     83{{{ 
     84@XmlRpcBean 
     85@ConverterMappings( @Mapping(type=URL.class,converter=URLConverter.class) ) 
     86public class CoffeeBean 
     87{ 
     88    public URL getOrigin() 
     89    { 
     90        return mOrigin; 
     91    } 
     92    public void setOrigin( URL origin ) 
     93    { 
     94        mOrigin = origin; 
     95    } 
     96    public String getType() 
     97    { 
     98        return mType; 
     99    } 
     100    public void setType( String type ) 
     101    { 
     102        mType = type; 
     103    } 
     104     
     105    public String toString() 
     106    { 
     107        return( "CoffeeBean(" + getType() + ") comming from '" + getOrigin() + "'" ); 
     108    } 
     109    private String mType; 
     110    private URL mOrigin; 
     111} 
     112}}} 
     113 
     114== Client side == 
     115 
     116Again, the client has no restrictions using the bean class: 
     117{{{ 
     118public interface Api 
     119{ 
     120    @Contains(CoffeeBean.class) 
     121    Collection<CoffeeBean> getAllBeans(); 
     122} 
     123 
     124---- 
     125 
     126Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port ); 
     127 
     128Collection<CoffeeBean> beans = remote_api.getAllBeans(); 
     129 
     130for( CoffeeBeans b: beans ) 
     131{ 
     132    System.out.println( "Bean of type " + b.getType() + " comes from " + b.getOrigin() ); 
     133} 
     134... 
     135}}} 
     136 
     137See also [http://delight.opendfki.de/wiki/ExampleUsingOwnConceteTypes#UsingowntypesinCollectionsandMaps How to use own types in Collections an Maps]. 
     138 
     139Examples in source code: [http://delight.opendfki.de/repos/trunk/XmlRpcDelight/src/examples/de/dfki/util/xmlrpc/examples/interfaces/]