Reputation: 13424
I coded a bundle that uses Apache Felix Dependency management. It's Activator extends DependencyActivatorBase. But Plugin my plugin activator extends AbstractUIPlugin. How can I get services from the felix dependency manager from within the eclipse plugin?
DependencyManager has a getDepenencyManagers method but it is a list, not sure how I would know the right manager in the list.
Upvotes: 0
Views: 554
Reputation: 3323
The DependencyActivatorBase class is just a base class that is there for your convenience. If, for some reason, you cannot use it (like, arguably, in your case), you can always instantiate an instance of DependencyManager yourself from your own class. All it needs is a reference to the BundleContext (which you can get from the start() method of BundleActivator, assuming you do implement that yourself). Then just do something like this:
DependencyManager dm = new DependencyManager(bundleContext);
dm.add(dm.createComponent()
.setImplementation(YourComponent.class)
.add(dm.createServiceDependency()
.setService(LogService.class)
)
);
Upvotes: 2
Reputation: 23958
Yes you can use Dependency Manager in any OSGi framework, including Equinox (on which Eclipse is based).
Why does your bundle activator need to extend AbstractUIPlugin
?? Are you actually using AbstractUIPlugin,
or was this just generated for you because you used Eclipse PDE to generate the initial code? The project templates in PDE are basically junk, most bundles do not need activators at all, and very very few really need to extend AbstractUIPlugin
.
So, just change your activator to extend DependencyActivatorBase
instead of AbstractUIPlugin
.
Upvotes: 2