You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Christian Lutz <Ch...@kreeloo.de> on 2020/06/04 12:38:55 UTC

Use configuration file with ObjectClassDefinition

Hello,

is it possible with karaf (4.1.x or 4.2.x) to use a configuration file with an ObjectClassDefinition?

E.g. I have a simple ObjectClassDefinition with one boolean method. I set the pid property to de.xy

My idea was that if I want to change the default value all I need to do is to create a de.xy.cfg file in karaf /cfg set the boolean value to false and during the component active the value from the config file will be used instead of the default value. 

I found some tutorials of how to use the objectclassdefinition itself. But I didnt find anything about how I am able to wire this with the karaf Configuration Admin Service. 

Kind regards
Christian 

Re: Use configuration file with ObjectClassDefinition

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Hi Christian,

It’s the case by default. It’s used in Decanter for instance.

If you have a component like:

@Component(name = "foo.bar")

You can have etc/foo.bar.cfg.

Then you get the properties in the component context (in the activate method).

Regards
JB

> Le 4 juin 2020 à 14:38, Christian Lutz <Ch...@kreeloo.de> a écrit :
> 
> Hello,
> 
> is it possible with karaf (4.1.x or 4.2.x) to use a configuration file with an ObjectClassDefinition?
> 
> E.g. I have a simple ObjectClassDefinition with one boolean method. I set the pid property to de.xy
> 
> My idea was that if I want to change the default value all I need to do is to create a de.xy.cfg file in karaf /cfg set the boolean value to false and during the component active the value from the config file will be used instead of the default value. 
> 
> I found some tutorials of how to use the objectclassdefinition itself. But I didnt find anything about how I am able to wire this with the karaf Configuration Admin Service. 
> 
> Kind regards
> Christian 


Re: Use configuration file with ObjectClassDefinition

Posted by Christian Lutz <Ch...@kreeloo.de>.
Hello JB,

Ok it works. Thx. 

What surprised me was the fact, that I have to use the name attribute of the component to bind to the configuration service pid. Even though there is a configurationPid in the component available. 

It is the first time I use this kind of configuration (used blueprint so far) I havent been aware of that there several (at least two) ways of doing this. I guess there are some reason to use one or the other. Any hints?

Kind regards
Christian

> Am 04.06.2020 um 14:52 schrieb Jean-Baptiste Onofre <jb...@nanthrax.net>:
> 
> Hi
> 
> By default it’s based on component name.
> 
> But you can provide any pid.
> 
> Metatype is enabled by default in Karaf. So, you can have your annotation @ObjectClassDefintion.
> 
> However, you can’t mix SCR level property and metatype property.
> So it’s all one or the other.
> 
> Regards
> JB
> 
>> Le 4 juin 2020 à 14:49, Christian Lutz <Ch...@kreeloo.de> a écrit :
>> 
>> Hello JB,
>> 
>> oh it is wired to the name of the component. I will give it a try. 
>> 
>> If I look into the OSGI compendium ObjectClassDefinition is a MetaType Annotation. What did I miss?
>> 
>> Kind regards
>> Christian 
>> 
>>>> Am 04.06.2020 um 14:44 schrieb Jean-Baptiste Onofre <jb...@nanthrax.net>:
>>> 
>>> And by the way, you can also use metatype.
>>> 
>>> Regards
>>> JB
>>> 
>>>> Le 4 juin 2020 à 14:38, Christian Lutz <Ch...@kreeloo.de> a écrit :
>>>> 
>>>> Hello,
>>>> 
>>>> is it possible with karaf (4.1.x or 4.2.x) to use a configuration file with an ObjectClassDefinition?
>>>> 
>>>> E.g. I have a simple ObjectClassDefinition with one boolean method. I set the pid property to de.xy
>>>> 
>>>> My idea was that if I want to change the default value all I need to do is to create a de.xy.cfg file in karaf /cfg set the boolean value to false and during the component active the value from the config file will be used instead of the default value. 
>>>> 
>>>> I found some tutorials of how to use the objectclassdefinition itself. But I didnt find anything about how I am able to wire this with the karaf Configuration Admin Service. 
>>>> 
>>>> Kind regards
>>>> Christian 
>>> 
>> 
> 


