| 2 | | See [http://delight.opendfki.de/wiki/ExampleUsingOwnConceteTypes#UsingowntypesinCollectionsandMaps How to use own typed in Collections an Maps]. |
| | 3 | See also: [http://delight.opendfki.de/wiki/ExampleUsingOwnConceteTypes#UsingowntypesinCollectionsandMaps How to use own typed in Collections an Maps]. |
| | 4 | |
| | 5 | The API is defined the same way as in the [wiki:ExampleUsingOwnConceteTypes preceeding use case]. |
| | 6 | |
| | 7 | {{{ |
| | 8 | public interface Api |
| | 9 | { |
| | 10 | Param returnParam(); |
| | 11 | |
| | 12 | void passAsParameter( Param p ); |
| | 13 | } |
| | 14 | |
| | 15 | public class Impl implements Api |
| | 16 | { |
| | 17 | public Param returnParam() { return createParam( ... ); } |
| | 18 | |
| | 19 | void passAsParameter( Param p ) { doSomethingWith( p ); } |
| | 20 | } |
| | 21 | }}} |
| | 22 | |
| | 23 | Since Param is an interface, the runtime system cannot create instances of this type without further information. |
| | 24 | We 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 | |
| | 26 | In 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 ) |
| | 30 | public interface Param |
| | 31 | { |
| | 32 | public String printContent() { ... } |
| | 33 | } |
| | 34 | |
| | 35 | public 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 | |
| | 46 | The 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 | {{{ |
| | 48 | Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port ); |
| | 49 | |
| | 50 | Param p = remote_api.returnParam(); |
| | 51 | System.out.println( p.printContent() ); |
| | 52 | |
| | 53 | Param asParam = new ParamImpl(...); |
| | 54 | remote_api.passAsParameter( asParam ); |
| | 55 | |
| | 56 | ... |
| | 57 | }}} |