Multiple configuration in Component class | Community
Skip to main content
Level 3
Jul 12, 2022 6:24 PM UTC
Solved

Multiple configuration in Component class

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.
SantoshSai
SantoshSaiAccepted solution
New Participant
Jul 12, 2022 7:53 PM UTC

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

2 replies

SantoshSai
SantoshSaiAccepted solution
New Participant
Jul 12, 2022 7:53 PM UTC

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

Translate
Santosh Sai
aembeeAuthor
Level 3
Jul 13, 2022 8:39 PM UTC

Thanks @santoshsai . That was helpful!

Translate