Re: Use configuration file with ObjectClassDefinition

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Hi

By default it’s based on component name.

But you can provide any pid.

Metatype is enabled by default in Karaf. So, you can have your annotation @ObjectClassDefintion.

However, you can’t mix SCR level property and metatype property.
So it’s all one or the other.

Regards
JB

> Le 4 juin 2020 à 14:49, Christian Lutz <Ch...@kreeloo.de> a écrit :
> 
> Hello JB,
> 
> oh it is wired to the name of the component. I will give it a try. 
> 
> If I look into the OSGI compendium ObjectClassDefinition is a MetaType Annotation. What did I miss?
> 
> Kind regards
> Christian 
> 
>> Am 04.06.2020 um 14:44 schrieb Jean-Baptiste Onofre <jb...@nanthrax.net>:
>> 
>> And by the way, you can also use metatype.
>> 
>> Regards
>> JB
>> 
>>> Le 4 juin 2020 à 14:38, Christian Lutz <Ch...@kreeloo.de> a écrit :
>>> 
>>> Hello,
>>> 
>>> is it possible with karaf (4.1.x or 4.2.x) to use a configuration file with an ObjectClassDefinition?
>>> 
>>> E.g. I have a simple ObjectClassDefinition with one boolean method. I set the pid property to de.xy
>>> 
>>> My idea was that if I want to change the default value all I need to do is to create a de.xy.cfg file in karaf /cfg set the boolean value to false and during the component active the value from the config file will be used instead of the default value. 
>>> 
>>> I found some tutorials of how to use the objectclassdefinition itself. But I didnt find anything about how I am able to wire this with the karaf Configuration Admin Service. 
>>> 
>>> Kind regards
>>> Christian 
>> 
> 


Re: Use configuration file with ObjectClassDefinition

Posted by Christian Lutz <Ch...@kreeloo.de>.
Hello JB,

oh it is wired to the name of the component. I will give it a try. 

If I look into the OSGI compendium ObjectClassDefinition is a MetaType Annotation. What did I miss?

Kind regards
Christian 

> Am 04.06.2020 um 14:44 schrieb Jean-Baptiste Onofre <jb...@nanthrax.net>:
> 
> And by the way, you can also use metatype.
> 
> Regards
> JB
> 
>> Le 4 juin 2020 à 14:38, Christian Lutz <Ch...@kreeloo.de> a écrit :
>> 
>> Hello,
>> 
>> is it possible with karaf (4.1.x or 4.2.x) to use a configuration file with an ObjectClassDefinition?
>> 
>> E.g. I have a simple ObjectClassDefinition with one boolean method. I set the pid property to de.xy
>> 
>> My idea was that if I want to change the default value all I need to do is to create a de.xy.cfg file in karaf /cfg set the boolean value to false and during the component active the value from the config file will be used instead of the default value. 
>> 
>> I found some tutorials of how to use the objectclassdefinition itself. But I didnt find anything about how I am able to wire this with the karaf Configuration Admin Service. 
>> 
>> Kind regards
>> Christian 
> 


Re: Use configuration file with ObjectClassDefinition

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
And by the way, you can also use metatype.

Regards
JB

> Le 4 juin 2020 à 14:38, Christian Lutz <Ch...@kreeloo.de> a écrit :
> 
> Hello,
> 
> is it possible with karaf (4.1.x or 4.2.x) to use a configuration file with an ObjectClassDefinition?
> 
> E.g. I have a simple ObjectClassDefinition with one boolean method. I set the pid property to de.xy
> 
> My idea was that if I want to change the default value all I need to do is to create a de.xy.cfg file in karaf /cfg set the boolean value to false and during the component active the value from the config file will be used instead of the default value. 
> 
> I found some tutorials of how to use the objectclassdefinition itself. But I didnt find anything about how I am able to wire this with the karaf Configuration Admin Service. 
> 
> Kind regards
> Christian