Reputation: 4103
I have a ServiceReference
and I want to check if the implementation has an annotation. So I need to get the implementing class.
I figured out how to get the interfaces the service implements:
ServiceReference<T> reference = //
String[] interfaces = (String[]) reference.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
But even with the JavaDoc I can't figure out how to get the implementation (obviously without getting the service from the context, because that might be a heavy-weight operation and I need just the class).
How do I get the implementation out of a ServiceReference
?
Upvotes: 0
Views: 99
Reputation: 9384
So you want to get the service object without getting the service object? I think you are asking for something impossible. You will need to get the service object to introspect it's implementation class for annotations. There is no other way. Make sure to unget the service object when done.
Upvotes: 1
Reputation: 19606
You have to get the service using service = context.getService(reference)
. It is not a heavy weight operation.
You might also benefit from using a ServiceTracker. Apart from that I am curious what you want to achieve.. maybe there is a better way.
Upvotes: 0