OSGi Configuration Admin and MetaType Service
I've been using the OSGi Configuration Admin to implement some basic configuration capability in our program. I now started looking into the MetaType Service specification because I need type information for each configuration property.
It's unclear to me how these two services interact. The Configuration Admin deals with essentially untyped Key/Value pairs. The MetaType Service knows names and types (among other things) of configuration properties, but not their values. My goal is to dynamically generate a configuration/preferences dialog for all components which have a configuration and corresponding metatype information. According to the MetaType Service spec, the service was conceived to cover this exact use case. So I reckon it shouldn't be too difficult
I can retrieve the metatype information with the following the sample code:
ServiceReference metatypeRef = bundleContext.getServiceReference(MetaTypeService.class.getName());
MetaTypeService service = (MetaTypeService) bundleContext.getService(metatypeRef);
MetaTypeInformation information = service.getMetaTypeInformation(myBundle);
After retrieving the MetaTypeInformation object for the required bundle, I have access to all the information contained in the metatype XML definition. In particular, it is possible to access the ObjectClassDefinition:
ObjectClassDefinition ocd = information.getObjectClassDefinition(pid, null);
AttributeDefinition attributes = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
My questions are:
- Given the AttributeDefinition; how can I retrieve the actual value of the underlying property? I know its name, but not its value.
- How can I enumerate the metatype information for all components in all bundles that are currently present (active and inactive)? I know how to list all configurations through the Configuration Admin interface. It there perhaps a way to get to the MetaTypeInformation from the Configuration?
osgi
add a comment |
I've been using the OSGi Configuration Admin to implement some basic configuration capability in our program. I now started looking into the MetaType Service specification because I need type information for each configuration property.
It's unclear to me how these two services interact. The Configuration Admin deals with essentially untyped Key/Value pairs. The MetaType Service knows names and types (among other things) of configuration properties, but not their values. My goal is to dynamically generate a configuration/preferences dialog for all components which have a configuration and corresponding metatype information. According to the MetaType Service spec, the service was conceived to cover this exact use case. So I reckon it shouldn't be too difficult
I can retrieve the metatype information with the following the sample code:
ServiceReference metatypeRef = bundleContext.getServiceReference(MetaTypeService.class.getName());
MetaTypeService service = (MetaTypeService) bundleContext.getService(metatypeRef);
MetaTypeInformation information = service.getMetaTypeInformation(myBundle);
After retrieving the MetaTypeInformation object for the required bundle, I have access to all the information contained in the metatype XML definition. In particular, it is possible to access the ObjectClassDefinition:
ObjectClassDefinition ocd = information.getObjectClassDefinition(pid, null);
AttributeDefinition attributes = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
My questions are:
- Given the AttributeDefinition; how can I retrieve the actual value of the underlying property? I know its name, but not its value.
- How can I enumerate the metatype information for all components in all bundles that are currently present (active and inactive)? I know how to list all configurations through the Configuration Admin interface. It there perhaps a way to get to the MetaTypeInformation from the Configuration?
osgi
add a comment |
I've been using the OSGi Configuration Admin to implement some basic configuration capability in our program. I now started looking into the MetaType Service specification because I need type information for each configuration property.
It's unclear to me how these two services interact. The Configuration Admin deals with essentially untyped Key/Value pairs. The MetaType Service knows names and types (among other things) of configuration properties, but not their values. My goal is to dynamically generate a configuration/preferences dialog for all components which have a configuration and corresponding metatype information. According to the MetaType Service spec, the service was conceived to cover this exact use case. So I reckon it shouldn't be too difficult
I can retrieve the metatype information with the following the sample code:
ServiceReference metatypeRef = bundleContext.getServiceReference(MetaTypeService.class.getName());
MetaTypeService service = (MetaTypeService) bundleContext.getService(metatypeRef);
MetaTypeInformation information = service.getMetaTypeInformation(myBundle);
After retrieving the MetaTypeInformation object for the required bundle, I have access to all the information contained in the metatype XML definition. In particular, it is possible to access the ObjectClassDefinition:
ObjectClassDefinition ocd = information.getObjectClassDefinition(pid, null);
AttributeDefinition attributes = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
My questions are:
- Given the AttributeDefinition; how can I retrieve the actual value of the underlying property? I know its name, but not its value.
- How can I enumerate the metatype information for all components in all bundles that are currently present (active and inactive)? I know how to list all configurations through the Configuration Admin interface. It there perhaps a way to get to the MetaTypeInformation from the Configuration?
osgi
I've been using the OSGi Configuration Admin to implement some basic configuration capability in our program. I now started looking into the MetaType Service specification because I need type information for each configuration property.
It's unclear to me how these two services interact. The Configuration Admin deals with essentially untyped Key/Value pairs. The MetaType Service knows names and types (among other things) of configuration properties, but not their values. My goal is to dynamically generate a configuration/preferences dialog for all components which have a configuration and corresponding metatype information. According to the MetaType Service spec, the service was conceived to cover this exact use case. So I reckon it shouldn't be too difficult
I can retrieve the metatype information with the following the sample code:
ServiceReference metatypeRef = bundleContext.getServiceReference(MetaTypeService.class.getName());
MetaTypeService service = (MetaTypeService) bundleContext.getService(metatypeRef);
MetaTypeInformation information = service.getMetaTypeInformation(myBundle);
After retrieving the MetaTypeInformation object for the required bundle, I have access to all the information contained in the metatype XML definition. In particular, it is possible to access the ObjectClassDefinition:
ObjectClassDefinition ocd = information.getObjectClassDefinition(pid, null);
AttributeDefinition attributes = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
My questions are:
- Given the AttributeDefinition; how can I retrieve the actual value of the underlying property? I know its name, but not its value.
- How can I enumerate the metatype information for all components in all bundles that are currently present (active and inactive)? I know how to list all configurations through the Configuration Admin interface. It there perhaps a way to get to the MetaTypeInformation from the Configuration?
osgi
osgi
edited Nov 13 '18 at 8:33
djf
asked Nov 13 '18 at 8:26
djfdjf
5,31263147
5,31263147
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The Configuration Admin and MetaType services are separate, but related, specifications. There is no hard link between them, which I think is probably one of the main points that will help to answer your questions.
Essentially Configuration Admin is a store of configuration records. Each configuration record has a unique persistent identifier (PID) and if the configuration record is for a factory configuration then it will also have a Factory PID. The configuration record then also contains a number of key value pairs, where the key is always a String, and the value is one of a limited set of types.
Metatype, on the other hand, is a tool for providing configuration definitions. These describe the expected layout of keys and values in a configuration, including things like the type of the value associated with a given key, a minimum/maximum size for the value, an enumerated list of allowable values, and potentially a default value. Each key/value definition is held in an Attribute Definition, and these are grouped together in an Object Class Definition, which is associated with a PID.
The important difference is that Metatype knows nothing about what the configuration actually is at runtime (it's just information about what shape the configuration should be). Similarly Configuration Admin knows nothing about what shape the configuration should be, it just knows what the values currently are.
Therefore:
Given the AttributeDefinition; how can I retrieve the actual value of the underlying property? I know its name, but not its value.
You need to identify the PID associated with the ObjectClassDefinition containing the Attribute Definition, and then to use this to find the relevant configuration dictionary in Configuration Admin. If the OCD is for a factory PID then you will need to identify which of the configurations for that factory PID you want to look at.
How can I enumerate the metatype information for all components in all bundles that are currently present (active and inactive)? I know how to list all configurations through the Configuration Admin interface. It there perhaps a way to get to the MetaTypeInformation from the Configuration?
The MetaTypeService
is a service in the OSGi Service Registry that you can use to ask for the MetaTypeInformation for a given bundle. If you ask for the Metatype Information for each bundle in turn then you will have the information that you are looking for. There is no hard link between Configuration Admin and Metatype, so a Configuration object has no way of knowing whether a meta type exists for it.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276730%2fosgi-configuration-admin-and-metatype-service%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Configuration Admin and MetaType services are separate, but related, specifications. There is no hard link between them, which I think is probably one of the main points that will help to answer your questions.
Essentially Configuration Admin is a store of configuration records. Each configuration record has a unique persistent identifier (PID) and if the configuration record is for a factory configuration then it will also have a Factory PID. The configuration record then also contains a number of key value pairs, where the key is always a String, and the value is one of a limited set of types.
Metatype, on the other hand, is a tool for providing configuration definitions. These describe the expected layout of keys and values in a configuration, including things like the type of the value associated with a given key, a minimum/maximum size for the value, an enumerated list of allowable values, and potentially a default value. Each key/value definition is held in an Attribute Definition, and these are grouped together in an Object Class Definition, which is associated with a PID.
The important difference is that Metatype knows nothing about what the configuration actually is at runtime (it's just information about what shape the configuration should be). Similarly Configuration Admin knows nothing about what shape the configuration should be, it just knows what the values currently are.
Therefore:
Given the AttributeDefinition; how can I retrieve the actual value of the underlying property? I know its name, but not its value.
You need to identify the PID associated with the ObjectClassDefinition containing the Attribute Definition, and then to use this to find the relevant configuration dictionary in Configuration Admin. If the OCD is for a factory PID then you will need to identify which of the configurations for that factory PID you want to look at.
How can I enumerate the metatype information for all components in all bundles that are currently present (active and inactive)? I know how to list all configurations through the Configuration Admin interface. It there perhaps a way to get to the MetaTypeInformation from the Configuration?
The MetaTypeService
is a service in the OSGi Service Registry that you can use to ask for the MetaTypeInformation for a given bundle. If you ask for the Metatype Information for each bundle in turn then you will have the information that you are looking for. There is no hard link between Configuration Admin and Metatype, so a Configuration object has no way of knowing whether a meta type exists for it.
add a comment |
The Configuration Admin and MetaType services are separate, but related, specifications. There is no hard link between them, which I think is probably one of the main points that will help to answer your questions.
Essentially Configuration Admin is a store of configuration records. Each configuration record has a unique persistent identifier (PID) and if the configuration record is for a factory configuration then it will also have a Factory PID. The configuration record then also contains a number of key value pairs, where the key is always a String, and the value is one of a limited set of types.
Metatype, on the other hand, is a tool for providing configuration definitions. These describe the expected layout of keys and values in a configuration, including things like the type of the value associated with a given key, a minimum/maximum size for the value, an enumerated list of allowable values, and potentially a default value. Each key/value definition is held in an Attribute Definition, and these are grouped together in an Object Class Definition, which is associated with a PID.
The important difference is that Metatype knows nothing about what the configuration actually is at runtime (it's just information about what shape the configuration should be). Similarly Configuration Admin knows nothing about what shape the configuration should be, it just knows what the values currently are.
Therefore:
Given the AttributeDefinition; how can I retrieve the actual value of the underlying property? I know its name, but not its value.
You need to identify the PID associated with the ObjectClassDefinition containing the Attribute Definition, and then to use this to find the relevant configuration dictionary in Configuration Admin. If the OCD is for a factory PID then you will need to identify which of the configurations for that factory PID you want to look at.
How can I enumerate the metatype information for all components in all bundles that are currently present (active and inactive)? I know how to list all configurations through the Configuration Admin interface. It there perhaps a way to get to the MetaTypeInformation from the Configuration?
The MetaTypeService
is a service in the OSGi Service Registry that you can use to ask for the MetaTypeInformation for a given bundle. If you ask for the Metatype Information for each bundle in turn then you will have the information that you are looking for. There is no hard link between Configuration Admin and Metatype, so a Configuration object has no way of knowing whether a meta type exists for it.
add a comment |
The Configuration Admin and MetaType services are separate, but related, specifications. There is no hard link between them, which I think is probably one of the main points that will help to answer your questions.
Essentially Configuration Admin is a store of configuration records. Each configuration record has a unique persistent identifier (PID) and if the configuration record is for a factory configuration then it will also have a Factory PID. The configuration record then also contains a number of key value pairs, where the key is always a String, and the value is one of a limited set of types.
Metatype, on the other hand, is a tool for providing configuration definitions. These describe the expected layout of keys and values in a configuration, including things like the type of the value associated with a given key, a minimum/maximum size for the value, an enumerated list of allowable values, and potentially a default value. Each key/value definition is held in an Attribute Definition, and these are grouped together in an Object Class Definition, which is associated with a PID.
The important difference is that Metatype knows nothing about what the configuration actually is at runtime (it's just information about what shape the configuration should be). Similarly Configuration Admin knows nothing about what shape the configuration should be, it just knows what the values currently are.
Therefore:
Given the AttributeDefinition; how can I retrieve the actual value of the underlying property? I know its name, but not its value.
You need to identify the PID associated with the ObjectClassDefinition containing the Attribute Definition, and then to use this to find the relevant configuration dictionary in Configuration Admin. If the OCD is for a factory PID then you will need to identify which of the configurations for that factory PID you want to look at.
How can I enumerate the metatype information for all components in all bundles that are currently present (active and inactive)? I know how to list all configurations through the Configuration Admin interface. It there perhaps a way to get to the MetaTypeInformation from the Configuration?
The MetaTypeService
is a service in the OSGi Service Registry that you can use to ask for the MetaTypeInformation for a given bundle. If you ask for the Metatype Information for each bundle in turn then you will have the information that you are looking for. There is no hard link between Configuration Admin and Metatype, so a Configuration object has no way of knowing whether a meta type exists for it.
The Configuration Admin and MetaType services are separate, but related, specifications. There is no hard link between them, which I think is probably one of the main points that will help to answer your questions.
Essentially Configuration Admin is a store of configuration records. Each configuration record has a unique persistent identifier (PID) and if the configuration record is for a factory configuration then it will also have a Factory PID. The configuration record then also contains a number of key value pairs, where the key is always a String, and the value is one of a limited set of types.
Metatype, on the other hand, is a tool for providing configuration definitions. These describe the expected layout of keys and values in a configuration, including things like the type of the value associated with a given key, a minimum/maximum size for the value, an enumerated list of allowable values, and potentially a default value. Each key/value definition is held in an Attribute Definition, and these are grouped together in an Object Class Definition, which is associated with a PID.
The important difference is that Metatype knows nothing about what the configuration actually is at runtime (it's just information about what shape the configuration should be). Similarly Configuration Admin knows nothing about what shape the configuration should be, it just knows what the values currently are.
Therefore:
Given the AttributeDefinition; how can I retrieve the actual value of the underlying property? I know its name, but not its value.
You need to identify the PID associated with the ObjectClassDefinition containing the Attribute Definition, and then to use this to find the relevant configuration dictionary in Configuration Admin. If the OCD is for a factory PID then you will need to identify which of the configurations for that factory PID you want to look at.
How can I enumerate the metatype information for all components in all bundles that are currently present (active and inactive)? I know how to list all configurations through the Configuration Admin interface. It there perhaps a way to get to the MetaTypeInformation from the Configuration?
The MetaTypeService
is a service in the OSGi Service Registry that you can use to ask for the MetaTypeInformation for a given bundle. If you ask for the Metatype Information for each bundle in turn then you will have the information that you are looking for. There is no hard link between Configuration Admin and Metatype, so a Configuration object has no way of knowing whether a meta type exists for it.
answered Nov 13 '18 at 13:25
Tim WardTim Ward
1,02969
1,02969
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276730%2fosgi-configuration-admin-and-metatype-service%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown