Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 20:29 Go to next message
Daniel Kashtan is currently offline Daniel KashtanFriend
Messages: 15
Registered: March 2010
Junior Member
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 07:11 Go to previous messageGo to next message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 486
Registered: July 2009
Location: San Francisco ✈ Germany
Senior Member

> 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] Mon, 12 July 2010 02:13 Go to previous message
Simon Archer is currently offline Simon ArcherFriend
Messages: 24
Registered: July 2009
Junior Member
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: Fri Apr 19 03:51:35 GMT 2024

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

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

Back to the top