felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Offermans <marcel.offerm...@luminis.nl>
Subject Re: Annotation Decorated Service
Date Tue, 10 Apr 2012 15:34:50 GMT
Hello Jorge,

On Apr 10, 2012, at 17:15 PM, Quecas wrote:

> One of the big paradigms of OSGI is to define a public API/SPI as an
> interface while keeping the implementation(s) private. Having said that and
> if the various implementations of a specific service each define meta-data
> using annotations, how would one get to this information without shifting
> from the paradigm or "bending" the rules.

You are talking about using annotations on a "POJO" that implements an interface but has no
dependencies whatsoever on the OSGi framework?

If so, then annotations are sort-of-evil in my book.

I look at annotations as part of the API, so if these annotations link you to an OSGi (framework)
specific API, they are bad if they appear in the POJO (which then no longer is a POJO).

There is one "but" here, and that is that annotations are optional. If you load a POJO that
has annotations, and those annotations are not available on the classpath, they don't get
loaded. In fact, some annotations don't even appear in the class at runtime and are just there
for the compiler or some pre-processor. From that point of view, they are like optional imports
and one could argue that it does not make the POJO depend on the API (only optionally). On
the other hand, if, to reuse the POJO in different frameworks, each framework requires its
own set of annotations, then compiling the POJO with all these different sets of annotations
becomes difficult and it's not a direction I would want to go in (and having lots of annotations
on all kinds of methods does not make the code more readable either).

About getting to such metadata at runtime, I would advise you to use service properties whenever
this information can be used to select a service from a collection of ones with the same interface.

Hope this answers your question. :)

Greetings, Marcel

To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org

View raw message