cq5 - Filtering OSGi services using SlingScriptHelper#getService() method -
i want instantiate service object in jsp using sling taglib. in normal scenario service class beingness implemented 1 class, pretty simple:-
registrationservice registrationservice = sling.getservice(registrationservice.class);
but if service class has more 1 implementation classes, how can create sure instantiate object particular class.
my java class like:- 1. interface: registrationservice 2. implementation class 1:-
@properties({@property(name = "datasource", value = "sbws"}) @service public class registrationserviceimpl implements registrationservice{ }
3. implementation class 2:-
@properties({@property(name = "datasource", value = "solr"}) @service public class registrationserviceimpl implements registrationservice{ }
how can create sure using
registrationservice registrationservice = sling.getservice(registrationservice.class);
in jsp instantiate service allow implementation class 1
use slingscripthelper#getservices(...)
method, allows specify filter:
registrationservice[] services = sling.getservice(registrationservice.class, "(datasource=sbws)"); if (services.length > 0) { // services[0] contains service }
getting osgi service , filtering via properties quite low-level stuff, consider moving jsp java class.
osgi cq5 osgi-bundle sling
No comments:
Post a Comment