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 be like an array value in order to be able to use a set of values, for example, in an image:

enter image description here

How to implement it?

+5
source share
1 answer

Use the unbounded attribute to specify a multi-valued property, and use the cardinality attribute to limit the number of entries.

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

To read an array of properties, you can use the #toStringArray() Method PropertiesUtil

 PropertiesUtil.toStringArray(properties.get(MULTI_PROPERTY)); 
+5
source

Source: https://habr.com/ru/post/1242634/


All Articles