Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] getservice throws class cast exception

Santosh,

I'm glad you got this working but please bear in mind that it is a
poor design choice to export an interface from the same bundle that
provides the service, because it does not truly de-couple the consumer
from the provider, and it makes it much harder for you to update the
provider bundle as the implementation of the service evolves. So I
still recommend that you pull the interface into a third bundle.

Regards,
Neil

On 5/30/08, Santosh Akhilesh <santoshakhilesh@xxxxxxxxxx> wrote:
>
> Hi,
>
> Thanks I got the problem solved as per your suggestion.
>
> However I could make it work with two bundles as per Toni's hint
>
> I included the jar in to the bundle one which was registering the service,
> this bundle exported the interface A.
>
> In the second bundle I just imported the interface A and retrieved the
> object and cast to A successfully.
>
> Thanks for your help and time.
>
> Cheers,
> Santosh Akhilesh
> ****************************************************************************
> **************
>
>  This email and its attachments contain confidential information from
> HUAWEI, which is intended only for the person or entity whose address is
> listed above. Any use of the information contained herein in any way
> (including, but not limited to, total or partial disclosure, reproduction,
> or dissemination) by persons other than the intended recipient(s) is
> prohibited. If you receive this e-mail in error, please notify the sender by
> phone or email immediately and delete it!
>
>
> ****************************************************************************
> *************
>
>
> -----Original Message-----
> From: equinox-dev-bounces@xxxxxxxxxxx
> [mailto:equinox-dev-bounces@xxxxxxxxxxx] On Behalf Of njbartlett@xxxxxxxxx
> Sent: Thursday, May 29, 2008 9:02 PM
> To: Equinox development mailing list
> Subject: Re: [equinox-dev] getservice throws class cast exception
>
> Santosh,
>
> You should not include the JAR that contains the interface in the
> classpath of the two bundles. You should make it into a third bundle
> and use Import-Package to depend on the interface.
>
> When a class is defined independently by two or more classloaders, the
> resulting classes are considered by the JVM to be different, even if
> they have exactly the same name and are defined from the same bytes on
> disk. Therefore you cannot cast an instance of one type into a field
> of the other.
>
> Regards
> Neil
>
> On 5/29/08, Santosh Akhilesh <santoshakhilesh@xxxxxxxxxx> wrote:
>> Dear All,
>>
>>
>>
>> I am new to OSGI and Equinox.
>>
>>
>>
>> I have defined an interface say A, this is defined in a project and
> exported
>> as jar
>>
>>
>>
>> Now I create Two OSGI bundles I include this jar in both the bundles.
>>
>>
>>
>> >From one bundle I implement the interface A and register the service to
> the
>> bundle context from second bundle I try to retrieve this service from
> bundle
>> context in the activator start function.
>>
>>
>>
>> I can see that service is retrieved but when I cast it to interface A, I
> get
>> class cast exception
>>
>>
>>
>> Any pointer why this happens and how to correct it.
>>
>>
>>
>> Regards,
>>
>> Santosh Akhilesh
>>
>> Ph: 9845482201
>>
>>
>>
>>
> _______________________________________________
> equinox-dev mailing list
> equinox-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/equinox-dev
>
>
> _______________________________________________
> equinox-dev mailing list
> equinox-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/equinox-dev
>


Back to the top