Java DBus Namespace problem.

Matthew Johnson dbus at matthew.ath.cx
Mon Mar 1 09:21:14 PST 2010


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

-- 
www.matthew.ath.cx
D-Bus Java
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: Digital signature
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20100301/58d48cf8/attachment.pgp>


More information about the dbus mailing list