Expand my Community achievements bar.

SOLVED

Multiple configuration in Component class

Avatar

Level 3

Hi Folks, 
I have imported one configuration using @Designate in my Component class. Now I need to add another one but @Designate doesn't allow. Is there any other way I can access another configuration in the same class? Thanks in advance!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @prachiz ,

  1. Unfortunately per documentation [0], multiple Object Class Definition's configurations are not allowed - there are two params Class<?>  ocd() (Required) & boolean factory() (Optional) 

    Screen Shot 2022-07-12 at 3.42.24 PM.png

  2. Another way, If you try extending @interface annotation, per Java documentation [1] - No extends clause is permitted. (Annotation types implicitly extend annotation.Annotation.) 
    So, you cannot extend an Annotation. 

Based on above assertions, to answer your question, unfortunately there in no way of referring multiple OCD's configuration. However, you can achieve that by defining those MetaType (@AttributeDefinition) in your original existing @interface which you are using in your component class.

OR

It might be much better to move the common configuration into some kind of configuration service, and centralize all common functionality there and use in other services using @Reference annotation.

[0]: http://docs.osgi.org/javadoc/r6/cmpn/org/osgi/service/metatype/annotations/Designate.html

[1]: https://docs.oracle.com/javase/specs/jls/se7/html/jls-9.html#jls-9.6

Hope that helps!

Regards,

Santosh

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @prachiz ,

  1. Unfortunately per documentation [0], multiple Object Class Definition's configurations are not allowed - there are two params Class<?>  ocd() (Required) & boolean factory() (Optional) 

    Screen Shot 2022-07-12 at 3.42.24 PM.png

  2. Another way, If you try extending @interface annotation, per Java documentation [1] - No extends clause is permitted. (Annotation types implicitly extend annotation.Annotation.) 
    So, you cannot extend an Annotation. 

Based on above assertions, to answer your question, unfortunately there in no way of referring multiple OCD's configuration. However, you can achieve that by defining those MetaType (@AttributeDefinition) in your original existing @interface which you are using in your component class.

OR

It might be much better to move the common configuration into some kind of configuration service, and centralize all common functionality there and use in other services using @Reference annotation.

[0]: http://docs.osgi.org/javadoc/r6/cmpn/org/osgi/service/metatype/annotations/Designate.html

[1]: https://docs.oracle.com/javase/specs/jls/se7/html/jls-9.html#jls-9.6

Hope that helps!

Regards,

Santosh