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.
Quick Links
- @AttributeDefinition Essential Parameters Explained
- Attribute Types – References
- How to Enable Configuration for OSGI Components
Attribute Types – References
@AttributeDefinition Essential Parameters Explained
As we know, the most basic way to define a configuration will be to utilise the annotation @AttributeDefinition. Let’s explore the essential configurations.
The @AttributeDefinition annotation accepts parameters as such:
- line 2: name: defines the human read-able 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.
1
2
3
4
5
6
7@AttributeDefinition(
name=""
description=""
type=""
}
name_of_conf_reference() default "";
// [] name_of_conf_reference_list() default "";Explained:
Illustrating how the label, description, and the 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 utilise and to familiarize ourselves with the supported essential data attribute types; most of the basic attributes are covered below:
- String Attribute Type
- String[] Attribute Type
- Long Attribute Type
- int Attribute Type
- Short Attribute Type
- Char Attribute Type
- byte Attribute Type
- Float Attribute Type
- Double Attribute Type
- Boolean Attribute Type
- Password Attribute Type
- Options Attribute Type
1. String Attribute Type
1
2
3
4
5@AttributeDefinition(
name = "String Label",
description = "String Config Example Description",
type = AttributeType.STRING)
String config_string_example() default "Default String";2. String[] Attribute Type
1
2
3
4
5@AttributeDefinition(
name = "String[] Label",
description = "String[] Config Example Description",
type = AttributeType.STRING)
String[] config_string_array_example() default {"item1", "item2"};Note:
Configuration can be set as multifield can be enabled without much effort, simply change the attribute type to an list type, shown in the #2. String[] Attribute Type example.
3. Long Attribute Type
1
2
3
4
5@AttributeDefinition(
name = "Long Label",
description = "Long Config Example Description",
type = AttributeType.LONG)
long config_long_example() default 0L;4. int Attribute Type
1
2
3
4
5@AttributeDefinition(
name = "int Label",
description = "innt Config Example Description",
type = AttributeType.INTEGER)
int config_number_example() default 0;5. Short Attribute Type
1
2
3
4
5@AttributeDefinition(
name = "Short Label",
description = "Short Config Example Description",
type = AttributeType.SHORT)
short config_short_example() default 0;6. Char Attribute Type
1
2
3
4
5@AttributeDefinition(
name = "Char Label",
description = "Char Config Example Description",
type = AttributeType.CHARACTER)
char config_char_example() default 0;7. Byte Attribute Type
1
2
3
4
5@AttributeDefinition(
name = "Byte Label",
description = "Byte Config Example Description",
type = AttributeType.BYTE)
byte config_byte_example() default 0;See Code Examples!
Click here to view OSGI R6 Configuration Code Examples.8. Double Attribute Type
1
2
3
4
5@AttributeDefinition(
name = "Double Label",
description = "Double Config Example Description",
type = AttributeType.DOUBLE)
double config_double_example() default 0;9. Float Attribute Type
1
2
3
4
5@AttributeDefinition(
name = "Float Label",
description = "Float Config Example Description",
type = AttributeType.FLOAT)
float config_float_example() default 0;10. Boolean Attribute Type
1
2
3
4
5@AttributeDefinition(
name = "Boolean Label",
description = "Boolean Config Example Description",
type = AttributeType.BOOLEAN)
boolean config_boolean_example() default true;11. Password Attribute Type
1
2
3
4
5@AttributeDefinition(
name = "Password Label",
description = "Password Config Example Description",
type = AttributeType.PASSWORD)
String config_password_config_example() default "";12. Options Attribute Type
1
2
3
4
5
6
7
8
9
10
11
12@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";
See Code Examples!
Click here to view OSGI R6 Configuration Code Examples.