<?xml version="1.0" encoding="iso-8859-1" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd--> <html xmlns="http://www.w3.org/1999/xhtml" > <head><title>DBusSerializable</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> <meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> <!-- xhtml,2,html --> <meta name="src" content="dbus-java.tex" /> <meta name="date" content="2016-03-02 10:34:00" /> <link rel="stylesheet" type="text/css" href="dbus-java.css" /> </head><body > <!--l. 760--><div class="crosslinks"><p class="noindent">[<a href="dbus-javase8.html" >prev</a>] [<a href="dbus-javase8.html#taildbus-javase8.html" >prev-tail</a>] [<a href="dbus-javase3.html#taildbus-javase9.html">tail</a>] [<a href="dbus-java.html# " >up</a>] </p></div> <h3 class="sectionHead"><span class="titlemark">9 </span> <a id="x30-340009"></a>DBusSerializable</h3> <!--l. 762--><p class="noindent" >Some people may want to be able to pass their own objects over D-Bus. Obviously only raw D-Bus types can be sent on the message bus itself, but the Java implementation allows the creation of serializable objects which can be passed to D-Bus functions and will be converted to/from D-Bus types by the library. </p><!--l. 767--><p class="indent" > To create such a class you must implement the <span class="cmtt-12">DBusSerializable</span><span class="footnote-mark"><a href="dbus-java31.html#fn18x0"><sup class="textsuperscript">18</sup></a></span><a id="x30-34001f18"></a> class and provide two methods and a zero-argument constructor. The first method has the signature <span class="cmtt-12">public Object</span> </p> <center class="math-display" > <img src="dbus-java0x.png" alt=" " class="math-display" /></center> <!--l. 770--><p class="nopar" > <span class="cmtt-12">serialize() throws DBusException </span>and the second must be called <span class="cmtt-12">deserialize</span>, return <span class="cmtt-12">null </span>and take as it’s arguments exactly all the dbus types that are being serialized to <span class="cmti-12">in order</span> and <span class="cmti-12">with parameterization</span>. The serialize method should return the class properties you wish to serialize, correctly formatted for the wire (<span class="cmtt-12">DBusConnection.convertParameters() </span>can help with this), in order in an Object array. </p><!--l. 778--><p class="indent" > An example of a serializable class can be seen in figure <a href="#x30-3400216">16<!--tex4ht:ref: fig:serializable --></a>. </p> <hr class="figure" /><div class="figure" > <a id="x30-3400216"></a> <div class="center" > <!--l. 782--><p class="noindent" > </p> <div class="verbatim" id="verbatim-23"> import java.lang.reflect.Type;  <br />  <br />import java.util.List;  <br />import java.util.Vector;  <br />  <br />import org.freedesktop.dbus.DBusConnection;  <br />import org.freedesktop.dbus.DBusSerializable;  <br />  <br />public class TestSerializable implements DBusSerializable  <br />{  <br />   private int a;  <br />   private String b;  <br />   private Vector<Integer> c;  <br />   public TestSerializable(int a, String b, Vector<Integer> c)  <br />   {  <br />      this.a = a;  <br />      this.b = b.toString();  <br />      this.c = c;  <br />   }  <br />   public TestSerializable() {}  <br />   public void deserialize(int a, String b, List<Integer> c)  <br />   {  <br />      this.a = a;  <br />      this.b = b;  <br />      this.c = new Vector<Integer>(c);  <br />   }  <br />   public Object[] serialize()  <br />   {  <br />      return new Object[] { a, b, c };  <br />   }  <br />   public int getInt() { return a; }  <br />   public String getString() { return b; }  <br />   public Vector<Integer> getVector() { return c; }  <br />   public String toString()  <br />   {  <br />      return "TestSerializable{"+a+","+b+","+c+"}";  <br />   }  <br />} </div> <!--l. 822--><p class="nopar" ></p></div> <br /> <div class="caption" ><span class="id">Figure 16: </span><span class="content">A serializable class</span></div><!--tex4ht:label?: x30-3400216 --> </div><hr class="endfigure" /> <!--l. 830--><div class="crosslinks"><p class="noindent">[<a href="dbus-javase8.html" >prev</a>] [<a href="dbus-javase8.html#taildbus-javase8.html" >prev-tail</a>] [<a href="dbus-javase9.html" >front</a>] [<a href="dbus-java.html# " >up</a>] </p></div> <!--l. 830--><p class="indent" > <a id="taildbus-javase9.html"></a> </p> </body></html>