Multiple configuration in Component class | Community
Skip to main content
Level 3
July 12, 2022
Solved

Multiple configuration in Component class

  • July 12, 2022
  • 1 reply
  • 1408 views

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!

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 SantoshSai

Hi @aembee ,

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



  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

1 reply

SantoshSai
Community Advisor
SantoshSaiCommunity AdvisorAccepted solution
Community Advisor
July 12, 2022

Hi @aembee ,

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



  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

Santosh Sai
aembeeAuthor
Level 3
July 13, 2022

Thanks @santoshsai . That was helpful!