OSGi R7 annotations Examples AEM (Adobe Experience Manager)

OSGi component / service Configs

String Config

 @AttributeDefinition(
        name = "String Property",
        description = "String example",
        type = AttributeType.STRING
    )
    String stringExample() default "String value";

String Array Config

@AttributeDefinition(
name = "String Array Example",
description = "String Array Example",
type = AttributeType.STRING
  )
 String[] stringArrayExample() default {"String1", "String2"};

Dropdown Config

 @AttributeDefinition(
        name = "Dropdown example",
        description = "Dropdown example",
        options = {
            @Option(label = "Option1", value = "Option1"),
            @Option(label = "Option2", value = "Option2"),
            @Option(label = "Option3", value = "Option3")
        }
    )
 String dropdownExample() default StringUtils.EMPTY;

Boolean Config
To declare your  OSGi configuration as boolean you must use the attribute type BOOLEAN
@AttributeDefinition(
        name = "Boolean Property",
        description = "Boolean example",
        type = AttributeType.BOOLEAN
 )

Long Config

 @AttributeDefinition(
     name = "Long Property",
     description = "Sample long property",
     type = AttributeType.LONG
)
  long longExample() default 0L;

2 comments:

  1. Thanks for the great annotation examples.

    Do you mind asking whether there exists a possibility to have a persisted default value such that you have, after deletion of a custom value, the default value as a fallback.

    Thanks in advance for any help or hint.

    ReplyDelete
  2. Yes, You can configure via OSGI config nodes

    ReplyDelete