Changes between Version 1 and Version 2 of ExampleUsingOwnInterfaceTypes


Ignore:
Timestamp:
10/09/06 13:22:31 (18 years ago)
Author:
lauer
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExampleUsingOwnInterfaceTypes

    v1 v2  
     1== Using Interface Types and Abstract Classes == 
    12 
    2 See [http://delight.opendfki.de/wiki/ExampleUsingOwnConceteTypes#UsingowntypesinCollectionsandMaps How to use own typed in Collections an Maps]. 
     3See also: [http://delight.opendfki.de/wiki/ExampleUsingOwnConceteTypes#UsingowntypesinCollectionsandMaps How to use own typed in Collections an Maps]. 
     4 
     5The API is defined the same way as in the [wiki:ExampleUsingOwnConceteTypes preceeding use case]. 
     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 createParam( ... ); } 
     18     
     19    void passAsParameter( Param p ) { doSomethingWith( p ); } 
     20} 
     21}}} 
     22 
     23Since Param is an interface, the runtime system cannot create instances of this type without further information. 
     24We use the concrete attribute of the @!XmlRpc annotation to tell the Delight runtime-system what concrete type to use to create instances of type Param.[[BR]] 
     25 
     26In this case we use the concete class ''!ParamImpl'' to create instances of type Param (note that ''!ParamImpl'' has to be a Convertable and also has to implement ''Param''): 
     27{{{ 
     28@XmlRpc( type=Type.STRING,  
     29         concrete=ParamImpl.class ) 
     30public interface Param 
     31{ 
     32    public String printContent() { ... } 
     33} 
     34 
     35public class ParamImpl implements Param,  
     36                                    Convertable<String> 
     37{ 
     38    public ParamImpl( String xmlRpcRepresentation ) { processXmlRpc( xmlRpcRepresentation ); } 
     39 
     40    public String toXmlRpc() { return( createXmlRpcRep() ); } 
     41} 
     42}}} 
     43 
     44=== Client side === 
     45 
     46The client can be created and used without further actions to take. No factories to register. No configuration files to load. Just like a lokal call to the API. 
     47{{{ 
     48Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port ); 
     49 
     50Param p = remote_api.returnParam(); 
     51System.out.println( p.printContent() ); 
     52 
     53Param asParam = new ParamImpl(...); 
     54remote_api.passAsParameter( asParam ); 
     55 
     56... 
     57}}}