Changes between Initial Version and Version 1 of ExamlesUsingNoAnnoAndNull


Ignore:
Timestamp:
Jun 29, 2010, 2:17:10 PM (16 years ago)
Author:
lauer
Comment:

added example

Legend:

Unmodified
Added
Removed
Modified
  • ExamlesUsingNoAnnoAndNull

    v1 v1  
     1You don't have to put an XmlRpcBean annotation to every bean you like to transfer.
     2XmlRpc-Delight can use any unknown type as XmlRpcBean by setting
     3
     4 '''{{{XmlRpc.XmlRpc.treatUnknownTypesAsBeans( true );}}}'''
     5
     6Also you can pass null-values as method arguments by setting
     7
     8 '''{{{XmlRpc.useAutomaticNullMasking( true );}}}'''
     9
     10__This has to be done on both server and client side.__
     11
     12{{{
     13public interface Api
     14{
     15    enum Size { tiny, medium, huge }
     16   
     17    class Bean
     18    {
     19        private Size size;
     20        private String[] content;
     21       
     22        public Size getSize()
     23        {
     24            return size;
     25        }
     26       
     27        public void setSize( Size size )
     28        {
     29            this.size = size;
     30        }
     31       
     32        public String[] getContent()
     33        {
     34            return content;
     35        }
     36       
     37        public void setContent( String[] content )
     38        {
     39            this.content = content;
     40        }
     41       
     42        @Override
     43        public String toString()
     44        {
     45            return "Bean(" + getSize() + "):" + Arrays.toString( getContent() );
     46        }
     47    }
     48   
     49    void updateBean( Bean b );
     50}
     51}}}
     52
     53{{{
     54...
     55       //start server
     56        XmlRpc.treatUnknownTypesAsBeans( true );
     57        XmlRpc.useAutomaticNullMasking( true );
     58        StartXmlRpcServer.startXmlRpcServer( new ApiHandler() );
     59
     60        //create a (remote) client to the API
     61        Api api = createClient( Api.class );
     62
     63        //do some calls
     64        Api.Bean bean = new Api.Bean();
     65        bean.setSize( Size.medium );
     66        bean.setContent( new String[]{ "a", "b", "c" } );
     67       
     68        api.updateBean( bean );
     69       
     70        //also null values allowed
     71        Api.Bean bean2 = new Api.Bean();
     72        bean2.setSize( Size.tiny );
     73        bean2.setContent( null );
     74       
     75        api.updateBean( bean2 );
     76...
     77}}}
     78
     79Examples in source code: [http://delight.opendfki.de/repos/trunk/delight-examples/src/main/java/de/dfki/util/xmlrpc/examples/no_annontations]