How to create a OSGI Configuration holding multi dimensional array value | Community
Skip to main content
Level 3
May 29, 2020
Solved

How to create a OSGI Configuration holding multi dimensional array value

  • May 29, 2020
  • 3 replies
  • 11226 views

I have a string array as below. 

String[][] group = {{"A","B","C","D"},{"E","F","G","H"},{"I","J","K","L"},{"M","N","O","P"},
{"Q","R","S"},{"T","U","V"}};

 

I need to create a OSGI configuration property holding this value. Is it possible? Does OSGI support this?

Can we create this kind of array configuration in OSGI?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by raghavc

@pn_2007 create a factory OSGI Configuration, and each factory item config can have an array property (@Property(unbounded=PropertyUnbounded.ARRAY)). This would allow you to have 2 dimensional array 

 

You can refer to the below link on how to create a factory config

https://www.tothenew.com/blog/creating-osgi-factory-configurations-in-aem/

3 replies

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 29, 2020

@pn_2007,

Definitely, OSGI configurations can contain string values for a configuration. For the specific string value, you can configure a String representation of a JSON Object. When your OSGI service is obtaining the configuration, you will expect to get the String value. With the String value, you can use a common JSON library like GSON, org.json, Jackson, or any other JSON library serialise the String to a JSON Object. Then you can use the JSON Object to get values within the JSON String.

Example:

 

 

import org.json.JSONObject; ... @Activate protected void activate(final Config config) { String config = config.jsonConfig(); JSONObject jsonObject = new JSONObject(config); String apiKey = jsonObject.has("apiKey") ? jsonObject.get("apiKey") : ""; }

 

 

 

Just make sure your configured value is a valid String formatted JSON object. Maintaining these configurations can be a nightmare.

I won't recommend Complex structures of JSON or XML, String formatted, because it is be hard to maintain in OSGI configurations. It might be better to create a configuration of String[] (OSGI will show multi-field string configurable input fields) rather than using complex structures like JSON or XML in a String format.
Example:

 

@AttributeDefinition(name = "MultipleValues", description = "Multi Configuration values") String[] getStringValues(); // from example, https://helpx.adobe.com/experience-manager/using/osgi_config63.html

 

 

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 29, 2020
complex structures of JSON or XML might be hard to maintain. It might be better to create configuration of String[] (OSGI will show multi-field string configurable input fields) rather than using complex structures like JSON or XML in a String format.
raghavc
raghavcAccepted solution
Level 4
May 29, 2020

@pn_2007 create a factory OSGI Configuration, and each factory item config can have an array property (@Property(unbounded=PropertyUnbounded.ARRAY)). This would allow you to have 2 dimensional array 

 

You can refer to the below link on how to create a factory config

https://www.tothenew.com/blog/creating-osgi-factory-configurations-in-aem/

joerghoh
Adobe Employee
Adobe Employee
May 29, 2020

OSGI does not support multi-dimensional arrays of values, but just simple lists.

 

When you need to provide more complex data as OSGI parameter, you should consider to package the configuration in a different format (e.g. as JSON file in the repository, or a node structure), and use OSGI to configure the path to it.