Changes between Version 4 and Version 5 of ExampleUsingThirdPartyTypes


Ignore:
Timestamp:
10/09/06 17:12:45 (18 years ago)
Author:
lauer
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExampleUsingThirdPartyTypes

    v4 v5  
    2828public class URLConverter implements ParameterConverter<URL, String> 
    2929{ 
    30     /** Converter uses XML-RPC type {@value XmlRpc.Type.STRING} as XML-RPC representation.*/ 
    31     public Type getXmlRpcRepresentationType() 
    32     { 
    33         return( XmlRpc.Type.STRING ); 
    34     } 
     30    public Type getXmlRpcRepresentationType() { return( XmlRpc.Type.STRING ); } 
    3531     
    3632    public URL createFrom( String xmlRepresentation ) 
    3733        throws TypeConversionException 
    38     { 
    39         URL url = null; 
    40         try 
    41         { 
    42             url = new URL( xmlRepresentation ); 
    43         } 
    44         catch( MalformedURLException e ) 
    45         { 
    46             throw( new TypeConversionException( e ) ); 
    47         } 
    48         return( url ); 
     34    {  ... 
    4935    } 
    5036 
     
    7258See also: [http://delight.opendfki.de/wiki/ExampleUsingOwnConceteTypes#UsingowntypesinCollectionsandMaps How to use own types contained in Collections an Maps]. 
    7359 
    74 == Using !XmlRpcBeans in you API == 
    75  
    76 What are !XmlRpcBeans?? 
    77  
    78 Sometimes parameter conversion is a straight-forward task which can be handed over to the XML-RPC runtime system. 
    79 When a java class fulfills certain conditions (roughly, being a java bean with compatible types) it can be turned into a !XmlRpcBean 
    80 by annotating it with the @!XmlRpcBean annotation. It then can be used in every XML-RPC call without restriction.[[BR]] 
    81  
    82 A !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  
    96 Technically, 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  
    99 Lets 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) ) 
    103 public 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  
    133 Again, the client has no restrictions using the bean class: 
    134 {{{ 
    135 public interface Api 
    136 { 
    137     @Contains(CoffeeBean.class) 
    138     Collection<CoffeeBean> getAllBeans(); 
    139 } 
    140  
    141 ---- 
    142  
    143 Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port ); 
    144  
    145 Collection<CoffeeBean> beans = remote_api.getAllBeans(); 
    146  
    147 for( CoffeeBeans b: beans ) 
    148 { 
    149     System.out.println( "Bean of type " + b.getType() + " comes from " + b.getOrigin() ); 
    150 } 
    151 ... 
    152 }}} 
    153  
    154 See also [http://delight.opendfki.de/wiki/ExampleUsingOwnConceteTypes#UsingowntypesinCollectionsandMaps How to use own types in Collections an Maps]. 
    155  
    15660Examples in source code: [http://delight.opendfki.de/repos/trunk/XmlRpcDelight/src/examples/de/dfki/util/xmlrpc/examples/external_types/]