diff --git a/dbus-java-core/src/main/java/org/freedesktop/dbus/annotations/BusName.java b/dbus-java-core/src/main/java/org/freedesktop/dbus/annotations/BusName.java new file mode 100644 index 00000000..d343bda8 --- /dev/null +++ b/dbus-java-core/src/main/java/org/freedesktop/dbus/annotations/BusName.java @@ -0,0 +1,11 @@ +package org.freedesktop.dbus.annotations; + + +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface BusName { + String value(); +} diff --git a/dbus-java-core/src/main/java/org/freedesktop/dbus/annotations/ObjectPath.java b/dbus-java-core/src/main/java/org/freedesktop/dbus/annotations/ObjectPath.java new file mode 100644 index 00000000..fb274fda --- /dev/null +++ b/dbus-java-core/src/main/java/org/freedesktop/dbus/annotations/ObjectPath.java @@ -0,0 +1,10 @@ +package org.freedesktop.dbus.annotations; + +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface ObjectPath { + String value(); +} diff --git a/dbus-java-core/src/main/java/org/freedesktop/dbus/connections/impl/DBusConnection.java b/dbus-java-core/src/main/java/org/freedesktop/dbus/connections/impl/DBusConnection.java index ca042fdf..6eeb1cbf 100644 --- a/dbus-java-core/src/main/java/org/freedesktop/dbus/connections/impl/DBusConnection.java +++ b/dbus-java-core/src/main/java/org/freedesktop/dbus/connections/impl/DBusConnection.java @@ -5,6 +5,9 @@ import org.freedesktop.dbus.DBusMatchRule; import org.freedesktop.dbus.RemoteInvocationHandler; import org.freedesktop.dbus.RemoteObject; +import org.freedesktop.dbus.annotations.BusName; +import org.freedesktop.dbus.annotations.DBusInterfaceName; +import org.freedesktop.dbus.annotations.ObjectPath; import org.freedesktop.dbus.connections.AbstractConnection; import org.freedesktop.dbus.connections.IDisconnectAction; import org.freedesktop.dbus.connections.config.ReceivingServiceConfig; @@ -455,6 +458,27 @@ public I getRemoteObject(String _busname, String _obje return getRemoteObject(_busname, _objectpath, _type, true); } + public I getRemoteObject(Class type) throws DBusException{ + BusName[] busNameTypes + = type.getAnnotationsByType(BusName.class); + if(busNameTypes.length == 0){ + throw new DBusException("No BusName annotation found on class " + type.getName()); + } + if(busNameTypes.length > 1){ + throw new DBusException("Multiple BusName annotations found on class " + type.getName()); + } + String busName= busNameTypes[0].value(); + ObjectPath[] objectPathTypes = type.getAnnotationsByType(ObjectPath.class); + if(objectPathTypes.length == 0){ + throw new DBusException("No DBusInterfaceName annotation found on class " + type.getName()); + } + if(objectPathTypes.length > 1){ + throw new DBusException("Multiple DBusInterfaceName annotations found on class " + type.getName()); + } + String interfaceName = objectPathTypes[0].value(); + return getRemoteObject(busName, interfaceName, type); + } + /** * Return a reference to a remote object. This method will always refer to the well known name (if given) rather * than resolving it to a unique bus name. In particular this means that if a process providing the well known name