Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » finding bundle name?
finding bundle name? [message #289433] Thu, 04 August 2005 17:16 Go to next message
Eclipse UserFriend
Originally posted by: sgollery.cadrc.calpoly.edu

Is there a way for a class to find out the name of the bundle that is
contained in, or alternately to get the Bundle object itself? I see how to
do that if the class is derived from WorkbenchPart, but what about classes
that are not part of any specific class hierarchy?

Thanks,

Steve Gollery
Re: finding bundle name? [message #289434 is a reply to message #289433] Thu, 04 August 2005 17:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Steven Gollery" <sgollery@cadrc.calpoly.edu> wrote in message
news:4f2cd67cb6789549acc5ab526a5c3b51$1@www.eclipse.org...
> Is there a way for a class to find out the name of the bundle that is
> contained in, or alternately to get the Bundle object itself? I see how to
> do that if the class is derived from WorkbenchPart, but what about classes
> that are not part of any specific class hierarchy?
>
> Thanks,
>
> Steve Gollery
>

bundle.getHeaders().get("Bundle-Name")
Re: finding bundle name? [message #289435 is a reply to message #289434] Thu, 04 August 2005 17:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sgollery.cadrc.calpoly.edu

Sunil Kamath wrote:


> "Steven Gollery" <sgollery@cadrc.calpoly.edu> wrote in message
> news:4f2cd67cb6789549acc5ab526a5c3b51$1@www.eclipse.org...
>> Is there a way for a class to find out the name of the bundle that is
>> contained in, or alternately to get the Bundle object itself? I see how to
>> do that if the class is derived from WorkbenchPart, but what about classes
>> that are not part of any specific class hierarchy?
>>
>> Thanks,
>>
>> Steve Gollery
>>

> bundle.getHeaders().get("Bundle-Name")

Sunil,

I'm hoping to avoid having to put the bundle name into the code or into a
properties file or something. In other words: starting with no Bundle
object and no bundle name, can a class find out what bundle it is part of?

Steve
Re: finding bundle name? [message #289437 is a reply to message #289435] Thu, 04 August 2005 19:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Steven Gollery" <sgollery@cadrc.calpoly.edu> wrote in message
news:ccdab9f80b4e1eb1e39e50116eb708da$1@www.eclipse.org...
> Sunil Kamath wrote:
>
>
>> "Steven Gollery" <sgollery@cadrc.calpoly.edu> wrote in message
>> news:4f2cd67cb6789549acc5ab526a5c3b51$1@www.eclipse.org...
>>> Is there a way for a class to find out the name of the bundle that is
>>> contained in, or alternately to get the Bundle object itself? I see how
>>> to do that if the class is derived from WorkbenchPart, but what about
>>> classes that are not part of any specific class hierarchy?
>>>
>>> Thanks,
>>>
>>> Steve Gollery
>>>
>
>> bundle.getHeaders().get("Bundle-Name")
>
> Sunil,
>
> I'm hoping to avoid having to put the bundle name into the code or into a
> properties file or something. In other words: starting with no Bundle
> object and no bundle name, can a class find out what bundle it is part of?
>
Starting with no Bundle object?
Why would you want to do that?
And "Bundle-Name" is not the actual bundle name, but the name of the
manifest attribute which points to the bundle name.
---
Sunil
Re: finding bundle name? [message #289438 is a reply to message #289433] Thu, 04 August 2005 20:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

You at least need access to a BundleContext, passed to the
BundleActivator.start(...) method. Once you have the context:

Object object = ...; //the object you want to find bundle for
BundleContext context = ...;
ServiceReference ref =
context.getServiceReference(PackageAdmin.class.getName());

if (ref != null) {
PackageAdmin admin = (PackageAdmin)context.getService(ref);
Bundle bundle = admin.getBundle(object.getClass());
bundle.getSymbolicName() -> voila...
}
--


Steven Gollery wrote:
> Is there a way for a class to find out the name of the bundle that is
> contained in, or alternately to get the Bundle object itself? I see how
> to do that if the class is derived from WorkbenchPart, but what about
> classes that are not part of any specific class hierarchy?
>
> Thanks,
>
> Steve Gollery
>
Re: finding bundle name? [message #289440 is a reply to message #289438] Thu, 04 August 2005 22:07 Go to previous message
Eclipse UserFriend
Originally posted by: sgollery.cadrc.calpoly.edu

John Arthorne wrote:

> You at least need access to a BundleContext, passed to the
> BundleActivator.start(...) method. Once you have the context:

> Object object = ...; //the object you want to find bundle for
> BundleContext context = ...;
> ServiceReference ref =
> context.getServiceReference(PackageAdmin.class.getName());

> if (ref != null) {
> PackageAdmin admin = (PackageAdmin)context.getService(ref);
> Bundle bundle = admin.getBundle(object.getClass());
> bundle.getSymbolicName() -> voila...
> }
> --

Which works fine unless you've created a plugin from an existing Jar file,
in which case there is no BundleActivator class in the plugin.

But I've worked out another way to solve the problem that I thought I
needed a bundle for, so thanks to you and to Sunil for your input.

Steve



> Steven Gollery wrote:
>> Is there a way for a class to find out the name of the bundle that is
>> contained in, or alternately to get the Bundle object itself? I see how
>> to do that if the class is derived from WorkbenchPart, but what about
>> classes that are not part of any specific class hierarchy?
>>
>> Thanks,
>>
>> Steve Gollery
>>
Previous Topic:CVS Folder Control
Next Topic:IPath.isValidPath()
Goto Forum:
  


Current Time: Thu Apr 25 10:11:37 GMT 2024

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

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

Back to the top