December 29, 2020
Estimated Post Reading Time ~

OSGI R6 Configuration @AttributeDefinition Essentials Reference Guide

When defining any OSGI component’s configuration its standard practice to use Declarative Services; these configurations can be edited in the OSGI Apache Felix Console. This can be done by creating a class interface with the annotated @ObjectClassDefinition, which includes a determined list of rules as @AttributeDefinition items.

The @AttributeDefinition defines the supporting configuration for a given OSGI component’s configuration. It allows you to set data types and default values for each given configuration. When an admin user interacts with the Felix console, how the @AttributeDefinition is defined will determine the look and feel of each of the input fields are presented.

Attribute Types – References
@AttributeDefinition Essential Parameters Explained
As we know, the most basic way to define a configuration will be to utilize the annotation @AttributeDefinition. Let’s explore the essential configurations.
  • The @AttributeDefinition annotation accepts parameters as such:
  • line 2: name: defines the human-readable label
  • line 3: description: description for the attribute configuration.
  • line 4: type: definition of the attribute’s data type.
  • line 6: <T>: definition of the attribute’s data type
  • line 6: name_of_conf_reference: configuration’s reference id : name.of.conf.reference
  • line 7: <T>[]: multifield (multi data set) is supported.
@AttributeDefinition(
name=""
description=""
type=""
}
name_of_conf_reference() default "";
// [] name_of_conf_reference_list() default "";


Explained:
Illustrating how the label, description, and configuration reference shows up on the OSGI Apache Felix console.


Attribute Types
With the understanding of how the @AttributeDefinition Essential Parameters are used, we can go ahead to utilize and to familiarize ourselves with the supported essential data attribute types; most of the basic attributes are covered below:

1. String Attribute Type
@AttributeDefinition(
name = "String Label",
description = "String Config Example Description",
type = AttributeType.STRING)
String config_string_example() default "Default String";

2. String[] Attribute Type
@AttributeDefinition(
name = "String[] Label",
description = "String[] Config Example Description",
type = AttributeType.STRING)
String[] config_string_array_example() default {"item1", "item2"};

Explained:
Illustrating how the multi-fields shows up on the OSGI Felix console.


Note:
Configuration can be set as multifield can be enabled without much effort, simply change the attribute type to a list type, shown in #2. String[] Attribute Type example.

3. Long Attribute Type
@AttributeDefinition(
name = "Long Label",
description = "Long Config Example Description",
type = AttributeType.LONG)
long config_long_example() default 0L;

4. int Attribute Type
@AttributeDefinition(
name = "int Label",
description = "innt Config Example Description",
type = AttributeType.INTEGER)
int config_number_example() default 0;

5. Short Attribute Type
@AttributeDefinition(
name = "Short Label",
description = "Short Config Example Description",
type = AttributeType.SHORT)
short config_short_example() default 0;

6. Char Attribute Type
@AttributeDefinition(
name = "Char Label",
description = "Char Config Example Description",
type = AttributeType.CHARACTER)
char config_char_example() default 0;

7. Byte Attribute Type
@AttributeDefinition(
name = "Byte Label",
description = "Byte Config Example Description",
type = AttributeType.BYTE)
byte config_byte_example() default 0;


8. Double Attribute Type
@AttributeDefinition(
name = "Double Label",
description = "Double Config Example Description",
type = AttributeType.DOUBLE)
double config_double_example() default 0;

9. Float Attribute Type
@AttributeDefinition(
name = "Float Label",
description = "Float Config Example Description",
type = AttributeType.FLOAT)
float config_float_example() default 0;

10. Boolean Attribute Type
@AttributeDefinition(
name = "Boolean Label",
description = "Boolean Config Example Description",
type = AttributeType.BOOLEAN)
boolean config_boolean_example() default true;

11. Password Attribute Type
@AttributeDefinition(
name = "Password Label",
description = "Password Config Example Description",
type = AttributeType.PASSWORD)
String config_password_config_example() default "";

12. Options Attribute Type
@AttributeDefinition(
name = "Dropdown Label",
description = "Dropdown Config Example Description",
options = {
@Option(label = "PRODUCTION", value = "PRODUCTION"),
@Option(label = "STAGING", value = "STAGING"),
@Option(label = "UAT", value = "UAT"),
@Option(label = "QA", value = "QA"),
@Option(label = "DEVELOP", value = "DEVELOP")
}
)
String config_dropdown_example() default "DEVELOP";



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.