Changes between Initial Version and Version 1 of ExampleUsingOwnConceteTypes


Ignore:
Timestamp:
Oct 6, 2006, 4:37:24 PM (20 years ago)
Author:
lauer
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExampleUsingOwnConceteTypes

    v1 v1  
     1== Using own concete types ==
     2
     3=== Server side ===
     4
     5
     6
     7{{{
     8public interface Api
     9{
     10    Param returnParam();
     11   
     12    void passAsParameter( Param p );
     13}
     14
     15public class Impl implements Api
     16{
     17    public Param returnParam() { return new ParamImpl( ... ); }
     18   
     19    void passAsParameter( Param p ) {}
     20}
     21
     22}}}
     23
     24To use type Param, we have to make it XML-RPC compliant. We use java annotations and
     25user-defined conversion operations to do this.
     26
     27 - the @!XmlRpc annotation declares that type Param uses XML-RPC type ARRAY as transport representation
     28
     29 - The interface {{{Convertable}} declares what specific java type is used for transfer via XML-RPC
     30
     31 - toXmlRpc converts an instance of type Param into its XML-RPC representation
     32
     33 - the constructor creates an instance of type Param back from it's XML-RPC representation
     34
     35{{{
     36@XmlRpc( type=Type.ARRAY )     
     37public class Param
     38               implements Convertable<Collection<String>>
     39{
     40    public Param( Collection<String> xmlRpcRepresentation ) { ... }
     41
     42    public Collection<String> toXmlRpc() { return ... }
     43}
     44}}}
     45
     46Now our type ist XML-RPC compliant!
     47
     48=== Client Side ===
     49
     50Our client can be used without any extra statements:
     51{{{
     52Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port );
     53
     54Param p = remote_api.returnParam();
     55
     56Param asParam = ...;
     57remote_api.passAsParameter( asParam );
     58
     59...
     60}}}