Java DBus Namespace problem.

Arigead captain.deadly at gmail.com
Tue Mar 2 01:12:54 PST 2010


Matthew Johnson wrote:
> On Mon Mar 01 17:12, Arigead wrote:
>> Hello all,
>>     I've got a wee problem with Java DBus code I'm trying to write to
>> use the org.navit_project.navit interfaces. My problem is that there are
>> methods in the interface org.navit_project.navit and in the interface
>> org.navit_project.navit.navit
>>
>> I've got an Interface file for the upper Interface:
>>
>> package org.navit_project;
>>
>> @DBusInterfaceName("org.navit_project.navit")
>> public interface navit extends DBusInterface
>> {
>>     public Path callback_attr_new(String signalname, String attribute);
>> }
>>
>>
>> But if I do the same thing again for org.navit_project.navit.navit:
>>
>> package org.navit_project.navit;
>>
>> @DBusInterfaceName("org.navit_project.navit.navit")
>> public interface navit extends DBusInterface
>> {
>>     public String method(String attribute);
>> }
>>
>> It'll cause namespace conflicts in the Java namespace? That's a question
>> as I'm not an expert in Java but I would have thought that this would
>> cause some confusion in the code which calls methods from both namespaces.
>>
>> import org.navit_project.navit
>> import org.navit_project.navit.navit
> 
> It's worse than that, you just can't have a class/interface with the same name
> as the package.
> 
> Two options here, firstly, the @DBusInterfaceName you currently have are
> redundant, that's the default which dbus-java automatically uses
> (package.name).  You can use @DBusInterfaceName to change the name, so you
> could use the Java package navit_dbus_interfaces, and call one navit and the
> other navit_navit (or something), then use @DBusInterfaceName to make the
> correct.
> 
> The other option is to declare one interface as a member of the other:
> 
> package org.navit_project;
> public interface navit extends DBusInterface
> {
>    public static interface navit extends DBusInterface
>    {
>       ...
>    }
>    ...
> }
> 
> Then, you can refer to both org.navit_project.navit.navit and
> org.navit_project.navit.navit in your Java code and everything will work
> correctly.
> 
> On the import side, you are right that you can't import both of them, but you
> can always use the fully qualified package.name form everywhere you would just
> name the class, or you can import org.navit_project.navit and then refer to
> navit and navit.navit.
> 
> Finally, may I say what a poor choice of interface names that is from whoever
> designed them (-;
> 
> Matt
> 

Sorry to post again, but I'm afraid I'm the bearer of bad tidings I
tried the nested interface example and Eclipse wasn't too happy with that:

The nested type navit cannot hide an enclosing type

The other method of using the annotation to correct the class name gives
me a problem at runtime when casting:

nav n = (nav) dbusConnection.getRemoteObject(NavitBusName, NavitPath);

Caused by: java.lang.ClassCastException: $Proxy6 cannot be cast to
org.navit_project.nav

if I change the name to navit n= (navit)
dbusConnection.getRemoteObject() it's happy.

Looks like a bit of an issue. I'll have a word on the navit IRC and see
if people have a solution or could change the namespace.




More information about the dbus mailing list