Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 588
cylinder.y Avatar asked Feb 09 '16 16:02

cylinder.y


1 Answers

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));
like image 110
rakhi4110 Avatar answered Sep 28 '22 04:09

rakhi4110