How to use multi value(array) property in OSGi?
Asked Answered
I

1

7

I have the following service:

@Component(
        immediate = true,
        metatype = true)
@Service
@Property(name = EventConstants.EVENT_TOPIC, value = {ReplicationAction.EVENT_TOPIC})
public class MyService implements EventHandler {

    @Property
    private static final String MULTI_PROPERTY = "config.multiproperty";

    ........
    //another implementation
    ........
}

I want MULTI_PROPERTY to be as array value, to have possibility to use a set of values like on image:

enter image description here

How to implement it?

Ism answered 9/2, 2016 at 16:56 Comment(0)
P
9

Use the unbounded attribute to specify multivalued property and use the cardinality attribute to restrict the number of entries.

 @Property(unbounded = PropertyUnbounded.ARRAY, cardinality=10, label = "Some Label")
 private static final String MULTI_PROPERTY = "config.multiproperty";

In order to read the property array you can use #toStringArray() method of the PropertiesUtil

PropertiesUtil.toStringArray(properties.get(MULTI_PROPERTY));
Pelf answered 9/2, 2016 at 18:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.