felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard S. Hall" <he...@ungoverned.org>
Subject Re: EventAdmin registered Event
Date Thu, 13 Jul 2006 07:40:49 GMT
Yes, this is basically what I was going to say too.

It sounds like you have some classes on your class path as well as in 
the bundle, which would result in class cast exceptions.

This is a tricky part when embedding the framework in a host 
application. If you want your host application to communicate with 
services from internal bundles, they must share the same classes. For 
services provided by the host application, this is generally not a 
problem since its service classes will likely be on the class path and 
can be exported by the system bundle.

However, having the host application use a service provided by a bundle 
is more difficult if the bundle is the one exporting the classes. You 
generally have two options in this case:

   1. Modify the bundle to import the classes and put them on the class
      path with your host application and export them via the system bundle.
   2. Modify your host application to use reflection to access the
      service provided by the bundle, thus your host application will
      not need the classes.

One day, when I find the time, I want to cook up a scheme where the host 
application can actually import from bundles.

-> richard

Marcel Offermans wrote:
> Hello Leo,
>
> The code in the main activator probably contains the 
> org.osgi.service.event package, since it uses it. Does the system 
> bundle explicitly export this package so other bundles can use it? If 
> you have some other bundle exporting the same package, you will get 
> this exception because then there are two versions in the framework.
>
> Greetings, Marcel
>
> On Jul 12, 2006, at 19:57 , Kwong, Leo wrote:
>
>> java.lang.ClassCastException:
>> org.apache.felix.eventadmin.impl.security.EventAdminSecurityDecorator
>>     at
>> com.simpledevices.simplecenter.SimpleCenterCommandHandler$CommandHandler
>> .run(SimpleCenterCommandHandler.java:84)
>>     at java.lang.Thread.run(Thread.java:595)
>>
>> The piece of code that I'm writing is to post an event via the
>> EventAdmin, and it is not a traditional plugin. It's not made into a jar
>> like a regular plugin. It doesn't import packages from the manifest
>> file. It works just like a regular java files. What we do is that we
>> override Felx and we call
>>
>> start(new MutablePropertyResolverImpl(propertyMap), getMainActivator());
>>
>> where the mainActivator is a wrapper class that starts the main
>> application class SimpleCenter.
>>
>>
>> -----Original Message-----
>> From: Karl Pauls [mailto:karlpauls@gmail.com]
>> Sent: Tuesday, July 11, 2006 10:35 PM
>> To: felix-dev@incubator.apache.org
>> Subject: Re: EventAdmin registered Event
>>
>> Hello Leo,
>>
>>> When I got the service object, I can see from my IDE that it's an
>>> instance of EventAdminSecurityDecorator.
>>
>> This is correct.
>>
>>> However, when ask to cast the
>>> service object to an EventAdmin class, I get a ClassCastException.
>>
>> Could you please share the stacktrace with us?
>>
>>> There are no other class with the same name in my source tree. Can
>> someone
>>> tell me what could be wrong? Thanks!
>>
>> Do you import the org.osgi.service.event package?
>>
>>> -Leo
>>
>> regards,
>>
>> Karl
>>
>> --Karl Pauls
>> karlpauls@gmail.com
>
>

Mime
View raw message