Closed bjhargrave closed 4 years ago
Comment author: @cziegeler
There are currently two ways to get a ServiceReferenceDTO: traversing down from a FrameworkDTO and adapting a bundle to an array of ServiceReferenceDTOs. Both approaches are not waisting a lot of resources to get a single reference.
I assume the easiest way would be to add an adapt method to ServiceReference
Comment author: @bjhargrave
CPEG call: Agree to add adapt method to ServiceReference. Target types to include ServiceReferenceDTO, Map(service properties), Bundle (registering bundle).
Also have ServiceReference extends BundleReference.
Comment author: @bjhargrave
Fixed by https://osgi.org/gitweb/build.git/commit/70eec607be7fc06b37f7ff2ffedbc7379621f6ac
This change adds an adapt method to ServiceReference and changes ServiceReference to extend BundleReference.
ServiceReference can only be adapted to ServiceReferenceDTO. I also added a CT method for the adaption.
There is no point in adapting ServiceReference to Bundle since there is already a getBundle method (now via BundleReference).
Also, the change does not support adapting to Map. There is already a getProperties() method which returns Dictionary which can be wrapped to a Map with the new FrameworkUtil.asMap method. Adapting to Map.class would loose any generic information which means the caller would need to suppress warnings.
@ SuppressWarnings("unchecked") Map<String,Object> props = ref.adapt(Map.class);
FrameworkUtil.asMap(ServiceReference.getProperties()) will return a properly generified Map with no warnings.
Map<String,Object> props = FrameworkUtil.asMap(ref.getProperties());
We just need to framework RI updated for adapting ServiceReference to a ServiceReferenceDTO. Assigning to Tom to update the RI.
Comment author: @bjhargrave
RI done. Need CT changes.
Comment author: @bjhargrave
CT was updated!
Original bug ID: BZ#3117 From: @cziegeler Reported version: R7