Skip to main content



      Home
Home » Eclipse Projects » Equinox » org.osgi.framework.FrameworkUtil.getBundle(Class) method, where is it?
org.osgi.framework.FrameworkUtil.getBundle(Class) method, where is it? [message #543858] Wed, 30 June 2010 16:29 Go to next message
Eclipse UserFriend
Hey all,

I am trying to access my BundleContext so I can use a service outside my activator. I found that OSGI 4.2 has a method org.osgi.framework.FrameworkUtil.getBundle(Class), but I cannot use it in my project (method doesn't exist, won't compile). I am using Equinox 3.6 and this link, http://download.eclipse.org/eclipse/downloads/drops/R-3.5-20 0906111540/eclipse-news-part3.html, appears to say that it has been available since 3.5.2.

Can anybody help me figure out how to use this method? Other alternatives are welcome too. The only other option I've seen is to make a static reference to the BundleContext in the Activator, which seems kinda ugly Sad
Re: org.osgi.framework.FrameworkUtil.getBundle(Class) method, where is it? [message #543934 is a reply to message #543858] Thu, 01 July 2010 03:11 Go to previous messageGo to next message
Eclipse UserFriend
> The only other option I've seen is to make a static reference to the BundleContext in the Activator, which seems kinda ugly :(

It's not ugly but common practice to set/unset a static reference in
your activator when a bundle is started/stopped. This allows to keep
references to your BundleContext. You could also install service
trackers in your activator and inject those into a factory class of your
own if you. But that just encapsulates the statics into another class. ;)

FrameworkUtil#getBundle(Class) may have some disadvantages (performance,
security). However, in case you need it, simply add "org.osgi.framework"
as Import-Package in your manifest and you'll have it. It's there in
Equinox 3.6.

BTW, have you looked at DS? This might be an alternative if you don't
like dealing with an activator and static references.

-Gunnar

--
Gunnar Wagenknecht
gunnar@wagenknecht.org
http://wagenknecht.org/
Re: org.osgi.framework.FrameworkUtil.getBundle(Class) method, where is it? [message #546178 is a reply to message #543858] Sun, 11 July 2010 22:13 Go to previous message
Eclipse UserFriend
Gunnar's suggestion to consider using DS is spot on. If you're new to DS I would like to suggest my book, which has two chapters dedicated to it.

Good luck,

Simon
Previous Topic:Passing an external object to an OSGi Bundle
Next Topic:Helios P2 Agent error
Goto Forum:
  


Current Time: Tue Jul 08 18:55:57 EDT 2025

Powered by FUDForum. Page generated in 0.05078 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top