forked from hypfvieh/dbus-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hypfvieh#130] DBusProperty annotation added
- Loading branch information
Showing
4 changed files
with
170 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.freedesktop.dbus; | ||
|
||
/** | ||
* Interface for retrieving generic type information with reflection. | ||
* <p> | ||
* Examples: | ||
* <pre>{@code | ||
* public interface ListOfStrings extends TypeRef<List<String>> { | ||
* } | ||
* } </pre> | ||
* | ||
* @param <T> generic type | ||
*/ | ||
public interface TypeRef<T> { | ||
} |
24 changes: 24 additions & 0 deletions
24
dbus-java/src/main/java/org/freedesktop/dbus/annotations/DBusProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.freedesktop.dbus.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Container for the multiple {@link DBusProperty} annotations in the single class. | ||
* You probably don't want to use this annotation in your code, please use {@link DBusProperty}. | ||
* | ||
* @see DBusProperty | ||
*/ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface DBusProperties { | ||
|
||
/** | ||
* Container for multiple properties | ||
* | ||
* @return value | ||
*/ | ||
DBusProperty[] value(); | ||
} |
70 changes: 70 additions & 0 deletions
70
dbus-java/src/main/java/org/freedesktop/dbus/annotations/DBusProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.freedesktop.dbus.annotations; | ||
|
||
import org.freedesktop.dbus.types.Variant; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* Appends information about properties in the interface. The annotated properties are added to the introspection data. | ||
* In case of complex type of the property please use {@link org.freedesktop.dbus.TypeRef}. | ||
* <p> | ||
* Usage: | ||
* </p> | ||
* <pre>{@code | ||
* @DBusInterfaceName("com.example.Bar") | ||
* @DBusProperty(name = "Name", type = String.class) | ||
* @DBusProperty(name = "ListOfVariables", type = List.class, access = Access.READ) | ||
* @DBusProperty(name = "MapOfStringList", type = ComplexTypeWithMapAndList.class, access = Access.READ) | ||
* public interface Bar extends DBusInterface { | ||
* | ||
* // TypeRef allows to provide detailed information about type | ||
* interface ComplexTypeWithMapAndList extends TypeRef<Map<String, List<String>>> { | ||
* } | ||
* } | ||
* }</pre> | ||
* | ||
* @see org.freedesktop.dbus.interfaces.DBusInterface | ||
* @see org.freedesktop.dbus.TypeRef | ||
*/ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Repeatable(DBusProperties.class) | ||
public @interface DBusProperty { | ||
|
||
/** | ||
* Property name | ||
* | ||
* @return name | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* type of the property, in case of complex types please create custom interface that extends {@link org.freedesktop.dbus.TypeRef} | ||
* | ||
* @return type | ||
*/ | ||
Class<?> type() default Variant.class; | ||
|
||
/** | ||
* Property access type | ||
* | ||
* @return access | ||
*/ | ||
Access access() default Access.READ_WRITE; | ||
|
||
enum Access { | ||
READ("read"), | ||
READ_WRITE("readwrite"), | ||
WRITE("write"); | ||
|
||
private final String accessName; | ||
|
||
Access(String accessName) { | ||
this.accessName = accessName; | ||
} | ||
|
||
public String getAccessName() { | ||
return accessName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters