Correct prototype for a method returning a Map of Variants

Gilles GIGAN gilles.gigan at gmail.com
Fri May 23 09:37:23 PDT 2008


Hi all,
I m writing a Java class which needs to execute the "GetAllProperties"
method from the org.freedesktop.Hal.Device interface  with the following
signature:
<interface name="org.freedesktop.Hal.Device">
    <method name="GetAllProperties">
      <arg name="properties" direction="out" type="a{sv}"/>
    </method>
...
</interface>

What is the correct prototype I have to use when I declare it in a
DBusInterface ?
This is my attempt, Is it correct ?:
package org.freedesktop.Hal;

import java.util.Map;
import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.Variant;

public interface Device extends DBusInterface {
    public Map<String,Variant<Object>> GetAllProperties();
...
}


I invoke this method with :
Device d = (Device)
conn.getRemoteObject("org.freedesktop.Hal","/org/freedesktop/Hal/devices/computer",Device.class);
d.GetAllProperties();

I managed to get the key (String) and the value (Variant<Object>) with:
Variant<Map<String,Variant<Object>>> v = new
Variant<Map<String,Variant<Object>>>(d.GetAllProperties(), new
DBusMapType(String.class, Variant.class));
Map<String,Variant<Object>> mp = v.getValue();
Iterator<String> iter = mp.keySet().iterator();
while(iter.hasNext()) {
                s = iter.next();
                System.out.println("Property: "+s + "-
"+mp.get(s).toString());
}

How can I cast the values (Variant<Object>) to their equivalent Java types
(which are known in advance) ?

Thanks
Gilles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20080524/96fa6394/attachment.html 


More information about the dbus mailing list